getBadges
Retrieve your Fitbit achievement badges to track fitness milestones and monitor your health progress through the FitBit MCP server.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"type": "object"
}
Implementation Reference
- src/server.ts:799-824 (handler)Inline handler function for the 'getBadges' tool. Fetches badges data from Fitbit API endpoint '/user/-/badges.json' using the makeApiRequest helper, formats as JSON text response, or returns error on failure.server.tool("getBadges", {}, async () => { try { const endpoint = "/user/-/badges.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:799-799 (registration)Registration of the 'getBadges' tool on the MCP server with empty input schema.server.tool("getBadges", {}, async () => {
- src/server.ts:44-65 (helper)Shared utility function that makes authenticated HTTP requests to the Fitbit API, used by the getBadges handler.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; } }