Skip to main content
Glama
ZeparHyfar

mcp-datetime

by ZeparHyfar

get_datetime

Retrieve current date and time in multiple formats including ISO, localized, filename-friendly, and compact options for integration and display purposes.

Instructions

Get current date and time in various formats

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatYes Available formats: - date: 2024-12-10 - date_slash: 2024/12/10 - date_jp: 2024年12月10日 - datetime: 2024-12-10 00:54:01 - datetime_jp: 2024年12月10日 00時54分01秒 - datetime_t: 2024-12-10T00:54:01 - compact: 20241210005401 - compact_date: 20241210 - compact_time: 005401 - filename_md: 20241210005401.md - filename_txt: 20241210005401.txt - filename_log: 20241210005401.log - iso: 2024-12-10T00:54:01+0900 - iso_basic: 20241210T005401+0900 - log: 2024-12-10 00:54:01.123456 - log_compact: 20241210_005401 - time: 00:54:01 - time_jp: 00時54分01秒

Implementation Reference

  • Implements the handler logic for the 'get_datetime' tool, extracting the format from arguments, calling format_datetime, and returning the formatted time as TextContent. Handles ValueError by logging and re-raising as RuntimeError.
    if name == "get_datetime":
        try:
            format_type = arguments.get("format")
            if not format_type:
                raise ValueError("Format type is required")
            formatted_time = format_datetime(format_type)
            return [TextContent(type="text", text=formatted_time)]
        except ValueError as e:
            logger.error("Format error: %s", str(e))
            raise RuntimeError(str(e)) from e
  • Registers the 'get_datetime' tool via the list_tools decorator, providing name, description, and inputSchema.
    @server.list_tools()
    async def list_tools() -> list[Tool]:
        return [
            Tool(
                name="get_datetime",
                description="Get current date and time in various formats",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "format": {
                            "type": "string",
                            "description": """
    Available formats:
    - date: 2024-12-10
    - date_slash: 2024/12/10
    - date_jp: 2024年12月10日
    - datetime: 2024-12-10 00:54:01
    - datetime_jp: 2024年12月10日 00時54分01秒
    - datetime_t: 2024-12-10T00:54:01
    - compact: 20241210005401
    - compact_date: 20241210
    - compact_time: 005401
    - filename_md: 20241210005401.md
    - filename_txt: 20241210005401.txt
    - filename_log: 20241210005401.log
    - iso: 2024-12-10T00:54:01+0900
    - iso_basic: 20241210T005401+0900
    - log: 2024-12-10 00:54:01.123456
    - log_compact: 20241210_005401
    - time: 00:54:01
    - time_jp: 00時54分01秒
    """,
                        }
                    },
                    "required": ["format"],
                },
            )
        ]
  • Defines the input schema for 'get_datetime' tool, requiring a 'format' string property with description of available formats.
                inputSchema={
                    "type": "object",
                    "properties": {
                        "format": {
                            "type": "string",
                            "description": """
    Available formats:
    - date: 2024-12-10
    - date_slash: 2024/12/10
    - date_jp: 2024年12月10日
    - datetime: 2024-12-10 00:54:01
    - datetime_jp: 2024年12月10日 00時54分01秒
    - datetime_t: 2024-12-10T00:54:01
    - compact: 20241210005401
    - compact_date: 20241210
    - compact_time: 005401
    - filename_md: 20241210005401.md
    - filename_txt: 20241210005401.txt
    - filename_log: 20241210005401.log
    - iso: 2024-12-10T00:54:01+0900
    - iso_basic: 20241210T005401+0900
    - log: 2024-12-10 00:54:01.123456
    - log_compact: 20241210_005401
    - time: 00:54:01
    - time_jp: 00時54分01秒
    """,
                        }
                    },
                    "required": ["format"],
                },
  • Helper function that formats the current UTC datetime (converted to local timezone) according to the specified format_type using a predefined dictionary of strftime formats.
    def format_datetime(format_type: str) -> str:
        # Generate a new time object each time, considering timezone
        current_time = datetime.now(timezone.utc).astimezone()
        formats = {
            # Basic date formats
            "date": "%Y-%m-%d",  # 2024-12-10
            "date_slash": "%Y/%m/%d",  # 2024/12/10
            "date_jp": "%Y年%m月%d日",  # 2024年12月10日
            # Basic datetime formats
            "datetime": "%Y-%m-%d %H:%M:%S",  # 2024-12-10 00:54:01
            "datetime_jp": "%Y年%m月%d日 %H時%M分%S秒",  # 2024年12月10日 00時54分01秒
            "datetime_t": "%Y-%m-%dT%H:%M:%S",  # 2024-12-10T00:54:01
            # Compact formats for filenames or IDs
            "compact": "%Y%m%d%H%M%S",  # 20241210005401
            "compact_date": "%Y%m%d",  # 20241210
            "compact_time": "%H%M%S",  # 005401
            # Filename formats
            "filename_md": "%Y%m%d%H%M%S.md",  # 20241210005401.md
            "filename_txt": "%Y%m%d%H%M%S.txt",  # 20241210005401.txt
            "filename_log": "%Y%m%d%H%M%S.log",  # 20241210005401.log
            # ISO 8601 formats
            "iso": "%Y-%m-%dT%H:%M:%S%z",  # 2024-12-10T00:54:01+0900
            "iso_basic": "%Y%m%dT%H%M%S%z",  # 20241210T005401+0900
            # Log formats
            "log": "%Y-%m-%d %H:%M:%S.%f",  # 2024-12-10 00:54:01.123456
            "log_compact": "%Y%m%d_%H%M%S",  # 20241210_005401
            # Time-only formats
            "time": "%H:%M:%S",  # 00:54:01
            "time_jp": "%H時%M分%S秒",  # 00時54分01秒
        }
    
        if format_type not in formats:
            raise ValueError(f"Unknown format type: {format_type}")
    
        try:
            return current_time.strftime(formats[format_type])
        except Exception as e:
            logger.error("Format error: %s", str(e))
            raise RuntimeError(f"Error formatting date: {str(e)}") from e

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A3.7/5.0
Behavior3/5

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

No annotations are present, so the description must carry the burden of behavioral disclosure. It implies a read-only operation but does not explicitly state that it has no side effects or that it returns the current server time. The description is adequate but not comprehensive.

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, front-loaded sentence that efficiently communicates the tool's function without unnecessary words.

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

Completeness5/5

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

For a simple tool with one well-documented parameter and no output schema, the description covers the essential information. It is complete for its complexity level.

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 description coverage is 100% for the single parameter, which already provides extensive detail on the 'format' options. The description adds no additional meaning beyond what the schema already conveys.

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

Purpose5/5

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

The description clearly states the tool's action ('Get') and resource ('current date and time in various formats'), providing a specific and unambiguous purpose.

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?

No guidance is provided on when to use this tool versus alternatives. Since there are no sibling tools listed, this is a minor gap, but the description does not include any contextual usage instructions.

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

Deploy Server

Other Tools