Skip to main content
Glama

getFloorsClimbed

Retrieve floors climbed data from Fitbit for specified dates or periods to track stair climbing activity and monitor daily or weekly fitness progress.

Input Schema

NameRequiredDescriptionDefault
dateNoDate in YYYY-MM-DD format. If not specified, will use today.
periodNoPeriod for data: 1d, 7d, 30d, 1w, 1m

Input Schema (JSON Schema)

{ "properties": { "date": { "description": "Date in YYYY-MM-DD format. If not specified, will use today.", "type": "string" }, "period": { "description": "Period for data: 1d, 7d, 30d, 1w, 1m", "type": "string" } }, "type": "object" }

Implementation Reference

  • The inline handler function that implements the core logic of the getFloorsClimbed tool. It formats the input date, constructs the appropriate Fitbit API endpoint for floors climbed data (/user/-/activities/floors/date/{date}/{period}.json), fetches the data using the shared makeApiRequest helper, parses and returns the relevant fields (floors and intraday) as a formatted JSON text response, with error handling.
    async ({ date, period }) => { try { const formattedDate = formatDate(date); let endpoint = ""; if (period) { endpoint = `/user/-/activities/floors/date/${formattedDate}/${period}.json`; } else { endpoint = `/user/-/activities/floors/date/${formattedDate}/1d.json`; } const data = await makeApiRequest(endpoint); return { content: [ { type: "text", text: JSON.stringify( { date: formattedDate, floors: data["activities-floors"] || [], intraday: data["activities-floors-intraday"] || {}, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } }
  • The Zod input schema for the getFloorsClimbed tool, defining two optional string parameters: 'date' (YYYY-MM-DD) and 'period' (e.g., 1d, 7d, 30d, 1w, 1m).
    { date: z .string() .optional() .describe("Date in YYYY-MM-DD format. If not specified, will use today."), period: z .string() .optional() .describe("Period for data: 1d, 7d, 30d, 1w, 1m"), },
  • src/server.ts:543-597 (registration)
    The MCP server.tool registration call for the getFloorsClimbed tool, specifying the name, input schema, and inline handler function within the initServer function.
    server.tool( "getFloorsClimbed", { date: z .string() .optional() .describe("Date in YYYY-MM-DD format. If not specified, will use today."), period: z .string() .optional() .describe("Period for data: 1d, 7d, 30d, 1w, 1m"), }, async ({ date, period }) => { try { const formattedDate = formatDate(date); let endpoint = ""; if (period) { endpoint = `/user/-/activities/floors/date/${formattedDate}/${period}.json`; } else { endpoint = `/user/-/activities/floors/date/${formattedDate}/1d.json`; } const data = await makeApiRequest(endpoint); return { content: [ { type: "text", text: JSON.stringify( { date: formattedDate, floors: data["activities-floors"] || [], intraday: data["activities-floors-intraday"] || {}, }, null, 2 ), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } } );
  • Shared helper function used by getFloorsClimbed (and other tools) to make authenticated HTTP requests to the Fitbit API, handling errors and JSON parsing.
    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; } }
  • Shared helper function used by getFloorsClimbed to format the input date or default to today's date in YYYY-MM-DD format.
    function formatDate(date?: string): string { if (date) return date; const today = new Date(); return today.toISOString().split("T")[0]; // YYYY-MM-DD }

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/NitayRabi/fitbit-mcp'

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