getDevices
Retrieve connected Fitbit devices to access health and fitness data for analysis through AI assistants.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.ts:771-796 (handler)The inline handler and registration for the 'getDevices' MCP tool. Fetches device data from Fitbit API endpoint '/user/-/devices.json' using makeApiRequest helper, returns formatted JSON text or error in MCP content structure.server.tool("getDevices", {}, async () => { try { const endpoint = "/user/-/devices.json"; const data = await makeApiRequest(endpoint); return { content: [ { type: "text", text: JSON.stringify(data, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } });
- src/server.ts:44-65 (helper)Shared utility function that performs authenticated GET requests to Fitbit API endpoints using fetch, handles errors, and returns parsed JSON. Used by getDevices and all other tools.async function makeApiRequest(endpoint: string): Promise<any> { try { const url = `${baseUrl}${endpoint}`; const response = await fetch(url, { headers: { Authorization: `Bearer ${accessToken}`, Accept: "application/json", }, }); if (!response.ok) { throw new Error( `Fitbit API error: ${response.status} ${response.statusText}` ); } return await response.json(); } catch (error) { console.error(`Error making request to ${endpoint}:`, error); throw error; } }