fastmcp-time-service


Namefastmcp-time-service JSON
Version 1.2.0 PyPI version JSON
download
home_pageNone
Summary基于SSE传输的MCP时间服务器,提供多时区时间查询功能
upload_time2025-08-06 12:44:51
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords mcp time timezone fastmcp model-context-protocol
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FastMCP Time Service

[![PyPI version](https://badge.fury.io/py/fastmcp-time-service.svg)](https://badge.fury.io/py/fastmcp-time-service)
[![Python](https://img.shields.io/pypi/pyversions/fastmcp-time-service.svg)](https://pypi.org/project/fastmcp-time-service/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

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

## 功能特性

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

## 安装

使用 pip 安装:

```bash
pip install fastmcp-time-service
```

## 快速开始

### 作为 CLI 工具运行

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

```bash
fastmcp-time-service
```

### 作为 Python 模块使用

```python
from fastmcp_time_service import TimeServer

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

# 启动服务器
server.run()
```

### 自定义配置

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

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

或在代码中直接指定:

```python
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"`

**示例:**

```python
# 获取北京时间
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` 文件进行配置:

```env
MCP_TIME_HOST=127.0.0.1
MCP_TIME_PORT=8005
```

## 在 MCP 客户端中使用

### Claude Desktop 配置

在 `claude_desktop_config.json` 中添加:

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

### 自定义 MCP 客户端

```python
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. 克隆仓库:
```bash
git clone https://github.com/AlexLIAOwang/fastmcp-time-service.git
cd fastmcp-time-service
```

2. 安装开发依赖:
```bash
pip install -e ".[dev]"
```

3. 运行测试:
```bash
pytest
```

### 代码格式化

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

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

## 许可证

本项目采用 MIT 许可证 - 详见 [LICENSE](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. 查看 [文档](https://github.com/AlexLIAOwang/fastmcp-time-service/blob/main/README.md)
2. 搜索现有 [Issues](https://github.com/AlexLIAOwang/fastmcp-time-service/issues)
3. 创建新的 Issue 描述问题

---

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

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "fastmcp-time-service",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "mcp, time, timezone, fastmcp, model-context-protocol",
    "author": null,
    "author_email": "AlexLIAOwang <liaowang@example.com>",
    "download_url": "https://files.pythonhosted.org/packages/7e/9d/c6d15424013c16a1f7a8fef401dddf1ad02f364119dafad904fa3e4f31b8/fastmcp_time_service-1.2.0.tar.gz",
    "platform": null,
    "description": "# FastMCP Time Service\n\n[![PyPI version](https://badge.fury.io/py/fastmcp-time-service.svg)](https://badge.fury.io/py/fastmcp-time-service)\n[![Python](https://img.shields.io/pypi/pyversions/fastmcp-time-service.svg)](https://pypi.org/project/fastmcp-time-service/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n\u57fa\u4e8eSSE\u4f20\u8f93\u7684MCP\u65f6\u95f4\u670d\u52a1\u5668\uff0c\u63d0\u4f9b\u591a\u65f6\u533a\u65f6\u95f4\u67e5\u8be2\u529f\u80fd\u3002\u8fd9\u662f\u4e00\u4e2a\u57fa\u4e8e [Model Context Protocol (MCP)](https://modelcontextprotocol.io) \u548c FastMCP \u6846\u67b6\u6784\u5efa\u7684\u65f6\u95f4\u670d\u52a1\u3002\n\n## \u529f\u80fd\u7279\u6027\n\n- \ud83c\udf0d **\u591a\u65f6\u533a\u652f\u6301** - \u652f\u6301\u5168\u7403\u5404\u5730\u65f6\u533a\u7684\u65f6\u95f4\u67e5\u8be2\n- \ud83c\udde8\ud83c\uddf3 **\u4e2d\u6587\u53cb\u597d** - \u652f\u6301\u4e2d\u6587\u65f6\u533a\u540d\u79f0\u8f93\u5165\n- \u26a1 **\u9ad8\u6027\u80fd** - \u57fa\u4e8e FastMCP \u6846\u67b6\uff0c\u652f\u6301\u5f02\u6b65\u5904\u7406\n- \ud83d\udd27 **\u6613\u4e8e\u914d\u7f6e** - \u652f\u6301\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u670d\u52a1\u5668\u53c2\u6570\n- \ud83d\udce1 **\u6807\u51c6\u534f\u8bae** - \u5b8c\u5168\u517c\u5bb9 MCP \u534f\u8bae\u6807\u51c6\n\n## \u5b89\u88c5\n\n\u4f7f\u7528 pip \u5b89\u88c5\uff1a\n\n```bash\npip install fastmcp-time-service\n```\n\n## \u5feb\u901f\u5f00\u59cb\n\n### \u4f5c\u4e3a CLI \u5de5\u5177\u8fd0\u884c\n\n\u5b89\u88c5\u540e\uff0c\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u547d\u4ee4\u884c\u542f\u52a8\u670d\u52a1\uff1a\n\n```bash\nfastmcp-time-service\n```\n\n### \u4f5c\u4e3a Python \u6a21\u5757\u4f7f\u7528\n\n```python\nfrom fastmcp_time_service import TimeServer\n\n# \u521b\u5efa\u65f6\u95f4\u670d\u52a1\u5668\u5b9e\u4f8b\nserver = TimeServer()\n\n# \u542f\u52a8\u670d\u52a1\u5668\nserver.run()\n```\n\n### \u81ea\u5b9a\u4e49\u914d\u7f6e\n\n\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u670d\u52a1\u5668\uff1a\n\n```bash\nexport MCP_TIME_HOST=127.0.0.1\nexport MCP_TIME_PORT=8005\nfastmcp-time-service\n```\n\n\u6216\u5728\u4ee3\u7801\u4e2d\u76f4\u63a5\u6307\u5b9a\uff1a\n\n```python\nfrom fastmcp_time_service import TimeServer\n\n# \u81ea\u5b9a\u4e49\u4e3b\u673a\u548c\u7aef\u53e3\nserver = TimeServer(host=\"127.0.0.1\", port=8005)\nserver.run()\n```\n\n## MCP \u5de5\u5177\n\n### get_current_time\n\n\u83b7\u53d6\u6307\u5b9a\u65f6\u533a\u7684\u5f53\u524d\u65f6\u95f4\u3002\n\n**\u53c2\u6570:**\n- `timezone` (\u53ef\u9009): \u65f6\u533a\u540d\u79f0\uff0c\u9ed8\u8ba4\u4e3a \"Asia/Shanghai\"\n\n**\u652f\u6301\u7684\u65f6\u533a\u683c\u5f0f:**\n- \u6807\u51c6\u65f6\u533a\u540d\u79f0: `\"Asia/Shanghai\"`, `\"America/New_York\"`, `\"Europe/London\"`\n- \u4e2d\u6587\u522b\u540d: `\"\u4e2d\u56fd\"`, `\"\u5317\u4eac\"`, `\"\u4e0a\u6d77\"`\n- \u82f1\u6587\u522b\u540d: `\"China\"`, `\"Beijing\"`, `\"CST\"`\n\n**\u793a\u4f8b:**\n\n```python\n# \u83b7\u53d6\u5317\u4eac\u65f6\u95f4\nresult = await get_current_time(\"Asia/Shanghai\")\n# \u8f93\u51fa: \"Asia/Shanghai \u7684\u5f53\u524d\u65f6\u95f4\u662f: 2024\u5e7401\u670815\u65e5 14:30:25 CST\"\n\n# \u4f7f\u7528\u4e2d\u6587\u522b\u540d\nresult = await get_current_time(\"\u5317\u4eac\")\n# \u8f93\u51fa: \"\u5317\u4eac \u7684\u5f53\u524d\u65f6\u95f4\u662f: 2024\u5e7401\u670815\u65e5 14:30:25 CST\"\n\n# \u83b7\u53d6\u7ebd\u7ea6\u65f6\u95f4\nresult = await get_current_time(\"America/New_York\")\n# \u8f93\u51fa: \"America/New_York \u7684\u5f53\u524d\u65f6\u95f4\u662f: 2024\u5e7401\u670815\u65e5 01:30:25 EST\"\n```\n\n## \u914d\u7f6e\u8bf4\u660e\n\n### \u73af\u5883\u53d8\u91cf\n\n- `MCP_TIME_HOST`: \u670d\u52a1\u5668\u7ed1\u5b9a\u5730\u5740\uff0c\u9ed8\u8ba4 `0.0.0.0`\n- `MCP_TIME_PORT`: \u670d\u52a1\u5668\u7aef\u53e3\uff0c\u9ed8\u8ba4 `8005`\n\n### \u914d\u7f6e\u6587\u4ef6\n\n\u652f\u6301\u4f7f\u7528 `.env` \u6587\u4ef6\u8fdb\u884c\u914d\u7f6e\uff1a\n\n```env\nMCP_TIME_HOST=127.0.0.1\nMCP_TIME_PORT=8005\n```\n\n## \u5728 MCP \u5ba2\u6237\u7aef\u4e2d\u4f7f\u7528\n\n### Claude Desktop \u914d\u7f6e\n\n\u5728 `claude_desktop_config.json` \u4e2d\u6dfb\u52a0\uff1a\n\n```json\n{\n  \"mcpServers\": {\n    \"time-service\": {\n      \"command\": \"fastmcp-time-service\",\n      \"transport\": \"stdio\"\n    }\n  }\n}\n```\n\n### \u81ea\u5b9a\u4e49 MCP \u5ba2\u6237\u7aef\n\n```python\nimport asyncio\nfrom mcp.client.stdio import StdioServerParameters, stdio_client\n\nasync def main():\n    server_params = StdioServerParameters(\n        command=\"fastmcp-time-service\",\n        args=[]\n    )\n    \n    async with stdio_client(server_params) as (read, write):\n        # \u4f7f\u7528 MCP \u5ba2\u6237\u7aef\u8c03\u7528\u65f6\u95f4\u5de5\u5177\n        pass\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n## \u5f00\u53d1\n\n### \u672c\u5730\u5f00\u53d1\n\n1. \u514b\u9686\u4ed3\u5e93\uff1a\n```bash\ngit clone https://github.com/AlexLIAOwang/fastmcp-time-service.git\ncd fastmcp-time-service\n```\n\n2. \u5b89\u88c5\u5f00\u53d1\u4f9d\u8d56\uff1a\n```bash\npip install -e \".[dev]\"\n```\n\n3. \u8fd0\u884c\u6d4b\u8bd5\uff1a\n```bash\npytest\n```\n\n### \u4ee3\u7801\u683c\u5f0f\u5316\n\n```bash\n# \u4f7f\u7528 black \u683c\u5f0f\u5316\u4ee3\u7801\nblack fastmcp_time_service/\n\n# \u4f7f\u7528 ruff \u8fdb\u884c\u4ee3\u7801\u68c0\u67e5\nruff check fastmcp_time_service/\n```\n\n## \u8bb8\u53ef\u8bc1\n\n\u672c\u9879\u76ee\u91c7\u7528 MIT \u8bb8\u53ef\u8bc1 - \u8be6\u89c1 [LICENSE](LICENSE) \u6587\u4ef6\u3002\n\n## \u8d21\u732e\n\n\u6b22\u8fce\u8d21\u732e\u4ee3\u7801\uff01\u8bf7\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a\n\n1. Fork \u672c\u4ed3\u5e93\n2. \u521b\u5efa\u7279\u6027\u5206\u652f (`git checkout -b feature/AmazingFeature`)\n3. \u63d0\u4ea4\u66f4\u6539 (`git commit -m 'Add some AmazingFeature'`)\n4. \u63a8\u9001\u5230\u5206\u652f (`git push origin feature/AmazingFeature`)\n5. \u6253\u5f00 Pull Request\n\n## \u66f4\u65b0\u65e5\u5fd7\n\n### v1.2.0\n- \u4f18\u5316\u5305\u7ed3\u6784\uff0c\u63d0\u4f9b\u66f4\u597d\u7684\u6a21\u5757\u5316\u8bbe\u8ba1\n- \u6539\u8fdb\u9519\u8bef\u5904\u7406\u548c\u5f02\u5e38\u4fe1\u606f\n- \u6dfb\u52a0\u66f4\u591a\u7684\u65f6\u533a\u522b\u540d\u652f\u6301\n- \u589e\u5f3a\u6587\u6863\u548c\u793a\u4f8b\n\n### v1.1.0\n- \u6dfb\u52a0\u4e2d\u6587\u65f6\u533a\u522b\u540d\u652f\u6301\n- \u4f18\u5316\u65f6\u95f4\u683c\u5f0f\u8f93\u51fa\n- \u4fee\u590d\u65f6\u533a\u89e3\u6790\u95ee\u9898\n\n### v1.0.0\n- \u521d\u59cb\u7248\u672c\u53d1\u5e03\n- \u57fa\u7840\u65f6\u533a\u67e5\u8be2\u529f\u80fd\n- MCP \u534f\u8bae\u652f\u6301\n\n## \u652f\u6301\n\n\u5982\u6709\u95ee\u9898\u6216\u5efa\u8bae\uff0c\u8bf7\uff1a\n\n1. \u67e5\u770b [\u6587\u6863](https://github.com/AlexLIAOwang/fastmcp-time-service/blob/main/README.md)\n2. \u641c\u7d22\u73b0\u6709 [Issues](https://github.com/AlexLIAOwang/fastmcp-time-service/issues)\n3. \u521b\u5efa\u65b0\u7684 Issue \u63cf\u8ff0\u95ee\u9898\n\n---\n\n**\u5173\u952e\u8bcd:** MCP, Model Context Protocol, \u65f6\u95f4\u670d\u52a1, \u65f6\u533a, FastMCP, Python, \u5f02\u6b65\u7f16\u7a0b\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "\u57fa\u4e8eSSE\u4f20\u8f93\u7684MCP\u65f6\u95f4\u670d\u52a1\u5668\uff0c\u63d0\u4f9b\u591a\u65f6\u533a\u65f6\u95f4\u67e5\u8be2\u529f\u80fd",
    "version": "1.2.0",
    "project_urls": {
        "Documentation": "https://github.com/AlexLIAOwang/fastmcp-time-service/blob/main/README.md",
        "Homepage": "https://github.com/AlexLIAOwang/fastmcp-time-service",
        "Issues": "https://github.com/AlexLIAOwang/fastmcp-time-service/issues",
        "Repository": "https://github.com/AlexLIAOwang/fastmcp-time-service"
    },
    "split_keywords": [
        "mcp",
        " time",
        " timezone",
        " fastmcp",
        " model-context-protocol"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "46538503d1137f1c914c2eec2f249eab7bf83247809fdf8fd3fe236259f04c94",
                "md5": "4b4cb16c4abe53e68b43460644838a84",
                "sha256": "539988e38fb68eb20fb38b7215a1b3c330da7a2dc86ad69c2fd29a1fd085e175"
            },
            "downloads": -1,
            "filename": "fastmcp_time_service-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4b4cb16c4abe53e68b43460644838a84",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 7039,
            "upload_time": "2025-08-06T12:44:49",
            "upload_time_iso_8601": "2025-08-06T12:44:49.885955Z",
            "url": "https://files.pythonhosted.org/packages/46/53/8503d1137f1c914c2eec2f249eab7bf83247809fdf8fd3fe236259f04c94/fastmcp_time_service-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "7e9dc6d15424013c16a1f7a8fef401dddf1ad02f364119dafad904fa3e4f31b8",
                "md5": "cb1a1944d04c45985f5eb58dfe67af6b",
                "sha256": "fd52d5795d46d4f30ed491375c1d806980348949904f8e55f2ee94f584385952"
            },
            "downloads": -1,
            "filename": "fastmcp_time_service-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "cb1a1944d04c45985f5eb58dfe67af6b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 6453,
            "upload_time": "2025-08-06T12:44:51",
            "upload_time_iso_8601": "2025-08-06T12:44:51.278774Z",
            "url": "https://files.pythonhosted.org/packages/7e/9d/c6d15424013c16a1f7a8fef401dddf1ad02f364119dafad904fa3e4f31b8/fastmcp_time_service-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-06 12:44:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AlexLIAOwang",
    "github_project": "fastmcp-time-service",
    "github_not_found": true,
    "lcname": "fastmcp-time-service"
}
        
Elapsed time: 2.16068s