apps/docs/content/guides/auth/oauth-server/mcp-authentication.mdx
The Model Context Protocol (MCP) is an open standard for connecting AI agents and LLM tools to data sources and services. While Supabase doesn't provide MCP server functionality, you can build your own MCP servers that connect to your Supabase project and leverage Supabase Auth's OAuth 2.1 capabilities to authenticate AI agents using your existing user base.
When building MCP servers that connect to your Supabase project, you can leverage your existing Supabase Auth infrastructure to authenticate AI agents:
When you build an MCP server that connects to your Supabase project, authentication flows through Supabase Auth:
By leveraging Supabase Auth, your MCP server can authenticate AI agents using your existing user accounts without building a separate authentication system.
Before setting up MCP authentication:
Configure your MCP server to use your Supabase Auth server:
https://<project-ref>.supabase.co/auth/v1
Replace <project-ref> with your project reference ID from the Supabase dashboard.
MCP clients will automatically discover your OAuth configuration from:
https://<project-ref>.supabase.co/.well-known/oauth-authorization-server/auth/v1
Depending on your MCP server implementation, you have two options:
Dynamic registration allows any MCP client to register with your project. Consider:
When building your own MCP server, integrate with Supabase Auth to authenticate AI agents as your existing users and leverage your RLS policies.
<Admonition type="tip">Looking for an easier way to build MCP servers?
FastMCP provides a streamlined way to build MCP servers with built-in Supabase Auth integration. FastMCP handles OAuth configuration, token management, and authentication flows automatically, letting you focus on building your AI agent's functionality. Check out their Supabase integration guide to get started quickly.
</Admonition>When your MCP server makes requests to your Supabase APIs on behalf of authenticated users, it will send access tokens issued by Supabase Auth, just like any other OAuth client.
Use the same token validation as other OAuth clients.
See Token Security & RLS for more examples.
Always require explicit user approval for MCP clients:
Problem: Client shows "OAuth discovery failed" or similar error.
Solutions:
/.well-known/oauth-authorization-server returns valid JSONProblem: Client receives 403 or 404 on registration endpoint.
Solutions:
Problem: Client receives "invalid_grant" error.
Solutions:
Problem: MCP client can't access data despite valid token.
Solutions:
client_id