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
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions the tool returns current date/time in various formats, which is basic behavioral information. However, it lacks details about whether this is a read-only operation, if it requires any permissions, how it handles timezones, or what happens on errors. For a tool with no annotation coverage, this is insufficient disclosure.

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, efficient sentence that communicates the core purpose without any unnecessary words. It's appropriately sized and front-loaded with the essential information.

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

Completeness3/5

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

Given the tool's low complexity (single parameter, no output schema, no annotations), the description is reasonably complete for basic understanding. However, it lacks information about return values, error handling, and timezone behavior which would be helpful for a datetime tool.

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 description mentions 'various formats' which hints at the format parameter, but the input schema already provides 100% coverage with a comprehensive list of format options. The description adds minimal value beyond what's in the schema, so it meets the baseline for high schema coverage.

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 verb ('Get') and resource ('current date and time'), specifying the action and what it returns. It also mentions the key capability 'in various formats' which adds useful context. However, with no sibling tools to distinguish from, it cannot achieve the highest score for sibling differentiation.

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 or in what contexts it's appropriate. It simply states what the tool does without any usage instructions, prerequisites, or exclusions.

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

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