whoop-exchange-code-for-token
Convert WHOOP authorization code into access token to authenticate and access fitness data through the WHOOP API.
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:249-262 (registration)Tool registration in ListTools handler, defining name, description, and input schema requiring 'code' string{ 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/mcp-server.ts:497-510 (handler)MCP CallTool handler: validates 'code' argument and calls WhoopApiClient.exchangeCodeForToken, returns JSON stringified resultcase '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/whoop-api.ts:155-170 (helper)Core implementation in WhoopApiClient: constructs form data with code, client credentials, and POSTs to Whoop OAuth token endpoint to exchange code for access/refresh tokensasync 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; }