Skip to main content
Glama

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
NameRequiredDescriptionDefault
dateNoThe date to get the days in month. Format: YYYY-MM-DD

Implementation Reference

  • 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}.`,
          },
        ],
      };
    }
  • 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',
          },
        },
      },
    };
  • 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],
      };
    });
  • 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'
      );
    }
Install Server

Other Tools

Related Tools

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/yokingma/time-mcp'

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