days_in_month
Calculate the number of days in a specific or current month. Provide a date in YYYY-MM-DD format to determine the days in that month. Part of the time-mcp server, enhancing applications with accurate time-related functionalities.
Instructions
Get the number of days in a month. If no date is provided, get the number of days in the current month.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | No | The date to get the days in month. Format: YYYY-MM-DD |
Implementation Reference
- src/index.ts:74-90 (handler)Main handler logic for the 'days_in_month' tool call within the MCP server request handler. Validates arguments, computes the result using getDaysInMonth, and returns a formatted response.case 'days_in_month': { if (!checkDaysInMonthArgs(args)) { throw new Error(`Invalid arguments for tool: [${name}]`); } const date = args.date; const result = getDaysInMonth(date); return { success: true, content: [ { type: 'text', text: `The number of days in month is ${result}.`, }, ], }; }
- src/tools.ts:50-62 (schema)Tool schema definition for 'days_in_month', including name, description, and input schema.export const DAYS_IN_MONTH: Tool = { name: 'days_in_month', description: 'Get the number of days in a month. If no date is provided, get the number of days in the current month.', inputSchema: { type: 'object', properties: { date: { type: 'string', description: 'The date to get the days in month. Format: YYYY-MM-DD', }, }, }, };
- src/index.ts:179-181 (helper)Core helper function that calculates the number of days in a given month (or current month) using dayjs library.function getDaysInMonth(date?: string) { return date ? dayjs(date).daysInMonth() : dayjs().daysInMonth(); }
- src/index.ts:30-34 (registration)Registration of the 'days_in_month' tool (via DAYS_IN_MONTH) in the server's list tools handler.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [CURRENT_TIME, RELATIVE_TIME, DAYS_IN_MONTH, GET_TIMESTAMP, CONVERT_TIME, GET_WEEK_YEAR], }; });
- src/index.ts:222-229 (helper)Input validation helper function for 'days_in_month' tool arguments.function checkDaysInMonthArgs(args: unknown): args is { date: string } { return ( typeof args === 'object' && args !== null && 'date' in args && typeof args.date === 'string' ); }