Repository navigation
Done
Labels
area:integrationsRecipes for LLM frameworks and MCParea:rlsRow-level filters and context bindingarea:securityGuarantees of the threat modellang:pythonPython package and the enginep1Prioridad 1: altasize:l3-5 daystype:featureNew capability
Description
Parent epic: #214
Priority: P1
Problem
sqlguardllm serve and the MCP server over HTTP accept one static bearer token shared by every caller. Row filters need a per-user context ({user.tenant_id}), and today the application has to inject it. A remote MCP server cannot tell who is calling, so it cannot give each person only their own rows.
Proposal
sqlguardllm mcp --http --policy policy.yaml --db "$READ_ONLY_URL" \
--auth oidc --issuer https://auth.example.com --audience sqlguardllm# policy.yaml
context_from_claims:
user.tenant_id: org_id
user.branches: branches
role: role # selects the role in a PolicySet- Validate the caller's OAuth 2.1 access token as the MCP authorization spec describes: signature against the issuer's JWKS,
iss,aud,exp,nbf. - Publish the protected resource metadata the spec requires, so MCP clients can discover the issuer.
- Build the guard context from the verified claims only, and pick the role of a
PolicySetfrom a claim. - Taint state and audit logs are keyed by the token subject.
Use case
One database, one server, many customers: a SaaS can let each customer connect Claude or ChatGPT to their own data, with the existing row filters doing the isolation.
Security impact
- Context comes only from a verified token. Tool arguments and model output never set it.
- Fails closed: a missing claim that a filter needs means
missing_context, as today. - Tokens are never logged. Audit records hold the subject and the claims used, not the token.
Acceptance criteria
- JWT validation against a JWKS, with tests for a bad signature, a wrong issuer or audience, an expired token and a missing claim.
- Two users with different
org_idclaims get different rows from the same query on PostgreSQL (engine test). - Protected resource metadata served and checked with an MCP client.
- Docs (EN / ES): "A multi-tenant MCP server for your SaaS database", with a Keycloak or Auth0 example.
Files
src/sqlguardllm/auth.py(new) ·mcp_server.py·server.py·policy.py·docs/MCP.md
Size
L
Metadata
Metadata
Assignees
Labels
area:integrationsRecipes for LLM frameworks and MCParea:rlsRow-level filters and context bindingarea:securityGuarantees of the threat modellang:pythonPython package and the enginep1Prioridad 1: altasize:l3-5 daystype:featureNew capability
Activity
Authenticate remote MCP callers and bind tenant policies to verified …
Add unit tests for OIDC token verification and per-user MCP identity (#…