Skip to main content
Glama
bossjones
by bossjones

get-current-time

Retrieve the current time in multiple formats (ISO, readable, Unix, RFC3339) with an optional timezone parameter using the Datetime MCP Server tool.

Instructions

Get the current time in various formats

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatYesFormat to return the time in
timezoneNoOptional timezone (default: local system timezone)

Implementation Reference

  • Handler function that executes the get-current-time tool. Parses format and optional timezone arguments, handles pytz import and timezone errors, formats the current time using the format_time helper, and returns it as TextContent.
    elif name == "get-current-time": if not arguments: raise ValueError("Missing arguments") time_format = arguments.get("format") timezone = arguments.get("timezone") if not time_format: raise ValueError("Missing format argument") # Handle timezone if provided, otherwise use system timezone if timezone: try: import pytz tz = pytz.timezone(timezone) now = datetime.datetime.now(tz) except ImportError: return [ types.TextContent( type="text", text="The pytz library is not available. Using system timezone instead." ), types.TextContent( type="text", text=format_time(datetime.datetime.now(), time_format) ) ] except Exception as e: return [ types.TextContent( type="text", text=f"Error with timezone '{timezone}': {str(e)}. Using system timezone instead." ), types.TextContent( type="text", text=format_time(datetime.datetime.now(), time_format) ) ] else: now = datetime.datetime.now() return [ types.TextContent( type="text", text=format_time(now, time_format) ) ]
  • JSON Schema defining the input parameters for the get-current-time tool: required 'format' (enum: iso, readable, unix, rfc3339), optional 'timezone'.
    inputSchema={ "type": "object", "properties": { "format": { "type": "string", "enum": ["iso", "readable", "unix", "rfc3339"], "description": "Format to return the time in" }, "timezone": { "type": "string", "description": "Optional timezone (default: local system timezone)" } }, "required": ["format"] }
  • Registration of the 'get-current-time' tool in the list_tools handler, including name, description, and input schema.
    types.Tool( name="get-current-time", description="Get the current time in various formats", inputSchema={ "type": "object", "properties": { "format": { "type": "string", "enum": ["iso", "readable", "unix", "rfc3339"], "description": "Format to return the time in" }, "timezone": { "type": "string", "description": "Optional timezone (default: local system timezone)" } }, "required": ["format"] } ),
  • Helper function format_time used by the get-current-time handler to format the datetime according to the specified format type (iso, readable, unix, rfc3339).
    def format_time(dt: datetime.datetime, format_type: str) -> str: """ Format a datetime object according to the specified format. Args: dt (datetime.datetime): The datetime to format. format_type (str): The format type (iso, readable, unix, rfc3339). Returns: str: The formatted datetime string. """ if format_type == "iso": return dt.isoformat() elif format_type == "readable": return dt.strftime("%Y-%m-%d %H:%M:%S") elif format_type == "unix": return str(int(dt.timestamp())) elif format_type == "rfc3339": return dt.strftime("%Y-%m-%dT%H:%M:%S%z") else: return dt.isoformat()

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