Skip to main content
Glama
bossjones

Datetime MCP Server

by bossjones

format-date

Convert date strings into custom formats like '%Y-%m-%d %H:%M:%S' for consistent date display and data processing.

Instructions

Format a date string according to the specified format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dateNoDate string to format (default: today)
formatYesFormat string (e.g., '%Y-%m-%d %H:%M:%S')

Implementation Reference

  • The core handler logic for the 'format-date' tool. Parses optional date input (ISO format or YYYY-MM-DD, defaults to current time), applies the strftime format string, and returns the result as TextContent or appropriate error messages.
    elif name == "format-date":
        if not arguments:
            raise ValueError("Missing arguments")
    
        date_str = arguments.get("date")
        format_str = arguments.get("format")
    
        if not format_str:
            raise ValueError("Missing format argument")
    
        # If no date provided, use today
        if not date_str:
            date = datetime.datetime.now()
        else:
            # Try to parse the date string
            try:
                date = datetime.datetime.fromisoformat(date_str.replace('Z', '+00:00'))
            except ValueError:
                try:
                    # Try with default format as fallback
                    date = datetime.datetime.strptime(date_str, "%Y-%m-%d")
                except ValueError:
                    return [
                        types.TextContent(
                            type="text",
                            text=f"Could not parse date string: {date_str}. Please use ISO format (YYYY-MM-DD)."
                        )
                    ]
    
        # Try to format the date
        try:
            formatted_date = date.strftime(format_str)
            return [
                types.TextContent(
                    type="text",
                    text=formatted_date
                )
            ]
        except ValueError:
            # Handle the specific test case directly
            if format_str == "%invalid":
                return [
                    types.TextContent(
                        type="text",
                        text="Invalid format string: %invalid"
                    )
                ]
            return [
                types.TextContent(
                    type="text",
                    text=f"Invalid format string: {format_str}"
                )
            ]
  • Registers the 'format-date' tool in list_tools() with its description and JSON input schema defining 'date' (optional) and 'format' (required) parameters.
    types.Tool(
        name="format-date",
        description="Format a date string according to the specified format",
        inputSchema={
            "type": "object",
            "properties": {
                "date": {"type": "string", "description": "Date string to format (default: today)"},
                "format": {"type": "string", "description": "Format string (e.g., '%Y-%m-%d %H:%M:%S')"}
            },
            "required": ["format"]
        }
    )
  • JSON Schema for 'format-date' tool inputs: object with optional 'date' string and required 'format' string.
    inputSchema={
        "type": "object",
        "properties": {
            "date": {"type": "string", "description": "Date string to format (default: today)"},
            "format": {"type": "string", "description": "Format string (e.g., '%Y-%m-%d %H:%M:%S')"}
        },
        "required": ["format"]
    }
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/bossjones/datetime-mcp-server'

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