Skip to main content
Glama
isdaniel

Weather MCP Server

get_current_datetime

Retrieve the current date and time for any IANA timezone. Simply provide the timezone name to get accurate local time.

Instructions

Get current time in specified timezone.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timezone_nameYesIANA timezone name (e.g., 'America/New_York', 'Europe/London'). Use UTC timezone if no timezone provided by the user.

Implementation Reference

  • The main handler class for the 'get_current_datetime' tool. It extends ToolHandler, registers the tool name, provides schema via get_tool_description(), and executes the core logic in run_tool() by resolving the timezone via utils.get_zoneinfo() and returning the current datetime formatted as JSON.
    class GetCurrentDateTimeToolHandler(ToolHandler):
        """
        Tool handler for getting current date and time in a specified timezone.
        """
    
        def __init__(self):
            super().__init__("get_current_datetime")
    
        def get_tool_description(self) -> Tool:
            """
            Return the tool description for current datetime lookup.
            """
            return Tool(
                name=self.name,
                description="""Get current time in specified timezone.""",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "timezone_name": {
                            "type": "string",
                            "description": "IANA timezone name (e.g., 'America/New_York', 'Europe/London'). Use UTC timezone if no timezone provided by the user."
                        }
                    },
                    "required": ["timezone_name"]
                }
            )
    
        async def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]:
            """
            Execute the current datetime tool.
            """
            try:
                self.validate_required_args(args, ["timezone_name"])
    
                timezone_name = args["timezone_name"]
                logger.info(f"Getting current time for timezone: {timezone_name}")
    
                # Get timezone info
                timezone = utils.get_zoneinfo(timezone_name)
                current_time = datetime.now(timezone)
    
                # Create time result
                time_result = utils.TimeResult(
                    timezone=timezone_name,
                    datetime=current_time.isoformat(timespec="seconds"),
                )
    
                return [
                    TextContent(
                        type="text",
                        text=json.dumps(time_result.model_dump(), indent=2)
                    )
                ]
    
            except Exception as e:
                logger.exception(f"Error in get_current_datetime: {str(e)}")
                return [
                    TextContent(
                        type="text",
                        text=f"Error getting current time: {str(e)}"
                    )
                ]
  • Input/output schema for the tool. Requires a 'timezone_name' string parameter (IANA timezone name). Returns JSON with 'timezone' and 'datetime' fields via the TimeResult model.
    def get_tool_description(self) -> Tool:
        """
        Return the tool description for current datetime lookup.
        """
        return Tool(
            name=self.name,
            description="""Get current time in specified timezone.""",
            inputSchema={
                "type": "object",
                "properties": {
                    "timezone_name": {
                        "type": "string",
                        "description": "IANA timezone name (e.g., 'America/New_York', 'Europe/London'). Use UTC timezone if no timezone provided by the user."
                    }
                },
                "required": ["timezone_name"]
            }
        )
  • Registration of the GetCurrentDateTimeToolHandler in the central register_all_tools() function, which calls add_tool_handler() to store it in the global tool_handlers dictionary.
    add_tool_handler(GetCurrentDateTimeToolHandler())
    add_tool_handler(GetTimeZoneInfoToolHandler())
  • Helper utilities: TimeResult Pydantic model defines the output schema (timezone string + datetime string), and get_zoneinfo() resolves an IANA timezone name to a ZoneInfo object, raising McpError on invalid timezone names.
    class TimeResult(BaseModel):
        timezone: str
        datetime: str
    
    def get_zoneinfo(timezone_name: str) -> ZoneInfo:
        try:
            return ZoneInfo(timezone_name)
        except Exception as e:
            error_data = ErrorData(code=-1, message=f"Invalid timezone: {str(e)}")
            raise McpError(error_data)
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must disclose behavior. It states the tool returns the current time, but does not specify that it relies on server time, that it's read-only, or any other behavioral traits. For a simple read operation, this is adequate but minimal.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, concise sentence that immediately conveys the tool's purpose. No redundant information, and it is front-loaded with the primary action.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's simplicity (one parameter, no output schema), the description is largely complete. It could benefit from a slight elaboration to differentiate from sibling tools, but it sufficiently covers the core functionality.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3. The description does not add meaning beyond the schema, which already provides an example and fallback instruction. The tool description itself is too brief to enhance parameter understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool gets the current time in a specified timezone. However, it doesn't differentiate from sibling tools like 'convert_time' or 'get_timezone_info', which could be used for related purposes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for obtaining current time in a timezone but provides no explicit guidance on when to use this tool versus alternatives like 'get_timezone_info' or 'convert_time'. No exclusion criteria are given.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/isdaniel/mcp_weather_server'

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