Skip to main content
Glama
bossjones
by bossjones

format-date

Transform dates into custom formats using a specified pattern. Input a date string and define the desired format (e.g., '%Y-%m-%d') to structure output accurately.

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

  • Handler function for executing the 'format-date' tool. Parses optional date input (defaults to current time), applies strftime formatting, handles parsing and formatting errors with 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}" ) ]
  • JSON Schema defining inputs for 'format-date' tool: 'date' (optional string), 'format' (required 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"] }
  • Registration of the 'format-date' tool in the @server.list_tools() function, specifying name, description, and input schema.
    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"] } )

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/bossjones/datetime-mcp-server'

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