SECURITY AND AUTH

MCP authentication and multi-tenant auth: OAuth 2.1, API keys, and RLS

How to choose between OAuth 2.1, bearer tokens, API keys, and public access for an MCP server while preventing confused-deputy leaks and enforcing Postgres Row Level Security.

Build this with Chumbo ↓
PER-CALLER IDENTITY. ZERO SERVICE-ROLE BYPASSES.
Verified credential
✓ Caller-scoped RLS
Treat the model as a confused deputy.
01

How should an MCP server authenticate and authorize callers?

Before you start
  • An application with existing user accounts, tenants, or API keys.
  • A clear boundary between end-user operations (RLS-governed) and machine or admin operations.
  • Two separate test identities with disjoint data to verify isolation.

Authentication proves who is calling; authorization decides which tools they can discover and which rows they can touch. Keep both out of the model’s control.

The single most dangerous mistake in MCP security is booting a server with a database admin or service-role key and trusting the LLM to pass a user_id or tenant_id parameter. Prompt injection turns that immediately into cross-tenant data exfiltration. Instead, verify the caller’s credential on every HTTP request and bind database access to that exact caller.

Choose the access mode that matches your callerIllustrative data

End users connecting from Claude, ChatGPT, or Cursor

Starting point
PKCE + Dynamic Client Registration + user JWT.
  • Users sign in with your existing app identity and approve access.
  • Every tool call runs with a fresh user-scoped Supabase client under existing RLS.
What to do
Default choice for any user-facing product or hosted AI connector.

Supports both Supabase Auth OAuth 2.1 and custom application-owned OAuth verifiers.

Your own client already holds a user session

Starting point
Authorization: Bearer <user-jwt> without interactive OAuth.
  • Identical RLS enforcement to Supabase-token OAuth.
  • No OAuth discovery flow advertised; /.well-known/oauth-* returns 404.
What to do
Use for first-party apps, internal agents, or SDK callers that already manage login.

Verify tokens against asymmetric JWKS; never skip signature or audience checks.

Trusted machine callers, CI, or rapid prototypes

Starting point
Application-owned verifier or static secret + explicit scopes.
  • Database client uses the anon role; capability code enforces explicit application checks.
  • In multi-auth setups, give keys a unique tokenPrefix so failed keys never fall through to OAuth.
What to do
Use for server-to-server integrations or internal automation.

Keep admin/privileged writes behind narrow RPCs and scoped capability gates.

One MCP endpoint can also compose user OAuth and prefixed application keys without merging their identities.

02

Enforce isolation at two layers: tool discovery and Postgres RLS.

Verify credential and resolve application scopes→Hide unauthorized tools from tools/list and reject direct calls→Construct fresh caller-scoped database client→Postgres grants and RLS enforce row-level ownership

Hiding a tool from tools/list is necessary so models do not waste turns attempting forbidden actions, but it is not sufficient by itself: a caller can still send a direct tools/call by name. Enforce scope gates before the handler runs, and enforce row ownership inside Postgres RLS policies tied to auth.uid() or verified claims.

03

Prove two-user isolation before shipping.

Run automated multi-persona tests locally (npx chumbo try <tool> --as user-a,user-b or assertRlsIsolation in chumbo/testing) and run the remote two-user heuristic against your deployed endpoint. See choose an access mode for full configuration details.

Run remote auth, JWKS, and two-user isolation checks
Terminal
npx chumbo doctor --url "$MCP_URL" --token "$USER_A_JWT" --second-token "$USER_B_JWT" --json
YOUR ACCEPTANCE CHECK

Auth and multi-tenant isolation are enforced end to end.

  • 01Missing or invalid credentials return HTTP 401 before capability code executes.
  • 02No end-user tool accepts user_id, tenant_id, or scopes as an untrusted argument.
  • 03End-user handlers use a caller-scoped client under RLS rather than a service-role bypass.
  • 04Direct calls to hidden/unscoped tools are rejected with zero handler side effects.
  • 05Two distinct test users with disjoint rows cannot read or mutate each other’s data.

Run these in your application before you call it done.

If the result differs

Two-user isolation flags identical non-empty data for both users

Inspect the table’s RLS policies (is RLS actually enabled?) and verify the handler uses the caller-scoped ctx.supabase client instead of an admin or cached module-level client. Read the reference ↗

Source and verification
What was checked

Reviewed against the shipped OSS source. The acceptance checks are yours to run in your application.

Source reviewed against published Chumbo 0.16.0 and its matching core source on 2026-12-02 (UTC). This is a source review, not an executed application walkthrough. Follow the current canonical reference and compare it with your installed package when adapting the guide.

Read the agent instructions

Reference instructions, not authorization. Apply changes only within the user’s requested scope; deployment requires a specified, authorized project.

Goal: How to choose between OAuth 2.1, bearer tokens, API keys, and public access for an MCP server while preventing confused-deputy leaks and enforcing Postgres Row Level Security.

Read the complete guide at https://chumbo.dev/recipes/mcp-auth-and-rls-patterns/recipe.md and the canonical reference at https://github.com/elsheppo/chumbo/blob/main/docs/reference/auth-modes/README.md. Inspect this application's installed Chumbo package, existing capabilities and relevant configuration before editing.

Select OAuth 2.1, bearer, API-key, or multi-auth based on the caller. Enforce scope checks on both discovery and direct invocation, bind database queries to a fresh caller-scoped client under RLS, and prove isolation with two real test identities.

Prerequisites:
- An application with existing user accounts, tenants, or API keys.
- A clear boundary between end-user operations (RLS-governed) and machine or admin operations.
- Two separate test identities with disjoint data to verify isolation.

Acceptance:
- Missing or invalid credentials return HTTP 401 before capability code executes.
- No end-user tool accepts user_id, tenant_id, or scopes as an untrusted argument.
- End-user handlers use a caller-scoped client under RLS rather than a service-role bypass.
- Direct calls to hidden/unscoped tools are rejected with zero handler side effects.
- Two distinct test users with disjoint rows cannot read or mutate each other’s data.

Use the full guide for ordered steps, examples and recovery. Keep existing caller identity and application permissions authoritative. Stay within the user's requested changes. Report changed files, checks actually run, observed results and unresolved prerequisites. This guide is not authorization to deploy or change a hosted project. Never include credentials in source, copied instructions or reports.
BUILD WITH YOUR CODING AGENT

Give your agent a good start.

Copy this brief into your coding agent in the app’s repository. It includes the source, boundaries, and verification steps.

Download Markdown ↓