sys_time
Retrieve current date and time for any specified timezone, with customizable format for output.
Instructions
获取当前日期和时间,支持指定时区。
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "sys_time"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timezone | No | 时区名称,如 Asia/Shanghai、UTC、America/New_York(默认 UTC) | UTC |
| format | No | 时间格式字符串(默认 %Y-%m-%d %H:%M:%S) | %Y-%m-%d %H:%M:%S |
Implementation Reference
- The _sys_time function is the core handler for the sys_time tool. It takes a timezone name (default UTC) and format string (default %Y-%m-%d %H:%M:%S), retrieves the current time using ZoneInfo, and returns formatted output including the time, UTC offset, Unix timestamp, and ISO 8601 representation.
def _sys_time(args: dict) -> list[types.TextContent]: tz_name = args.get("timezone", "UTC") fmt = args.get("format", "%Y-%m-%d %H:%M:%S") try: tz = ZoneInfo(tz_name) except ZoneInfoNotFoundError: return [types.TextContent( type="text", text=f"❌ 未知时区: {tz_name}\n示例: Asia/Shanghai, UTC, America/New_York", )] now = datetime.now(tz) return [types.TextContent(type="text", text=( f"🕐 当前时间\n\n" f"时区: {tz_name}\n" f"时间: {now.strftime(fmt)}\n" f"UTC偏移: {now.strftime('%z')}\n" f"Unix时间: {int(now.timestamp())}\n" f"ISO 8601: {now.isoformat()}" ))] - The inputSchema for sys_time defines two optional parameters: 'timezone' (string, default UTC) and 'format' (string, default %Y-%m-%d %H:%M:%S). This schema is registered as part of the SYSTEM_TOOLS list.
description="获取当前日期和时间,支持指定时区。", inputSchema={ "type": "object", "properties": { "timezone": { "type": "string", "description": "时区名称,如 Asia/Shanghai、UTC、America/New_York(默认 UTC)", "default": "UTC", }, "format": { "type": "string", "description": "时间格式字符串(默认 %Y-%m-%d %H:%M:%S)", "default": "%Y-%m-%d %H:%M:%S", }, }, }, - src/onion_mcp_server/server.py:60-61 (registration)The sys_time tool name is mapped to the handle_system dispatch function in the server's routing table. The registration iterates over SYSTEM_TOOLS and assigns handle_system as the handler for each tool name (including sys_time).
for _t in SYSTEM_TOOLS: _HANDLERS[_t.name] = handle_system - src/onion_mcp_server/tools/system.py:175-187 (registration)The handle_system dispatch function routes the 'sys_time' name to the _sys_time handler via a dictionary lookup. This is the intermediate routing layer between the server and the tool implementation.
async def handle_system(name: str, arguments: dict) -> list[types.TextContent]: handlers = { "sys_time": _sys_time, "sys_uuid": _sys_uuid, "sys_hash": _sys_hash, "sys_base64": _sys_base64, "sys_url_encode": _sys_url_encode, "sys_json_valid": _sys_json_valid, } fn = handlers.get(name) if fn is None: raise ValueError(f"未知 system 工具: {name}") return fn(arguments)