Skip to main content
Glama

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
NameRequiredDescriptionDefault
codeYesAuthorization code from OAuth callback

Implementation Reference

  • 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'], }, },
  • MCP CallTool handler: validates 'code' argument and calls WhoopApiClient.exchangeCodeForToken, returns 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), }, ], }; }
  • Core implementation in WhoopApiClient: constructs form data with code, client credentials, and POSTs to Whoop OAuth token endpoint to exchange code for access/refresh tokens
    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; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nissand/whoop-mcp-server-claude'

If you have feedback or need assistance with the MCP directory API, please join our Discord server