MCP Server Time - 官方时间和时区转换服务器

简介

MCP Server Time 是 Anthropic 官方开发的时间和时区转换服务器,作为 Model Context Protocol 生态系统的参考实现之一。该服务器为大语言模型提供了准确的时间信息获取和时区转换能力,支持全球所有 IANA 时区标准,并能自动检测和使用系统时区。服务器实现了两个核心工具:获取当前时间和时区转换,使 AI 助手能够处理各种与时间相关的任务,如安排会议、计算时差、转换时间戳等。作为官方参考实现,该服务器展示了 MCP 协议在实用工具集成方面的标准实践,代码质量高,文档完善,是学习 MCP 开发的优秀示例。

功能特性

  • 获取当前时间 - 支持任意时区的精确时间查询
  • IANA 时区标准 - 支持全球所有 IANA 时区(如 America/New_York, Asia/Tokyo)
  • 时区转换 - 在不同时区之间进行时间转换
  • 自动时区检测 - 自动使用系统默认时区
  • 官方维护 - Anthropic 官方支持,质量保证
  • MIT 许可 - 开源许可,可自由使用
  • 多传输协议 - 支持 stdio 和 SSE 传输协议
  • Docker 支持 - 提供容器化部署方案
  • 调试工具 - 完整的 MCP Inspector 支持

支持的工具

get_current_time

获取指定时区或系统时区的当前时间。

参数:

  • timezone (string, 可选) - IANA 时区名称(如 ‘Europe/Warsaw’),默认使用系统时区

返回值: 当前时间的 ISO 8601 格式字符串及时区信息

使用示例:

1
2
3
4
用户: 请告诉我现在东京是几点
AI 将调用 get_current_time:
- timezone: "Asia/Tokyo"
返回: 2025-10-14T12:30:00+09:00 (东京时区)

convert_time

在不同时区之间转换时间。

参数:

  • source_timezone (string, 必需) - 源时区 IANA 名称
  • time (string, 必需) - 要转换的时间(HH:MM 格式)
  • target_timezone (string, 必需) - 目标时区 IANA 名称

返回值: 转换后的时间及相关时区信息

使用示例:

1
2
3
4
5
6
用户: 纽约时间下午4点30分在东京是几点?
AI 将调用 convert_time:
- source_timezone: "America/New_York"
- time: "16:30"
- target_timezone: "Asia/Tokyo"
返回: 次日上午5:30(东京时区)

安装配置

方法1: 使用 uv (推荐)

1
2
# 直接运行,无需安装
uvx mcp-server-time

方法2: 使用 pip

1
2
pip install mcp-server-time
mcp-server-time

方法3: 使用 Docker

1
2
3
cd src/time
docker build -t mcp/time .
docker run -i --rm mcp/time

Claude Desktop 配置

claude_desktop_config.json 中添加:

1
2
3
4
5
6
7
8
{
"mcpServers": {
"time": {
"command": "uvx",
"args": ["mcp-server-time"]
}
}
}

Zed 编辑器配置

1
2
3
4
5
6
7
8
{
"context_servers": {
"mcp-server-time": {
"command": "uvx",
"args": ["mcp-server-time"]
}
}
}

VS Code 配置

1
2
3
4
5
6
7
8
{
"mcp.servers": {
"time": {
"command": "uvx",
"args": ["mcp-server-time"]
}
}
}

使用场景

1. 跨国团队会议协调

1
2
用户: 我在伦敦,团队成员在旧金山和上海,如果我这里上午10点开会,他们那边是几点?
AI: 将分别转换时间到两个目标时区,帮助找到合适的会议时间

2. 国际航班时间规划

1
2
用户: 我从巴黎出发的航班是当地时间下午3点,到达纽约是什么时间?
AI: 计算时区差异和飞行时长,提供到达时间

3. 全球金融市场监控

1
2
用户: 伦敦股市开盘时,纽约和东京是几点?
AI: 转换伦敦上午8点到其他时区,帮助规划交易时间

4. 远程工作时间管理

1
2
用户: 我需要在太平洋时间工作,现在北京时间晚上8点,我应该几点上线?
AI: 将当前北京时间转换为太平洋时间,确定工作时间

IANA 时区数据库

全球主要时区

美洲 (Americas):

  • America/New_York - 美国东部时间 (ET)
  • America/Los_Angeles - 美国太平洋时间 (PT)
  • America/Chicago - 美国中部时间 (CT)
  • America/Denver - 美国山地时间 (MT)
  • America/Sao_Paulo - 巴西圣保罗
  • America/Mexico_City - 墨西哥城
  • America/Toronto - 加拿大多伦多

欧洲 (Europe):

  • Europe/London - 英国伦敦 (GMT/BST)
  • Europe/Paris - 法国巴黎 (CET/CEST)
  • Europe/Berlin - 德国柏林
  • Europe/Moscow - 俄罗斯莫斯科
  • Europe/Warsaw - 波兰华沙

亚洲 (Asia):

  • Asia/Tokyo - 日本东京 (JST)
  • Asia/Shanghai - 中国上海 (CST)
  • Asia/Hong_Kong - 中国香港
  • Asia/Singapore - 新加坡
  • Asia/Seoul - 韩国首尔
  • Asia/Dubai - 阿联酋迪拜
  • Asia/Kolkata - 印度加尔各答

大洋洲 (Pacific):

  • Pacific/Auckland - 新西兰奥克兰
  • Australia/Sydney - 澳大利亚悉尼
  • Pacific/Fiji - 斐济

非洲 (Africa):

  • Africa/Cairo - 埃及开罗
  • Africa/Johannesburg - 南非约翰内斯堡

时区格式说明

  • 标准格式: Region/City (如 Asia/Tokyo)
  • UTC 偏移: 显示为 +HH:MM-HH:MM
  • DST 状态: 自动检测夏令时并调整时间
  • ISO 8601: 返回标准时间格式 YYYY-MM-DDTHH:MM:SS±HH:MM

夏令时处理

服务器自动处理夏令时(Daylight Saving Time, DST):

  • 自动检测: 根据日期判断是否处于夏令时
  • 时差调整: 夏令时期间自动调整 UTC 偏移
  • 转换准确: 时区转换时考虑双方的 DST 状态

示例:

  • 美国东部时间: 冬季 UTC-5, 夏季 UTC-4
  • 欧洲中部时间: 冬季 UTC+1, 夏季 UTC+2

更多使用场景

5. 客户服务多时区支持

1
2
用户: 我们的客服团队在美国、印度和菲律宾,如何安排24小时覆盖?
AI: 计算各地时区,设计三地轮班时间表

6. 日志时间戳转换

1
2
开发者: 这条服务器日志是 2025-10-14 03:30 UTC,转成我的本地时间是几点?
AI: 将 UTC 时间转换为用户系统时区

7. 国际直播活动

1
2
用户: 我要在北京时间晚上8点直播,欧美观众那边是几点?
AI: 转换到纽约、伦敦、巴黎等主要城市时间

8. 数据库时间标准化

1
2
开发者: 我需要将所有用户提交的本地时间统一存储为 UTC
AI: 将各时区时间转换为 UTC 标准时间

最佳实践

1. 始终使用 IANA 时区名称

❌ 避免: “EST”, “PST”, “GMT+8”
✅ 推荐: “America/New_York”, “America/Los_Angeles”, “Asia/Shanghai”

2. 存储和传输使用 UTC

在数据库中存储 UTC 时间,展示时转换为用户时区

3. 考虑夏令时影响

不要手动计算时差,使用服务器的转换功能自动处理 DST

4. 时区验证

使用标准 IANA 时区名称,避免自定义或缩写

5. 用户体验优化

为用户显示时间时包含时区信息,避免歧义

6. 错误处理

处理无效时区名称,提供友好的错误提示

7. 性能优化

对于高频查询,考虑缓存时区转换结果(短时间内)

常见问题 (FAQ)

Q1: 服务器支持多少个时区?

A: 支持 IANA 时区数据库中的所有时区(约 600+ 个),涵盖全球所有国家和地区

Q2: 如何处理已废弃的时区名称?

A: IANA 数据库会将旧时区名称映射到当前标准名称,服务器自动处理这种映射

Q3: 时区转换是否考虑历史时区变化?

A: 是的,IANA 数据库包含历史时区规则,可以准确转换过去的时间

Q4: 如何获取系统默认时区?

A: 调用 get_current_time 不传 timezone 参数,将使用服务器系统时区

Q5: 支持自定义时区吗?

A: 不支持,只能使用 IANA 标准时区名称

Q6: 时间格式必须是 24 小时制吗?

A: convert_time 工具要求 24 小时制(HH:MM 格式),如 “14:30”

Q7: 如何查询完整的时区列表?

A: 参考 IANA 时区数据库文档或使用 timedatectl list-timezones 命令

Q8: 服务器是否支持毫秒精度?

A: 返回 ISO 8601 格式,精度取决于系统时钟,通常支持毫秒级

Q9: 跨日期的时区转换如何处理?

A: 服务器自动处理日期变化,返回完整的日期时间信息

Q10: 如何在没有网络的环境中使用?

A: 服务器在本地运行,不需要网络连接,时区数据内置在系统或包中

故障排除

问题1: 时区名称无效

错误: “Invalid timezone”
解决: 检查时区名称拼写,使用标准 IANA 格式(如 Asia/Tokyo)

问题2: 时间格式错误

错误: “Invalid time format”
解决: convert_time 需要 24 小时制,格式为 “HH:MM” (如 “14:30”)

问题3: 服务器无法启动

原因: Python 或依赖包未安装
解决: 确保已安装 Python 3.7+,使用 pip install mcp-server-time

问题4: Claude 未显示时间工具

原因: 配置文件错误或服务器未启动
解决: 检查 claude_desktop_config.json 配置,重启 Claude Desktop

问题5: 时区转换结果不符合预期

原因: 未考虑夏令时
解决: 服务器已自动处理 DST,检查输入参数和当前日期

项目信息

  • 作者/组织: Anthropic
  • 协议: MIT License
  • 语言: TypeScript
  • 依赖: @modelcontextprotocol/sdk, zod, moment-timezone
  • MCP SDK: latest
  • GitHub Stars: 70,200+
  • 最后更新: 2025-10-13

官方服务器 🌟

这是 Anthropic 官方维护的参考实现,代码质量和文档完善度有保证。作为 MCP 生态系统的标准工具之一,是学习 MCP 开发的优秀示例。

相关链接


English Version

Introduction

MCP Server Time is an official time and timezone conversion server developed by Anthropic as a reference implementation of the Model Context Protocol ecosystem. The server provides accurate time information retrieval and timezone conversion capabilities for large language models, supporting all IANA timezone standards worldwide and automatically detecting system timezones.

Key Features

  • Current Time Retrieval - Query accurate time for any timezone
  • IANA Timezone Standards - Support for all global IANA timezones
  • Timezone Conversion - Convert times between different zones
  • Auto Timezone Detection - Automatically use system default timezone
  • Official Maintenance - Anthropic official support with quality assurance
  • MIT License - Open source, free to use
  • Multiple Transport Protocols - Support for stdio and SSE
  • Docker Support - Containerized deployment available
  • Debug Tools - Full MCP Inspector support

Available Tools

get_current_time

Retrieve the current time in a specified timezone or system timezone.

Parameters:

  • timezone (string, optional) - IANA timezone name (e.g., ‘Europe/Warsaw’), defaults to system timezone

Returns: Current time in ISO 8601 format with timezone information

convert_time

Convert time between different timezones.

Parameters:

  • source_timezone (string, required) - Source IANA timezone name
  • time (string, required) - Time to convert (HH:MM format)
  • target_timezone (string, required) - Target IANA timezone name

Returns: Converted time with timezone information

Installation

1
uvx mcp-server-time

Method 2: Using pip

1
2
pip install mcp-server-time
mcp-server-time

Method 3: Using Docker

1
2
3
cd src/time
docker build -t mcp/time .
docker run -i --rm mcp/time

Use Cases

  1. International Team Meeting Coordination - Schedule meetings across multiple timezones
  2. Travel Time Planning - Calculate arrival times for international flights
  3. Global Financial Markets - Track market opening times worldwide
  4. Remote Work Management - Coordinate work hours across timezones
  5. 24/7 Customer Support - Plan timezone-aware support coverage
  6. Log Timestamp Conversion - Convert server logs to local time
  7. Live Event Broadcasting - Schedule international livestreams
  8. Database Time Standardization - Convert local times to UTC

Best Practices

  1. Always use IANA timezone names - Avoid abbreviations like “EST” or “PST”
  2. Store in UTC - Save times in UTC, convert for display
  3. Handle DST automatically - Let the server handle daylight saving time
  4. Validate timezones - Use standard IANA names only
  5. Show timezone info - Always display timezone when showing time to users
  6. Error handling - Handle invalid timezone names gracefully
  7. Performance optimization - Cache conversion results for high-frequency queries

FAQ

Q: How many timezones are supported?
A: All 600+ timezones in the IANA timezone database covering all countries and regions worldwide.

Q: Does it handle daylight saving time?
A: Yes, DST is automatically detected and handled based on date and timezone rules.

Q: What time format is required?
A: convert_time requires 24-hour format (HH:MM) such as “14:30”.

Q: Can I use without internet?
A: Yes, the server runs locally with built-in timezone data, no internet required.

Q: How to get the full timezone list?
A: Refer to IANA timezone database documentation or use timedatectl list-timezones command.


Rating: 4.8/5.0

  • Functionality: 5.0
  • Documentation: 4.8
  • Activity: 5.0
  • Popularity: 4.5
  • Code Quality: 5.0

GitHub: modelcontextprotocol/servers

© 2025 Generative AI Discovery All Rights Reserved.
Theme by hiero