getUserProfile
Retrieve user profile information from Fitbit data to access health metrics and personal details for analysis.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "getUserProfile"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.ts:75-99 (handler)The handler function for the 'getUserProfile' tool, registered inline with server.tool. It fetches the user profile from Fitbit API using makeApiRequest and returns formatted JSON or error.
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)Helper function used by getUserProfile to make authenticated API requests to Fitbit endpoints.
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; } } - src/server.ts:75-99 (registration)Registration of the 'getUserProfile' tool using server.tool within the initServer function.
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-75 (schema)Empty input schema for the getUserProfile tool (no parameters required).
server.tool("getUserProfile", {}, async () => {