Skip to main content

基于SSE传输的MCP时间服务器,提供多时区时间查询功能

Project description

FastMCP Time Service

PyPI version Python License: MIT

基于SSE传输的MCP时间服务器,提供多时区时间查询功能。这是一个基于 Model Context Protocol (MCP) 和 FastMCP 框架构建的时间服务。

功能特性

  • 🌍 多时区支持 - 支持全球各地时区的时间查询
  • 🇨🇳 中文友好 - 支持中文时区名称输入
  • 高性能 - 基于 FastMCP 框架,支持异步处理
  • 🔧 易于配置 - 支持环境变量配置服务器参数
  • 📡 标准协议 - 完全兼容 MCP 协议标准

安装

使用 pip 安装:

pip install fastmcp-time-service

快速开始

作为 CLI 工具运行

安装后,可以直接通过命令行启动服务:

fastmcp-time-service

作为 Python 模块使用

from fastmcp_time_service import TimeServer

# 创建时间服务器实例
server = TimeServer()

# 启动服务器
server.run()

自定义配置

通过环境变量配置服务器:

export MCP_TIME_HOST=127.0.0.1
export MCP_TIME_PORT=8005
fastmcp-time-service

或在代码中直接指定:

from fastmcp_time_service import TimeServer

# 自定义主机和端口
server = TimeServer(host="127.0.0.1", port=8005)
server.run()

MCP 工具

get_current_time

获取指定时区的当前时间。

参数:

  • timezone (可选): 时区名称,默认为 "Asia/Shanghai"

支持的时区格式:

  • 标准时区名称: "Asia/Shanghai", "America/New_York", "Europe/London"
  • 中文别名: "中国", "北京", "上海"
  • 英文别名: "China", "Beijing", "CST"

示例:

# 获取北京时间
result = await get_current_time("Asia/Shanghai")
# 输出: "Asia/Shanghai 的当前时间是: 2024年01月15日 14:30:25 CST"

# 使用中文别名
result = await get_current_time("北京")
# 输出: "北京 的当前时间是: 2024年01月15日 14:30:25 CST"

# 获取纽约时间
result = await get_current_time("America/New_York")
# 输出: "America/New_York 的当前时间是: 2024年01月15日 01:30:25 EST"

配置说明

环境变量

  • MCP_TIME_HOST: 服务器绑定地址,默认 0.0.0.0
  • MCP_TIME_PORT: 服务器端口,默认 8005

配置文件

支持使用 .env 文件进行配置:

MCP_TIME_HOST=127.0.0.1
MCP_TIME_PORT=8005

在 MCP 客户端中使用

Claude Desktop 配置

claude_desktop_config.json 中添加:

{
  "mcpServers": {
    "time-service": {
      "command": "fastmcp-time-service",
      "transport": "stdio"
    }
  }
}

自定义 MCP 客户端

import asyncio
from mcp.client.stdio import StdioServerParameters, stdio_client

async def main():
    server_params = StdioServerParameters(
        command="fastmcp-time-service",
        args=[]
    )
    
    async with stdio_client(server_params) as (read, write):
        # 使用 MCP 客户端调用时间工具
        pass

if __name__ == "__main__":
    asyncio.run(main())

开发

本地开发

  1. 克隆仓库:
git clone https://github.com/AlexLIAOwang/fastmcp-time-service.git
cd fastmcp-time-service
  1. 安装开发依赖:
pip install -e ".[dev]"
  1. 运行测试:
pytest

代码格式化

# 使用 black 格式化代码
black fastmcp_time_service/

# 使用 ruff 进行代码检查
ruff check fastmcp_time_service/

许可证

本项目采用 MIT 许可证 - 详见 LICENSE 文件。

贡献

欢迎贡献代码!请遵循以下步骤:

  1. Fork 本仓库
  2. 创建特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 打开 Pull Request

更新日志

v1.2.0

  • 优化包结构,提供更好的模块化设计
  • 改进错误处理和异常信息
  • 添加更多的时区别名支持
  • 增强文档和示例

v1.1.0

  • 添加中文时区别名支持
  • 优化时间格式输出
  • 修复时区解析问题

v1.0.0

  • 初始版本发布
  • 基础时区查询功能
  • MCP 协议支持

支持

如有问题或建议,请:

  1. 查看 文档
  2. 搜索现有 Issues
  3. 创建新的 Issue 描述问题

关键词: MCP, Model Context Protocol, 时间服务, 时区, FastMCP, Python, 异步编程

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastmcp_time_service-1.2.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastmcp_time_service-1.2.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file fastmcp_time_service-1.2.0.tar.gz.

File metadata

  • Download URL: fastmcp_time_service-1.2.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for fastmcp_time_service-1.2.0.tar.gz
Algorithm Hash digest
SHA256 fd52d5795d46d4f30ed491375c1d806980348949904f8e55f2ee94f584385952
MD5 cb1a1944d04c45985f5eb58dfe67af6b
BLAKE2b-256 7e9dc6d15424013c16a1f7a8fef401dddf1ad02f364119dafad904fa3e4f31b8

See more details on using hashes here.

File details

Details for the file fastmcp_time_service-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastmcp_time_service-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 539988e38fb68eb20fb38b7215a1b3c330da7a2dc86ad69c2fd29a1fd085e175
MD5 4b4cb16c4abe53e68b43460644838a84
BLAKE2b-256 46538503d1137f1c914c2eec2f249eab7bf83247809fdf8fd3fe236259f04c94

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page