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.
End users connecting from Claude, ChatGPT, or Cursor
Starting pointPKCE + 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.
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 pointAuthorization: Bearer <user-jwt> without interactive OAuth.
- Identical RLS enforcement to Supabase-token OAuth.
- No OAuth discovery flow advertised; /.well-known/oauth-* returns 404.
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 pointApplication-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.
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.
Enforce isolation at two layers: tool discovery and Postgres RLS.
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.
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.
npx chumbo doctor --url "$MCP_URL" --token "$USER_A_JWT" --second-token "$USER_B_JWT" --jsonAuth 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 ↗
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.
