mcp-time-server-hsy 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hsy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcp-time-server-hsy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: An MCP Server that provides a tool to get the current time with an optional IANA timezone.
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Author: hsy
|
|
8
|
+
Author-email: hsy@example.com
|
|
9
|
+
Requires-Python: >=3.10,<4.0
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
19
|
+
Requires-Dist: mcp (>=2.0.0)
|
|
20
|
+
Requires-Dist: tzdata ; sys_platform == "win32"
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# mcp-time-server-hsy
|
|
24
|
+
|
|
25
|
+
一个最小可用的 [MCP](https://modelcontextprotocol.io) Server,提供 `get_current_time` 工具,
|
|
26
|
+
支持可选的 IANA 时区参数。
|
|
27
|
+
|
|
28
|
+
## 安装
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install mcp-time-server-hsy
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 使用
|
|
35
|
+
|
|
36
|
+
默认以 streamable-http 传输启动(监听 http://127.0.0.1:8000/mcp):
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
mcp-time-server-hsy
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
以 stdio 传输启动(供 Trae / Claude Desktop 等客户端以子进程方式拉起):
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Linux / macOS
|
|
46
|
+
MCP_TRANSPORT=stdio mcp-time-server-hsy
|
|
47
|
+
|
|
48
|
+
# Windows PowerShell
|
|
49
|
+
$env:MCP_TRANSPORT="stdio"; mcp-time-server-hsy
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 工具
|
|
53
|
+
|
|
54
|
+
### `get_current_time(timezone: str | None = None) -> str`
|
|
55
|
+
|
|
56
|
+
返回当前时间,格式为 `YYYY-MM-DD HH:MM:SS.SSSSSS 时区名称`。
|
|
57
|
+
|
|
58
|
+
- `timezone` 省略时返回服务器本地时间
|
|
59
|
+
- 传入非法时区名时返回 `isError: true` 及可读的错误信息
|
|
60
|
+
|
|
61
|
+
示例返回:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
2026-11-30 21:48:07.123456 CST
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 客户端配置示例
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"mcpServers": {
|
|
72
|
+
"time-server": {
|
|
73
|
+
"command": "mcp-time-server-hsy",
|
|
74
|
+
"env": { "MCP_TRANSPORT": "stdio" }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
MIT
|
|
83
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# mcp-time-server-hsy
|
|
2
|
+
|
|
3
|
+
一个最小可用的 [MCP](https://modelcontextprotocol.io) Server,提供 `get_current_time` 工具,
|
|
4
|
+
支持可选的 IANA 时区参数。
|
|
5
|
+
|
|
6
|
+
## 安装
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install mcp-time-server-hsy
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 使用
|
|
13
|
+
|
|
14
|
+
默认以 streamable-http 传输启动(监听 http://127.0.0.1:8000/mcp):
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
mcp-time-server-hsy
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
以 stdio 传输启动(供 Trae / Claude Desktop 等客户端以子进程方式拉起):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# Linux / macOS
|
|
24
|
+
MCP_TRANSPORT=stdio mcp-time-server-hsy
|
|
25
|
+
|
|
26
|
+
# Windows PowerShell
|
|
27
|
+
$env:MCP_TRANSPORT="stdio"; mcp-time-server-hsy
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 工具
|
|
31
|
+
|
|
32
|
+
### `get_current_time(timezone: str | None = None) -> str`
|
|
33
|
+
|
|
34
|
+
返回当前时间,格式为 `YYYY-MM-DD HH:MM:SS.SSSSSS 时区名称`。
|
|
35
|
+
|
|
36
|
+
- `timezone` 省略时返回服务器本地时间
|
|
37
|
+
- 传入非法时区名时返回 `isError: true` 及可读的错误信息
|
|
38
|
+
|
|
39
|
+
示例返回:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
2026-11-30 21:48:07.123456 CST
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 客户端配置示例
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"mcpServers": {
|
|
50
|
+
"time-server": {
|
|
51
|
+
"command": "mcp-time-server-hsy",
|
|
52
|
+
"env": { "MCP_TRANSPORT": "stdio" }
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
MIT
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""MCP Time Server 主模块。
|
|
2
|
+
|
|
3
|
+
暴露一个工具 get_current_time,支持可选的 IANA 时区参数。
|
|
4
|
+
默认以 streamable-http 传输启动;设置环境变量 MCP_TRANSPORT=stdio 时以 stdio 启动。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
from datetime import datetime
|
|
11
|
+
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
|
12
|
+
|
|
13
|
+
from mcp.server.mcpserver import MCPServer
|
|
14
|
+
from mcp.server.mcpserver.exceptions import ToolError
|
|
15
|
+
|
|
16
|
+
mcp = MCPServer("time-server")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@mcp.tool()
|
|
20
|
+
def get_current_time(timezone: str | None = None) -> str:
|
|
21
|
+
"""获取当前时间。
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
timezone: 可选,IANA 时区名,例如 "Asia/Shanghai"、"America/New_York"。
|
|
25
|
+
注意:北京时间在 IANA 数据库中的名称就是 "Asia/Shanghai"
|
|
26
|
+
(没有 "Asia/Beijing" 这个时区),要取北京时间请传 "Asia/Shanghai"。
|
|
27
|
+
不传(或传空字符串)时,返回服务器本地时间。
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
格式化字符串,格式为 YYYY-MM-DD HH:MM:SS.SSSSSS 时区名称,例如
|
|
31
|
+
"2026-11-30 21:48:07.123456 CST"。
|
|
32
|
+
|
|
33
|
+
Raises:
|
|
34
|
+
ToolError: 传入的时区名不是合法的 IANA 时区。
|
|
35
|
+
"""
|
|
36
|
+
tz_name = (timezone or "").strip()
|
|
37
|
+
|
|
38
|
+
if not tz_name:
|
|
39
|
+
now = datetime.now().astimezone()
|
|
40
|
+
return now.strftime("%Y-%m-%d %H:%M:%S.%f %Z")
|
|
41
|
+
|
|
42
|
+
try:
|
|
43
|
+
tz = ZoneInfo(tz_name)
|
|
44
|
+
except (ZoneInfoNotFoundError, ValueError) as exc:
|
|
45
|
+
raise ToolError(
|
|
46
|
+
f"未知的时区 {tz_name!r},请传入合法的 IANA 时区名,例如 'Asia/Shanghai'"
|
|
47
|
+
f"(北京时间就用该名称,IANA 中没有 'Asia/Beijing')。"
|
|
48
|
+
) from exc
|
|
49
|
+
|
|
50
|
+
now = datetime.now(tz)
|
|
51
|
+
return now.strftime("%Y-%m-%d %H:%M:%S.%f %Z")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def main() -> None:
|
|
55
|
+
"""启动 MCP 服务器。
|
|
56
|
+
|
|
57
|
+
默认 streamable-http(URL 方式连接);MCP_TRANSPORT=stdio 时用 stdio。
|
|
58
|
+
"""
|
|
59
|
+
transport = os.environ.get("MCP_TRANSPORT", "streamable-http").strip().lower()
|
|
60
|
+
mcp.run(transport=transport)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if __name__ == "__main__":
|
|
64
|
+
main()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "mcp-time-server-hsy"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "An MCP Server that provides a tool to get the current time with an optional IANA timezone."
|
|
5
|
+
authors = ["hsy <hsy@example.com>"]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
classifiers = [
|
|
9
|
+
"Programming Language :: Python :: 3",
|
|
10
|
+
"Programming Language :: Python :: 3.10",
|
|
11
|
+
"Programming Language :: Python :: 3.11",
|
|
12
|
+
"Programming Language :: Python :: 3.12",
|
|
13
|
+
"License :: OSI Approved :: MIT License",
|
|
14
|
+
"Operating System :: OS Independent",
|
|
15
|
+
]
|
|
16
|
+
packages = [{ include = "mcp_time_server" }]
|
|
17
|
+
|
|
18
|
+
[tool.poetry.dependencies]
|
|
19
|
+
python = "^3.10"
|
|
20
|
+
mcp = ">=2.0.0"
|
|
21
|
+
# Windows 默认没有 IANA 时区数据库,zoneinfo 需要 tzdata 才能识别 Asia/Shanghai 等时区
|
|
22
|
+
tzdata = { version = "*", markers = "sys_platform == 'win32'" }
|
|
23
|
+
|
|
24
|
+
[tool.poetry.scripts]
|
|
25
|
+
mcp-time-server-hsy = "mcp_time_server.main:main"
|
|
26
|
+
|
|
27
|
+
[build-system]
|
|
28
|
+
requires = ["poetry-core>=1.0.0"]
|
|
29
|
+
build-backend = "poetry.core.masonry.api"
|