Skip to content

feat(frontend): MCP service-token auth on gas-station endpoint#62

Merged
artugrande merged 1 commit into
mainfrom
feat/gas-station-mcp-auth
May 6, 2026
Merged

feat(frontend): MCP service-token auth on gas-station endpoint#62
artugrande merged 1 commit into
mainfrom
feat/gas-station-mcp-auth

Conversation

@artugrande
Copy link
Copy Markdown
Collaborator

Summary

Enables the MCP server (apps/mcp, PR #61) to call /api/gas-station/sponsor for service-to-service requests using a shared secret in the x-mcp-service-token header. Privy bearer auth for human users is unchanged.

Why

The MCP server's onboarding flow (create_account.complete) needs to submit gas-sponsored transactions on behalf of agents. Privy auth is for humans — agents have no Privy session. The shared-secret pattern is the simplest service-to-service path; a separate signed JWT scheme can come later if we ever expose the gas station to other internal services.

Behavior

Header sent env GAS_STATION_SERVICE_TOKEN Auth result
x-mcp-service-token valid set ✅ bypass Privy, proceed
x-mcp-service-token mismatch set ❌ 401 "Invalid MCP service token"
x-mcp-service-token present NOT set ❌ 401 (defensive: server not configured)
header absent any fall through to existing Privy path (unchanged)

Comparison uses crypto.timingSafeEqual to avoid timing attacks.

Required env var

Add to BOTH frontend Vercel project (this) AND apps/mcp Vercel project:

GAS_STATION_SERVICE_TOKEN=<openssl rand -hex 32 — same value in both projects>

Test plan

  • pnpm typecheck passes
  • pnpm test passes (existing gas-station tests + new MCP-token tests: 28 total, +4 vs baseline of 24)
  • Manual: deploy preview, confirm Privy path still works for human users
  • Manual: with the env set, curl with the x-mcp-service-token header succeeds; without it, 401

🤖 Generated with Claude Code

…ponsor

Enables the MCP server (apps/mcp, PR #61) to call /api/gas-station/sponsor
via a shared secret in the x-mcp-service-token header, bypassing Privy
verification. Timing-safe comparison (crypto.timingSafeEqual) guards against
oracle attacks. The existing Privy bearer-auth path is unchanged.

Adds 4 new tests covering: valid token, mismatched token, token present but
env not configured, and absent header falls through to Privy.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@artugrande artugrande requested a review from tomazzi14 as a code owner May 6, 2026 22:35
@vercel
Copy link
Copy Markdown

vercel Bot commented May 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
gh-bounty-frontend Ready Ready Preview, Comment May 6, 2026 10:36pm

@artugrande artugrande merged commit 6344973 into main May 6, 2026
4 checks passed
@artugrande artugrande deleted the feat/gas-station-mcp-auth branch May 6, 2026 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant