getUserProfile
Retrieve user profile information from Fitbit, including personal details and health metrics, to enable personalized health and fitness analysis.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"type": "object"
}
Implementation Reference
- src/server.ts:75-99 (handler)The inline handler function for the 'getUserProfile' tool. It calls the Fitbit API endpoint '/user/-/profile.json' via the makeApiRequest helper, returns the profile data as formatted JSON text, or an error message if failed.server.tool("getUserProfile", {}, async () => { try { const data = await makeApiRequest("/user/-/profile.json"); 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:75-99 (registration)Registration of the 'getUserProfile' tool on the MCP server with empty input schema.server.tool("getUserProfile", {}, async () => { try { const data = await makeApiRequest("/user/-/profile.json"); 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 helper function that makes authenticated HTTP requests to the Fitbit API, used by the getUserProfile handler and 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; } }