UNPKG

mcp-fitbit

Version:

Model Context Protocol (MCP) server for accessing Fitbit health and fitness data. Connect AI assistants like Claude to your Fitbit data for personalized health insights.

36 lines (35 loc) 1.62 kB
import { z } from 'zod'; import { registerTool, CommonSchemas, handleFitbitApiCall } from './utils.js'; /** * Registers an activity time series tool with the MCP server. * @param server The McpServer instance. * @param getAccessTokenFn Function to retrieve the current access token. */ export function registerActivityTimeSeriesTool(server, getAccessTokenFn) { registerTool(server, { name: 'get_activity_timeseries', description: "Get the raw JSON response for activity time series data from Fitbit over a date range (max 30 days). Supports various resource paths like 'steps', 'distance', 'calories', 'activityCalories', 'caloriesBMR'.", parametersSchema: { resourcePath: z .enum([ 'steps', 'distance', 'calories', 'activityCalories', 'caloriesBMR', 'tracker/activityCalories', 'tracker/calories', 'tracker/distance' ]) .describe("Activity resource to retrieve (e.g., 'steps', 'distance', 'calories')"), startDate: CommonSchemas.startDate, endDate: CommonSchemas.endDate, }, handler: async ({ resourcePath, startDate, endDate }) => { const endpoint = `activities/${resourcePath}/date/${startDate}/${endDate}.json`; return handleFitbitApiCall(endpoint, { resourcePath, startDate, endDate }, getAccessTokenFn, { errorContext: `resource '${resourcePath}' from ${startDate} to ${endDate}` }); } }); }