get_time
Retrieve real-time environmental time data including local time, UTC, timezone, and timestamps to provide accurate responses to time-sensitive queries and current events.
Instructions
【必须调用】获取用户环境的实时时间信息。
⚠️ 重要:你的训练数据和系统提示中的时间信息可能不准确或过时,必须调用此工具获取用户的真实当前时间。
强制调用场景(必须调用,不要依赖你的知识):
用户提到"现在"、"今天"、"最近"、"这周"、"这个月"、"今年"等时间词
用户询问时间相关的事件、新闻、趋势(如"最近有什么AI大事件")
需要判断某个日期是过去还是未来
分析时间敏感的数据(日志、事件、截止日期)
任何需要知道"当前时间"才能准确回答的问题
返回信息:用户本地时间、UTC时间、时区、Unix时间戳、完整的年月日时分秒、星期等。
⚠️ 不要假设你知道当前时间,必须调用此工具!
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | 时间格式:'iso' (ISO 8601), 'locale' (本地化), 'unix' (Unix时间戳) | iso |
Implementation Reference
- src/tools/time.ts:1-35 (handler)The getTimeInfo function implements the core logic for the 'get_time' tool, computing various time-related information based on the optional format parameter ('iso', 'locale', 'unix').export async function getTimeInfo(format: string = "iso") { const now = new Date(); const timeInfo = { timestamp: now.getTime(), iso: now.toISOString(), locale: now.toLocaleString(), utc: now.toUTCString(), timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, timezoneOffset: now.getTimezoneOffset(), year: now.getFullYear(), month: now.getMonth() + 1, day: now.getDate(), hour: now.getHours(), minute: now.getMinutes(), second: now.getSeconds(), dayOfWeek: now.toLocaleDateString('zh-CN', { weekday: 'long' }), }; // 根据格式返回不同的结果 if (format === "unix") { return { timestamp: timeInfo.timestamp, timezone: timeInfo.timezone, }; } else if (format === "locale") { return { locale: timeInfo.locale, timezone: timeInfo.timezone, dayOfWeek: timeInfo.dayOfWeek, }; } return timeInfo; }
- src/index.ts:187-197 (registration)In the CallToolRequestSchema handler, the switch case for 'get_time' invokes the getTimeInfo handler and formats the result as MCP content.case "get_time": { const result = await getTimeInfo(args?.format as string); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; }
- src/index.ts:32-59 (registration)The 'get_time' tool registration in ListToolsRequestSchema, including name, description, and input schema.{ name: "get_time", description: `【必须调用】获取用户环境的实时时间信息。 ⚠️ 重要:你的训练数据和系统提示中的时间信息可能不准确或过时,必须调用此工具获取用户的真实当前时间。 强制调用场景(必须调用,不要依赖你的知识): - 用户提到"现在"、"今天"、"最近"、"这周"、"这个月"、"今年"等时间词 - 用户询问时间相关的事件、新闻、趋势(如"最近有什么AI大事件") - 需要判断某个日期是过去还是未来 - 分析时间敏感的数据(日志、事件、截止日期) - 任何需要知道"当前时间"才能准确回答的问题 返回信息:用户本地时间、UTC时间、时区、Unix时间戳、完整的年月日时分秒、星期等。 ⚠️ 不要假设你知道当前时间,必须调用此工具!`, inputSchema: { type: "object", properties: { format: { type: "string", description: "时间格式:'iso' (ISO 8601), 'locale' (本地化), 'unix' (Unix时间戳)", enum: ["iso", "locale", "unix"], default: "iso", }, }, }, },
- src/index.ts:48-58 (schema)Input schema definition for the 'get_time' tool, specifying the optional 'format' parameter with possible values and default.inputSchema: { type: "object", properties: { format: { type: "string", description: "时间格式:'iso' (ISO 8601), 'locale' (本地化), 'unix' (Unix时间戳)", enum: ["iso", "locale", "unix"], default: "iso", }, }, },