Skip to content

Commit bc0f25f

Browse files
jyeakleyJustin Yeakley
andauthored
Remote OAuth (#13)
* OAuth Implementation Using Stytch for remote workers. --------- Co-authored-by: Justin Yeakley <justin@genomoncology.com>
1 parent 0ddd3ae commit bc0f25f

8 files changed

Lines changed: 1210 additions & 10 deletions

File tree

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Setting Up Stytch OAuth for BioMCP
2+
3+
This document outlines the steps required to set up Stytch OAuth authentication for the BioMCP application.
4+
5+
## Prerequisites
6+
7+
- A Stytch account (sign up at [Stytch](https://stytch.com/))
8+
- Access to the BioMCP codebase
9+
10+
## Setting Up Your Stytch Account
11+
12+
1. **Create a Stytch Account**
13+
14+
- Sign up at [Stytch](https://stytch.com/)
15+
- Select "Consumer Authentication" when prompted during the setup process
16+
17+
2. **Configure the Stytch Project**
18+
19+
- In the Stytch dashboard, navigate to "Frontend SDKs" and enable the frontend SDK
20+
- Navigate to "Connected Apps" and enable "Dynamic Client Registration"
21+
- This allows MCP clients to register themselves dynamically with Stytch
22+
23+
3. **Retrieve Your Credentials**
24+
- Go to "Project Settings" in the Stytch dashboard
25+
- Note down the following credentials:
26+
- Project ID
27+
- Secret (API Key)
28+
- Public Token
29+
30+
## Configuring BioMCP with Stytch
31+
32+
1. **Update the Wrangler Configuration**
33+
34+
- Open `wrangler.toml` in the BioMCP project
35+
- Update the following variables with your Stytch credentials:
36+
```toml
37+
STYTCH_PROJECT_ID = "your-project-id"
38+
STYTCH_SECRET = "your-secret-key"
39+
STYTCH_PUBLIC_TOKEN = "your-public-token"
40+
```
41+
- For development, use the test environment:
42+
```toml
43+
STYTCH_API_URL = "https://test.stytch.com/v1"
44+
```
45+
- For production, use:
46+
```toml
47+
STYTCH_API_URL = "https://api.stytch.com/v1"
48+
```
49+
50+
2. **Configure the OAuth KV Namespace**
51+
52+
- Create a KV namespace in Cloudflare for storing OAuth tokens and state
53+
- Update the KV namespace ID in `wrangler.toml`:
54+
```toml
55+
[[kv_namespaces]]
56+
binding = "OAUTH_KV"
57+
id = "your-kv-namespace-id"
58+
```
59+
60+
3. **Configure JWT Secret**
61+
- Set a strong JWT secret for token signing:
62+
```toml
63+
JWT_SECRET = "your-secure-jwt-secret"
64+
```
65+
66+
## OAuth Flow Overview
67+
68+
The BioMCP application uses the following OAuth flow:
69+
70+
1. **Discovery**: MCP clients fetch OAuth metadata to locate Stytch authorization endpoints
71+
2. **Registration**: MCP clients dynamically register with Stytch
72+
3. **Authorization**: Users are redirected to Stytch for authentication and consent
73+
4. **Token Exchange**: After consent, authorization codes are exchanged for access tokens
74+
5. **MCP Connection**: MCP clients connect to the BioMCP server using OAuth access tokens
75+
76+
## Endpoints
77+
78+
The worker implements the following OAuth endpoints:
79+
80+
- `/.well-known/oauth-authorization-server`: OAuth server metadata
81+
- `/authorize`: OAuth authorization endpoint
82+
- `/callback`: OAuth callback endpoint
83+
- `/token`: Token exchange endpoint
84+
85+
## Testing
86+
87+
To test the OAuth implementation:
88+
89+
1. Deploy the worker to Cloudflare:
90+
91+
```
92+
wrangler deploy
93+
```
94+
95+
2. Use the MCP Inspector or another OAuth client to test the flow:
96+
- Set the OAuth discovery URL to: `https://your-worker.workers.dev/.well-known/oauth-authorization-server`
97+
- The inspector will guide you through the OAuth flow
98+
99+
## Troubleshooting
100+
101+
- **JWT Validation Issues**: Ensure the JWKS endpoint is correctly configured and accessible
102+
- **Callback Errors**: Check that the redirect URIs are properly registered and match exactly
103+
- **Token Exchange Failures**: Verify that the authorization code is valid and not expired
104+
105+
## Security Considerations
106+
107+
- Always use HTTPS for all OAuth endpoints
108+
- Implement proper CORS headers for cross-origin requests
109+
- Regularly rotate the JWT secret
110+
- Use the production Stytch API URL for production environments

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ nav:
1616
- MCP Client: tutorials/mcp-client.md
1717
- Cursor IDE: tutorials/cursor-ide.md
1818
- Cloudflare Worker Deployment: tutorials/cloudflare-worker-deployment.md
19+
- Setting Up Stytch OAuth for BioMCP: tutorials/stytch_oauth_setup.md
1920
- CLI Reference:
2021
- Trials: cli/trials.md
2122
- Articles: cli/articles.md

package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"devDependencies": {
33
"wrangler": "^4.13.2"
4+
},
5+
"dependencies": {
6+
"hono": "^4.7.8",
7+
"jose": "^6.0.11"
48
}
59
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies = [
1919
"certifi>=2025.1.31",
2020
"diskcache>=5.6.3",
2121
"httpx>=0.28.1",
22-
"mcp[cli]==1.6.0",
22+
"mcp[cli]>=1.7.1",
2323
"platformdirs>=4.3.6",
2424
"psutil>=7.0.0",
2525
"pydantic>=2.10.6",

0 commit comments

Comments
 (0)