docs/v2/integrations/supabase.mdx
import { VersionBadge } from "/snippets/version-badge.mdx"
<VersionBadge version="2.13.0" />This guide shows you how to secure your FastMCP server using Supabase Auth. This integration uses the Remote OAuth pattern, where Supabase handles user authentication and your FastMCP server validates the tokens.
Before you begin, you will need:
http://localhost:8000)In your Supabase Dashboard:
https://abc123.supabase.co)Create your FastMCP server using the SupabaseProvider:
from fastmcp import FastMCP
from fastmcp.server.auth.providers.supabase import SupabaseProvider
# Configure Supabase Auth
auth = SupabaseProvider(
project_url="https://abc123.supabase.co",
base_url="http://localhost:8000",
auth_route="/my/auth/route" # if self-hosting and using custom routes
)
mcp = FastMCP("Supabase Protected Server", auth=auth)
@mcp.tool
def protected_tool(message: str) -> str:
"""This tool requires authentication."""
return f"Authenticated user says: {message}"
if __name__ == "__main__":
mcp.run(transport="http", port=8000)
Start your FastMCP server with HTTP transport to enable OAuth flows:
fastmcp run server.py --transport http --port 8000
Your server is now running and protected by Supabase authentication.
Create a test client that authenticates with your Supabase-protected server:
from fastmcp import Client
import asyncio
async def main():
# The client will automatically handle Supabase OAuth
async with Client("http://localhost:8000/mcp", auth="oauth") as client:
# First-time connection will open Supabase login in your browser
print("✓ Authenticated with Supabase!")
# Test the protected tool
result = await client.call_tool("protected_tool", {"message": "Hello!"})
print(result)
if __name__ == "__main__":
asyncio.run(main())
When you run the client for the first time:
For production deployments, use environment variables instead of hardcoding credentials.
Setting this environment variable allows the Supabase provider to be used automatically without explicitly instantiating it in code.
<Card> <ParamField path="FASTMCP_SERVER_AUTH" default="Not set"> Set to `fastmcp.server.auth.providers.supabase.SupabaseProvider` to use Supabase authentication. </ParamField> </Card>These environment variables provide default values for the Supabase provider, whether it's instantiated manually or configured via FASTMCP_SERVER_AUTH.
Example .env file:
# Use the Supabase provider
FASTMCP_SERVER_AUTH=fastmcp.server.auth.providers.supabase.SupabaseProvider
# Supabase configuration
FASTMCP_SERVER_AUTH_SUPABASE_PROJECT_URL=https://abc123.supabase.co
FASTMCP_SERVER_AUTH_SUPABASE_BASE_URL=https://your-server.com
FASTMCP_SERVER_AUTH_SUPABASE_REQUIRED_SCOPES=openid,email
With environment variables set, your server code simplifies to:
from fastmcp import FastMCP
# Authentication is automatically configured from environment
mcp = FastMCP(name="Supabase Protected Server")