Skip to content

FEAT-009 — Per-user identity for remote MCP: OAuth claims become the guard context #218

Done

Description

@jmmana

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 PolicySet from 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_id claims 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

Activity

  1. added
    type:feature
    area:security
    area:rls
    area:integrations
    size:l
    lang:python
    p1
    on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:integrationsarea:rlsarea:securitylang:pythonp1size:ltype:feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions