Skip to main content
Glama
isdaniel

Weather MCP Server

get_current_datetime

Retrieve current time for any IANA timezone to coordinate weather data with 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 GetCurrentDateTimeToolHandler class provides the full implementation of the 'get_current_datetime' tool, including initialization with the tool name, schema definition via get_tool_description, and execution logic in run_tool which retrieves the current datetime for the given timezone using zoneinfo and returns it 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)}"
                    )
                ]
  • Registration of the GetCurrentDateTimeToolHandler instance in the server's tool registry via add_tool_handler during initialization in register_all_tools().
    add_tool_handler(GetCurrentDateTimeToolHandler())
  • Input schema definition for the 'get_current_datetime' tool, specifying the required 'timezone_name' parameter as a string.
        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"]
        }
    )
  • Helper function get_zoneinfo that resolves the IANA timezone name to a zoneinfo.ZoneInfo object, used in the tool handler.
    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)
  • Pydantic model TimeResult used to structure the tool's output data containing timezone and datetime.
    class TimeResult(BaseModel):
        timezone: str
        datetime: str
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states what the tool does but doesn't describe important behavioral aspects like the return format, whether it's a read-only operation, error handling for invalid timezones, or performance characteristics. The description is minimal and lacks behavioral context.

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 extremely concise - a single sentence that communicates the core functionality without any wasted words. It's front-loaded with the essential information and doesn't contain unnecessary elaboration.

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

Completeness2/5

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

For a tool with no annotations and no output schema, the description is insufficient. It doesn't explain what format the current time is returned in (timestamp, string, object), doesn't mention error conditions, and provides minimal behavioral context. Given the lack of structured metadata, the description should do more to compensate.

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?

The schema has 100% description coverage, so the parameter is well-documented in the structured schema. The description adds minimal value beyond the schema by mentioning 'specified timezone' but doesn't provide additional context about the parameter's purpose or usage beyond what's already in the schema description.

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 action ('Get current time') and the resource ('in specified timezone'), making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools like 'get_timezone_info' or 'convert_time', but the specificity of 'current time' provides some implicit distinction.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'get_timezone_info' or 'convert_time'. It mentions the timezone parameter but doesn't explain when this tool is appropriate versus other time-related tools in the sibling list.

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