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.

28 lines (27 loc) 1.4 kB
import { registerTool, CommonSchemas, handleFitbitApiCall } from './utils.js'; import { FITBIT_API_VERSIONS, VALIDATION_MESSAGES } from './config.js'; // --- Tool Registration --- /** * Registers a single, parameterized Fitbit sleep tool with the MCP server for a date range. * @param server The McpServer instance. * @param getAccessTokenFn Function to retrieve the current access token. */ export function registerSleepTool(server, getAccessTokenFn) { registerTool(server, { name: 'get_sleep_by_date_range', description: `Get the raw JSON response for sleep logs from Fitbit for a specific date range. Requires 'startDate' and 'endDate' parameters in 'YYYY-MM-DD' format. ${VALIDATION_MESSAGES.MAX_RANGE_100_DAYS}.`, parametersSchema: { startDate: CommonSchemas.startDate, endDate: CommonSchemas.endDate, }, handler: async ({ startDate, endDate }) => { const endpoint = `/sleep/date/${startDate}/${endDate}.json`; return handleFitbitApiCall(endpoint, { startDate, endDate }, getAccessTokenFn, { apiBase: FITBIT_API_VERSIONS.V1_2, successDataExtractor: (data) => data.sleep || [], noDataMessage: `the date range '${startDate}' to '${endDate}'`, errorContext: `date range '${startDate}' to '${endDate}'` }); } }); }