whoop-exchange-code-for-token
Exchange an OAuth authorization code for an access token to authenticate with WHOOP fitness and health data APIs.
Instructions
Exchange authorization code for access token
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Authorization code from OAuth callback |
Implementation Reference
- src/mcp-server.ts:497-510 (handler)MCP tool handler for 'whoop-exchange-code-for-token': validates 'code' argument and calls WhoopApiClient.exchangeCodeForToken, returning JSON stringified result.case 'whoop-exchange-code-for-token': { if (!args || typeof args.code !== 'string') { throw new Error('code is required and must be a string'); } const result = await this.whoopClient.exchangeCodeForToken(args.code); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
- src/mcp-server.ts:249-262 (registration)Registers the 'whoop-exchange-code-for-token' tool in the listTools response, including name, description, and input schema.{ name: 'whoop-exchange-code-for-token', description: 'Exchange authorization code for access token', inputSchema: { type: 'object', properties: { code: { type: 'string', description: 'Authorization code from OAuth callback', }, }, required: ['code'], }, },
- src/whoop-api.ts:155-170 (helper)Core implementation: exchanges OAuth code for access/refresh tokens by sending POST request to Whoop's token endpoint with client credentials.async exchangeCodeForToken(code: string): Promise<{ access_token: string; refresh_token: string; expires_in: number }> { const formData = new URLSearchParams(); formData.append('client_id', this.config.clientId); formData.append('client_secret', this.config.clientSecret); formData.append('code', code); formData.append('grant_type', 'authorization_code'); formData.append('redirect_uri', this.config.redirectUri); const response = await axios.post('https://api.prod.whoop.com/oauth/oauth2/token', formData, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }); return response.data; }