This file provides guidance to WARP (warp.dev) when working with code in this repository.
# Install dependencies
npm install
# Start local development server
wrangler dev
# Run tests with Vitest
npm test
# Generate TypeScript types for Cloudflare Workers
npm run cf-typegen# Login to Cloudflare (first time only)
wrangler login
# Set Strava API secrets
wrangler secret put STRAVA_CLIENT_ID
wrangler secret put STRAVA_CLIENT_SECRET
# Set webhook secrets (optional - for real-time notifications)
wrangler secret put STRAVA_WEBHOOK_VERIFY_TOKEN
wrangler secret put POKE_API_KEY
# Deploy to production
npm run deploy
# or: wrangler deploy
# Verify deployment
node scripts/verify-deployment.js# Test server capabilities
curl https://your-worker.workers.dev/mcp
# Test tool listing
curl -X POST -H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":"1","method":"tools/list","params":{}}' \
https://your-worker.workers.dev/mcp# Test webhook endpoint
node scripts/manage-webhook.js test
# Create webhook subscription
STRAVA_CLIENT_ID=xxx STRAVA_CLIENT_SECRET=xxx node scripts/manage-webhook.js create
# View active subscription
STRAVA_CLIENT_ID=xxx STRAVA_CLIENT_SECRET=xxx node scripts/manage-webhook.js view
# Delete subscription
STRAVA_CLIENT_ID=xxx STRAVA_CLIENT_SECRET=xxx node scripts/manage-webhook.js delete
# Monitor webhook events in real-time
wrangler tailThis is a Cloudflare Workers application that implements a Model Context Protocol (MCP) server for Strava API integration with OAuth authentication.
- Entry Point:
src/index.ts- Hono-based web server with routing and middleware - MCP Server:
src/mcp-server.ts- Implements full MCP protocol with 9 Strava tools - OAuth Flow:
src/auth.ts+src/session.ts- Device-based authentication with KV storage - API Proxy:
src/api.ts+src/middleware.ts- Authenticated Strava API wrapper - Templates:
src/templates.ts- Landing page and dashboard HTML generation - Webhooks:
src/webhook.ts- Real-time Strava activity notifications with Poke integration
- Device Authentication: Browser fingerprinting for seamless MCP client auth
- KV Session Storage: Persistent authentication with automatic token refresh
- Complete MCP Implementation: 9 Strava tools (activities, segments, routes, stats)
- Protected API Routes:
/api/*endpoints with authentication middleware - Beautiful Web Interface: Landing page + personal dashboard at
/dashboard - Real-time Webhooks: Strava webhook integration for instant activity notifications via Poke
welcome-strava-mcp- Setup instructionsauthenticate-strava- Get OAuth URLget-recent-activities- Fetch activitiesget-athlete-profile- Profile infoget-athlete-stats- Statistics (recent, YTD, all-time)get-activity-details- Specific activity dataget-activity-streams- Time-series data (HR, power, etc.)get-starred-segments- Starred segmentsexplore-segments- Find segments by locationget-athlete-routes- Created routes
- Clone repository:
git clone <repo-url> - Install dependencies:
npm install - Login to Cloudflare:
wrangler login(uses CloudFlare CLI per user preference) - Copy environment template:
cp .env.example .env(if exists)
# Start local dev server with KV bindings
wrangler dev
# Visit http://localhost:8787 to test OAuth flow
# MCP endpoint available at http://localhost:8787/mcpRequired Secrets (set with wrangler secret put):
STRAVA_CLIENT_ID- From Strava API app settingsSTRAVA_CLIENT_SECRET- From Strava API app settings
Optional Secrets (for webhook functionality):
STRAVA_WEBHOOK_VERIFY_TOKEN- Token to verify webhook callbacks (e.g., "STRAVA_MCP_WEBHOOK")POKE_API_KEY- API key for Poke notification service
Environment Variables (in wrangler.jsonc):
STRAVA_REDIRECT_URI- OAuth callback URL (worker domain +/callback)
KV Namespace:
STRAVA_SESSIONS- Stores user sessions, OAuth tokens, and webhook activity summaries
- Unit Tests:
npm test(Vitest with Cloudflare Workers integration) - Integration Tests: Run
scripts/verify-deployment.jsafter deployment - Manual Testing: Use
/dashboardto verify OAuth flow and data access
- Update
STRAVA_REDIRECT_URIinwrangler.jsoncto match worker domain - Set Strava app Authorization Callback Domain to match worker URL
- Deploy with
npm run deploy - Run verification script to test all endpoints
- Update Strava app settings if domain changed
src/
├── index.ts # Main Hono app with routing
├── mcp-server.ts # MCP protocol implementation
├── auth.ts # OAuth handlers
├── session.ts # KV session management
├── middleware.ts # Auth middleware + API proxy
├── api.ts # Strava API handlers
├── webhook.ts # Webhook verification and event handling
├── templates.ts # HTML template engine
├── types.ts # TypeScript interfaces
└── worker-fixed.ts # Worker type fixes
test/
├── index.spec.ts # Basic integration tests
├── env.d.ts # Test environment types
└── tsconfig.json # Test-specific TS config
scripts/
├── verify-deployment.js # Post-deploy verification
└── manage-webhook.js # Webhook subscription management
wrangler.jsonc # Cloudflare Workers config
vitest.config.mts # Vitest configuration
- User visits
/auth→ redirects to Strava OAuth - Strava redirects to
/callback→ exchanges code for tokens - Creates device fingerprint from browser headers
- Stores session in KV with 30-day expiration
- MCP clients authenticate via device fingerprint or personal token
- Tokens auto-refresh 5 minutes before expiry
- Create webhook subscription via
manage-webhook.jsscript - Strava verifies callback URL with GET request to
/webhook - When activities are created/updated/deleted, Strava POSTs to
/webhook - Worker fetches full activity details using athlete's stored token
- Formats activity message and sends to Poke API (if configured)
- Stores activity summary in KV for 30 days
- Handles athlete deauthorization events automatically
Supported Webhook Events:
- Activity created (new workouts)
- Activity updated (title, type, privacy changes)
- Activity deleted
- Athlete deauthorized (auto-cleanup)
This architecture enables AI assistants to access personal Strava data through natural language queries while maintaining secure, per-user authentication, with optional real-time push notifications for new activities.