c

chuk-mcp-time-server 时间微服务工具

@chrishayuk/chuk-mcp-time-server
1 Stars 253 次浏览 chrishayuk 更新于 2026-08-23

一个提供获取当前时间及在不同全球时区之间转换的实用工具的Python微服务,并具有强大的验证功能。

该服务暂未提供标准配置,请参考 README 手动接入

服务介绍

MCP 时间服务器

概述

MCP 时间服务器是一个基于 Python 的微服务,旨在提供跨越不同时区的高级时间相关工具。它提供了强大的功能来检索当前时间和在不同的全球时区之间转换时间。

项目详情

  • 版本: 0.1.1
  • Python 兼容性: Python 3.11+

特性

  • 获取当前时间: 获取任何 IANA 时区的当前时间
  • 时区转换: 在不同的时区之间转换时间
  • 全面验证: 使用 Pydantic 模型进行强大的输入验证
  • 异步服务器架构: 使用 asyncio 构建以实现高效性能
  • 灵活配置: 可通过环境变量和配置文件进行配置

依赖项

核心依赖:

  • mcp (>=1.6.0)
  • pydantic (>=2.11.2)
  • PyYAML (>=6.0.2)
  • pyz (>=0.4.3)

开发依赖:

  • pytest (>=8.3.5)

安装

前提条件

  • Python 3.11 或更高版本
  • pip
  • (可选) 推荐使用虚拟环境

从 PyPI 安装

pip install chuk-mcp-time-server

从源代码安装

  1. 克隆仓库:
git clone <repository-url>
cd chuk-mcp-time-server
  1. 创建一个虚拟环境:
python -m venv venv
source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
  1. 安装包:
pip install .  # Installs the package in editable mode

开发安装

要设置开发环境:

pip install .[dev]  # Installs package with development dependencies

运行服务器

命令行接口

chuk-mcp-time-server

程序化使用

from chuk_mcp_time_server.main import main

if __name__ == "__main__":
    main()

环境变量

  • NO_BOOTSTRAP: 设置为禁用组件引导
  • 其他配置选项可以在配置文件中设置

可用工具

1. 获取当前时间

输入:

  • timezone: IANA 时区名称(例如,'America/New_York')

示例:

get_current_time('Europe/London')

返回:

  • 指定时区的当前时间
  • 时区详细信息
  • 夏令时 (DST) 状态

2. 转换时间

输入:

  • source_timezone: 源时区 (IANA 格式)
  • time: 时间 (HH:MM, 24小时制格式)
  • target_timezone: 目标时区 (IANA 格式)

示例:

convert_time('America/New_York', '14:30', 'Europe/Paris')

返回:

  • 源时间详细信息
  • 目标时间详细信息
  • 时区之间的时间差

开发

代码格式化

  • 使用 Black 进行代码格式化
  • 使用 isort 进行导入排序
  • 行长度设置为 88 个字符

运行测试

pytest

贡献

  1. 分叉仓库
  2. 创建你的功能分支 (git checkout -b feature/AmazingFeature)
  3. 确保代码通过格式化和测试
  4. 提交你的更改 (git commit -m 'Add some AmazingFeature')
  5. 将分支推送到远程 (git push origin feature/AmazingFeature)
  6. 打开一个 Pull Request

许可证

MIT 许可证

相关 MCP 服务