Setting Up Stytch OAuth for BioMCP¶
This document outlines the steps required to set up Stytch OAuth authentication for the BioMCP application.
Prerequisites¶
- A Stytch account (sign up at Stytch)
- Access to the BioMCP codebase
Setting Up Your Stytch Account¶
-
Create a Stytch Account
-
Sign up at Stytch
-
Select "Consumer Authentication" when prompted during the setup process
-
Configure the Stytch Project
-
In the Stytch dashboard, navigate to "Frontend SDKs" and enable the frontend SDK
- Navigate to "Connected Apps" and enable "Dynamic Client Registration"
-
This allows MCP clients to register themselves dynamically with Stytch
-
Retrieve Your Credentials
- Go to "Project Settings" in the Stytch dashboard
- Note down the following credentials:
- Project ID
- Secret (API Key)
- Public Token
Configuring BioMCP with Stytch¶
-
Update the Wrangler Configuration
-
Open
wrangler.toml
in the BioMCP project - Update the following variables with your Stytch credentials:
- For development, use the test environment:
-
For production, use:
-
Configure the OAuth KV Namespace
-
Create a KV namespace in Cloudflare for storing OAuth tokens and state
-
Update the KV namespace ID in
wrangler.toml
: -
Configure JWT Secret
- Set a strong JWT secret for token signing:
OAuth Flow Overview¶
The BioMCP application uses the following OAuth flow:
- Discovery: MCP clients fetch OAuth metadata to locate Stytch authorization endpoints
- Registration: MCP clients dynamically register with Stytch
- Authorization: Users are redirected to Stytch for authentication and consent
- Token Exchange: After consent, authorization codes are exchanged for access tokens
- MCP Connection: MCP clients connect to the BioMCP server using OAuth access tokens
Endpoints¶
The worker implements the following OAuth endpoints:
/.well-known/oauth-authorization-server
: OAuth server metadata/authorize
: OAuth authorization endpoint/callback
: OAuth callback endpoint/token
: Token exchange endpoint
Testing¶
To test the OAuth implementation:
- Deploy the worker to Cloudflare:
- Use the MCP Inspector or another OAuth client to test the flow:
- Set the OAuth discovery URL to:
https://your-worker.workers.dev/.well-known/oauth-authorization-server
- The inspector will guide you through the OAuth flow
Troubleshooting¶
- JWT Validation Issues: Ensure the JWKS endpoint is correctly configured and accessible
- Callback Errors: Check that the redirect URIs are properly registered and match exactly
- Token Exchange Failures: Verify that the authorization code is valid and not expired
Security Considerations¶
- Always use HTTPS for all OAuth endpoints
- Implement proper CORS headers for cross-origin requests
- Regularly rotate the JWT secret
- Use the production Stytch API URL for production environments