Skip to main content
Glama
ainarsklavins

Date MCP Server

Format Date

format-date

Convert dates to readable formats using short, medium, long, or full styles with locale support for international applications.

Instructions

Format a date in various styles (short, medium, long, full).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dateNoDate in ISO format (defaults to today)
styleNoDate style
localeNoLocale code (e.g., "en-US", "fr-FR")

Implementation Reference

  • The handler function for the 'format-date' tool. It takes date, style, and locale parameters, validates them, formats the date using toLocaleDateString with the specified style, and returns a JSON-structured response or error.
    async ({ date, style = 'medium', locale = 'en-US' }) => {
      const targetDate = date ? new Date(date) : new Date();
    
      if (isNaN(targetDate.getTime())) {
        return {
          content: [{ type: 'text', text: 'Error: Invalid date format.' }],
          isError: true
        };
      }
    
      try {
        const styleMap: Record<string, 'short' | 'medium' | 'long' | 'full'> = {
          short: 'short',
          medium: 'medium',
          long: 'long',
          full: 'full'
        };
    
        return {
          content: [{
            type: 'text',
            text: JSON.stringify({
              formatted: targetDate.toLocaleDateString(locale, { dateStyle: styleMap[style] }),
              style,
              locale,
              iso: targetDate.toISOString()
            }, null, 2)
          }]
        };
      } catch {
        return {
          content: [{ type: 'text', text: `Error: Invalid locale "${locale}".` }],
          isError: true
        };
      }
    }
  • The input schema defined using Zod for the 'format-date' tool, specifying optional parameters for date, style (enum: short/medium/long/full), and locale.
    inputSchema: {
      date: z.string().optional().describe('Date in ISO format (defaults to today)'),
      style: z.enum(['short', 'medium', 'long', 'full']).optional().describe('Date style'),
      locale: z.string().optional().describe('Locale code (e.g., "en-US", "fr-FR")')
    }
  • src/index.ts:138-185 (registration)
    The registration of the 'format-date' tool using server.registerTool, including name, metadata (title, description, inputSchema), and the handler function.
    server.registerTool(
      'format-date',
      {
        title: 'Format Date',
        description: 'Format a date in various styles (short, medium, long, full).',
        inputSchema: {
          date: z.string().optional().describe('Date in ISO format (defaults to today)'),
          style: z.enum(['short', 'medium', 'long', 'full']).optional().describe('Date style'),
          locale: z.string().optional().describe('Locale code (e.g., "en-US", "fr-FR")')
        }
      },
      async ({ date, style = 'medium', locale = 'en-US' }) => {
        const targetDate = date ? new Date(date) : new Date();
    
        if (isNaN(targetDate.getTime())) {
          return {
            content: [{ type: 'text', text: 'Error: Invalid date format.' }],
            isError: true
          };
        }
    
        try {
          const styleMap: Record<string, 'short' | 'medium' | 'long' | 'full'> = {
            short: 'short',
            medium: 'medium',
            long: 'long',
            full: 'full'
          };
    
          return {
            content: [{
              type: 'text',
              text: JSON.stringify({
                formatted: targetDate.toLocaleDateString(locale, { dateStyle: styleMap[style] }),
                style,
                locale,
                iso: targetDate.toISOString()
              }, null, 2)
            }]
          };
        } catch {
          return {
            content: [{ type: 'text', text: `Error: Invalid locale "${locale}".` }],
            isError: true
          };
        }
      }
    );

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other 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/ainarsklavins/date-mcp'

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