nutrivita-mcp-oauth-spike
A throwaway MCP server spike to prove Claude can complete OAuth 2.1 + PKCE and call a trivial ping tool.
README
N-US-078 MCP OAuth Spike
Throwaway spike to prove Claude can complete OAuth 2.1 + PKCE against a Nutrivita-hosted MCP server and call a trivial ping tool.
Do not merge to dev. This code is intentionally disposable.
What it does
- Serves RFC 9728 protected-resource metadata and RFC 8414 authorization-server metadata.
- Implements a minimal OAuth 2.1 Authorization Server:
GET /oauth/authorize— hardcoded login + consent page.POST /oauth/authorize— issues an authorizationcode(with PKCE binding andiss).POST /oauth/token— exchanges code for a JWT access token whoseaudis the canonical MCP URI.
- Implements a stateless MCP Resource Server over Streamable HTTP:
POST /mcp— returns401withWWW-Authenticate+as_uriwhen unauthenticated.- Authenticated requests list and call a single
pingtool.
Run locally
cd scratch/n-us-078-mcp-oauth-spike
cp .env.example .env
# edit .env: set SPIKE_CLIENT_SECRET and JWT_SECRET
npm run dev
Local curl test
# 1. Discover protected resource metadata
curl http://localhost:3000/.well-known/oauth-protected-resource
# 2. Open the consent page in a browser, approve, and copy the `code` from the URL.
# Or use the authorize URL directly:
open "http://localhost:3000/oauth/authorize?client_id=n-us-078-spike-client-id&response_type=code&redirect_uri=https%3A%2F%2Flocalhost%2Fcallback&scope=mcp%3Aping&code_challenge=abc123&code_challenge_method=S256&state=xyz"
# 3. Exchange the code for an access token
curl -X POST http://localhost:3000/oauth/token \
-H "Content-Type: application/json" \
-d '{
"grant_type": "authorization_code",
"client_id": "n-us-078-spike-client-id",
"client_secret": "n-us-078-spike-client-secret",
"code": "PASTE_CODE",
"redirect_uri": "https://localhost/callback",
"code_verifier": "PASTE_VERIFIER"
}'
# 4. Call ping via MCP (Accept must include both application/json and text/event-stream)
curl -X POST http://localhost:3000/mcp \
-H "Authorization: Bearer PASTE_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"ping"}}'
Note: the MCP transport returns a streamable response, so the body is formatted as an SSE event (event: message\ndata: {...}) even for direct HTTP responses.
Deploy for Claude testing
The server must be on a public host with an IPv4 A record and HTTPS (Claude calls from 160.79.104.0/21).
The recommended approach is a separate subdomain on the existing Nutrivita backend VM so the spike doesn't touch the backend Nginx config.
Deploy on Render (quick option)
If you don't want to touch GCP, Render can host the spike directly. The repo includes a render.yaml blueprint that creates a free Web Service with the required env vars.
1. Create a GitHub repo for the spike
Create a new private GitHub repository (e.g. nutrivita-mcp-oauth-spike). Do not include the Nutrivita main repo.
2. Push the spike files
From this directory, push all files except secrets and dependencies:
# Run in a terminal
git init
git checkout -b main
# Add all the files: package.json, *.mjs, Dockerfile, README.md, .env.example,
# .env.production.example, nginx-mcp-spike.conf, deploy.sh, render.yaml
git add package.json config.mjs oauth.mjs server.mjs test-flow.mjs Dockerfile README.md .env.example .env.production.example nginx-mcp-spike.conf deploy.sh render.yaml
git commit -m "N-US-078 MCP OAuth spike"
git remote add origin https://github.com/YOUR_USER/nutrivita-mcp-oauth-spike.git
git push -u origin main
3. Create the Render service
- In the Render dashboard, click New → Web Service.
- Connect the
nutrivita-mcp-oauth-spikeGitHub repository. - Render will detect
render.yamland provision the service automatically. - Wait for the build to finish. The service URL will be something like
https://nutrivita-mcp-spike.onrender.com.
The render.yaml sets:
SPIKE_CLIENT_ID=n-us-078-spike-client-idSPIKE_CLIENT_SECRET,JWT_SECRET,SPIKE_USER_PASSWORD= Render-generated random secretsBASE_URLis derived automatically fromRENDER_EXTERNAL_URL.
You can override any of these in the Render Dashboard → Environment tab.
4. Verify
curl https://nutrivita-mcp-spike.onrender.com/.well-known/oauth-authorization-server
curl https://nutrivita-mcp-spike.onrender.com/health
5. Connect in Claude
Use the Render URL as the MCP server endpoint:
- MCP server URL:
https://nutrivita-mcp-spike.onrender.com/mcp - Client ID:
n-us-078-spike-client-id - Client Secret: copy from the Render Dashboard (
SPIKE_CLIENT_SECRET) - Consent password: copy from the Render Dashboard (
SPIKE_USER_PASSWORD)
Note: Render's free Web Service sleeps after 15 minutes of inactivity. The first request may take 30–60 seconds to wake up. For the OAuth handshake, either ping
/healthfirst or upgrade to a paid instance.
GCP deployment (if you prefer the Nutrivita VM)
1. Prepare environment
Create the production env file and fill in real secrets:
cp .env.production.example .env.production
# edit .env.production
2. Add a DNS record
Create an A record for mcp-spike.nutrivita.asia (or your chosen subdomain) pointing to the external IPv4 address of the nutrivita-backend VM.
3. Run the deploy script
Requires: gcloud CLI authenticated, Docker installed, and permission to push to the project's Artifact Registry.
export GCP_PROJECT_ID=your-project-id
export GCP_REPOSITORY_NAME=your-repo-name
export DOMAIN=mcp-spike.nutrivita.asia
export SSL_EMAIL=admin@nutrivita.asia
chmod +x deploy.sh
./deploy.sh
The script will:
- Build and push the spike Docker image.
- SSH into the existing VM and run the container on
localhost:3002. - Install an Nginx site for the subdomain.
- Obtain a Let's Encrypt certificate.
- Test the metadata endpoint.
If you prefer, you can run the same steps manually; see deploy.sh for the exact commands.
4. Verify
curl https://mcp-spike.nutrivita.asia/.well-known/oauth-authorization-server
curl https://mcp-spike.nutrivita.asia/health
5. Connect in Claude
- In Claude, go to Settings → Custom Connectors → Add connector.
- Enter the MCP server URL:
https://mcp-spike.nutrivita.asia/mcp. - In Advanced settings, enter the
SPIKE_CLIENT_IDandSPIKE_CLIENT_SECRETfrom.env.production. - On the hardcoded login+consent page, enter the
SPIKE_USER_PASSWORDand click Approve. - Ask Claude "call ping" and confirm it returns
pong.
Capture redirect_uris
During discovery, leave ALLOWED_REDIRECT_URIS unset. The spike logs every redirect_uri sent by Claude. Copy the exact observed values and add them to .env before handing off to N-US-079.
Stop the spike
When the spike is done (pass or fail), delete this directory or keep it on a clearly named branch. Do not merge to develop.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。