mcp-time-server-1124agent 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.
- mcp_time_server_1124agent-0.1.0/LICENSE +21 -0
- mcp_time_server_1124agent-0.1.0/PKG-INFO +129 -0
- mcp_time_server_1124agent-0.1.0/README.md +102 -0
- mcp_time_server_1124agent-0.1.0/pyproject.toml +59 -0
- mcp_time_server_1124agent-0.1.0/src/mcp_time_server/__init__.py +6 -0
- mcp_time_server_1124agent-0.1.0/src/mcp_time_server/__main__.py +6 -0
- mcp_time_server_1124agent-0.1.0/src/mcp_time_server/server.py +84 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mcp-time-server contributors
|
|
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,129 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mcp-time-server-1124agent
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A minimal MCP server exposing a timezone-aware current-time tool.
|
|
5
|
+
Author: mcp-time-server contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: iana,mcp,model-context-protocol,time,timezone
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Requires-Dist: mcp<3,>=2.3
|
|
20
|
+
Requires-Dist: pydantic>=2.0
|
|
21
|
+
Requires-Dist: tzdata>=2024.1
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
24
|
+
Requires-Dist: mcp[cli]<3,>=2.3; extra == 'dev'
|
|
25
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# mcp-time-server
|
|
29
|
+
|
|
30
|
+
一个基于 [MCP Python SDK](https://py.sdk.modelcontextprotocol.io/) v2 的最小 MCP Server,提供 `get_current_time` 工具。
|
|
31
|
+
|
|
32
|
+
- 可选 IANA 时区参数,例如 `Asia/Shanghai`
|
|
33
|
+
- 省略参数时使用服务器本地时区
|
|
34
|
+
- 返回 ISO 8601 时间字符串,并附带时区名
|
|
35
|
+
- 非法时区通过 `ToolError` 返回可读错误,便于模型自行纠正
|
|
36
|
+
- 协议版本:MCP `2025-11-25`
|
|
37
|
+
|
|
38
|
+
## 快速开始
|
|
39
|
+
|
|
40
|
+
使用 [uv](https://docs.astral.sh/uv/) 直接运行,无需手动安装:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"mcpServers": {
|
|
45
|
+
"time": {
|
|
46
|
+
"command": "uvx",
|
|
47
|
+
"args": ["mcp-time-server"]
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
或先安装再运行:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install mcp-time-server
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"mcpServers": {
|
|
62
|
+
"time": {
|
|
63
|
+
"command": "mcp-time-server"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
也可以作为模块启动:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
python -m mcp_time_server
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 工具
|
|
76
|
+
|
|
77
|
+
### `get_current_time`
|
|
78
|
+
|
|
79
|
+
获取当前时间。
|
|
80
|
+
|
|
81
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
82
|
+
|---|---|---|---|
|
|
83
|
+
| `timezone` | `string` | 否 | IANA 时区标识,如 `Asia/Shanghai`;省略时使用服务器本地时区 |
|
|
84
|
+
|
|
85
|
+
返回示例:
|
|
86
|
+
|
|
87
|
+
```text
|
|
88
|
+
2026-11-24T21:30:00+08:00 (Asia/Shanghai)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
不传 `timezone` 时,时区名取决于服务器本地设置,例如:
|
|
92
|
+
|
|
93
|
+
```text
|
|
94
|
+
2026-11-24T21:30:00+08:00 (CST)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
时区值会经过校验;传入 `Asia/Shanghia` 这类拼写错误时,工具返回:
|
|
98
|
+
|
|
99
|
+
```text
|
|
100
|
+
无法识别的 IANA 时区 'Asia/Shanghia'。请传入如 'Asia/Shanghai' 的有效时区名。
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## 本地开发
|
|
104
|
+
|
|
105
|
+
```powershell
|
|
106
|
+
python -m venv .venv
|
|
107
|
+
.venv\Scripts\Activate.ps1
|
|
108
|
+
pip install -e ".[dev]"
|
|
109
|
+
|
|
110
|
+
# 以 stdio 启动
|
|
111
|
+
python -m mcp_time_server
|
|
112
|
+
|
|
113
|
+
# 使用 MCP Inspector 调试
|
|
114
|
+
mcp dev src/mcp_time_server/server.py
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## 发布(维护者)
|
|
118
|
+
|
|
119
|
+
```powershell
|
|
120
|
+
uv build
|
|
121
|
+
uvx twine check dist/*
|
|
122
|
+
uvx twine upload dist/*
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
上传时使用 PyPI API Token(用户名固定为 `__token__`)。
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# mcp-time-server
|
|
2
|
+
|
|
3
|
+
一个基于 [MCP Python SDK](https://py.sdk.modelcontextprotocol.io/) v2 的最小 MCP Server,提供 `get_current_time` 工具。
|
|
4
|
+
|
|
5
|
+
- 可选 IANA 时区参数,例如 `Asia/Shanghai`
|
|
6
|
+
- 省略参数时使用服务器本地时区
|
|
7
|
+
- 返回 ISO 8601 时间字符串,并附带时区名
|
|
8
|
+
- 非法时区通过 `ToolError` 返回可读错误,便于模型自行纠正
|
|
9
|
+
- 协议版本:MCP `2025-11-25`
|
|
10
|
+
|
|
11
|
+
## 快速开始
|
|
12
|
+
|
|
13
|
+
使用 [uv](https://docs.astral.sh/uv/) 直接运行,无需手动安装:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"mcpServers": {
|
|
18
|
+
"time": {
|
|
19
|
+
"command": "uvx",
|
|
20
|
+
"args": ["mcp-time-server"]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
或先安装再运行:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install mcp-time-server
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"mcpServers": {
|
|
35
|
+
"time": {
|
|
36
|
+
"command": "mcp-time-server"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
也可以作为模块启动:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
python -m mcp_time_server
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 工具
|
|
49
|
+
|
|
50
|
+
### `get_current_time`
|
|
51
|
+
|
|
52
|
+
获取当前时间。
|
|
53
|
+
|
|
54
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
55
|
+
|---|---|---|---|
|
|
56
|
+
| `timezone` | `string` | 否 | IANA 时区标识,如 `Asia/Shanghai`;省略时使用服务器本地时区 |
|
|
57
|
+
|
|
58
|
+
返回示例:
|
|
59
|
+
|
|
60
|
+
```text
|
|
61
|
+
2026-11-24T21:30:00+08:00 (Asia/Shanghai)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
不传 `timezone` 时,时区名取决于服务器本地设置,例如:
|
|
65
|
+
|
|
66
|
+
```text
|
|
67
|
+
2026-11-24T21:30:00+08:00 (CST)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
时区值会经过校验;传入 `Asia/Shanghia` 这类拼写错误时,工具返回:
|
|
71
|
+
|
|
72
|
+
```text
|
|
73
|
+
无法识别的 IANA 时区 'Asia/Shanghia'。请传入如 'Asia/Shanghai' 的有效时区名。
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 本地开发
|
|
77
|
+
|
|
78
|
+
```powershell
|
|
79
|
+
python -m venv .venv
|
|
80
|
+
.venv\Scripts\Activate.ps1
|
|
81
|
+
pip install -e ".[dev]"
|
|
82
|
+
|
|
83
|
+
# 以 stdio 启动
|
|
84
|
+
python -m mcp_time_server
|
|
85
|
+
|
|
86
|
+
# 使用 MCP Inspector 调试
|
|
87
|
+
mcp dev src/mcp_time_server/server.py
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## 发布(维护者)
|
|
91
|
+
|
|
92
|
+
```powershell
|
|
93
|
+
uv build
|
|
94
|
+
uvx twine check dist/*
|
|
95
|
+
uvx twine upload dist/*
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
上传时使用 PyPI API Token(用户名固定为 `__token__`)。
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
MIT
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mcp-time-server-1124agent"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "A minimal MCP server exposing a timezone-aware current-time tool."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "mcp-time-server contributors" }]
|
|
14
|
+
keywords = ["mcp", "model-context-protocol", "time", "timezone", "iana"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Programming Language :: Python :: 3.14",
|
|
24
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"mcp>=2.3,<3",
|
|
28
|
+
"pydantic>=2.0",
|
|
29
|
+
"tzdata>=2024.1",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
dev = [
|
|
34
|
+
"mcp[cli]>=2.3,<3",
|
|
35
|
+
"build>=1.2",
|
|
36
|
+
"twine>=5.0",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.scripts]
|
|
40
|
+
mcp-time-server = "mcp_time_server.server:main"
|
|
41
|
+
|
|
42
|
+
# 发布前按需补充项目主页/仓库地址,例如:
|
|
43
|
+
# [project.urls]
|
|
44
|
+
# Homepage = "https://github.com/<your-name>/mcp-time-server"
|
|
45
|
+
# Issues = "https://github.com/<your-name>/mcp-time-server/issues"
|
|
46
|
+
|
|
47
|
+
[tool.hatch.version]
|
|
48
|
+
path = "src/mcp_time_server/__init__.py"
|
|
49
|
+
|
|
50
|
+
[tool.hatch.build.targets.wheel]
|
|
51
|
+
packages = ["src/mcp_time_server"]
|
|
52
|
+
|
|
53
|
+
[tool.hatch.build.targets.sdist]
|
|
54
|
+
include = [
|
|
55
|
+
"/src",
|
|
56
|
+
"/README.md",
|
|
57
|
+
"/LICENSE",
|
|
58
|
+
"/pyproject.toml",
|
|
59
|
+
]
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""MCP Server 实现:提供一个获取当前时间的工具。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
from typing import Annotated
|
|
7
|
+
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
|
8
|
+
|
|
9
|
+
from mcp.server import MCPServer
|
|
10
|
+
from mcp.server.mcpserver.exceptions import ToolError
|
|
11
|
+
from mcp.types import ToolAnnotations
|
|
12
|
+
from pydantic import Field
|
|
13
|
+
|
|
14
|
+
# 服务名会出现在 MCP 初始化握手的 serverInfo 中
|
|
15
|
+
mcp = MCPServer("time-server")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _local_zone_label(now: datetime) -> str:
|
|
19
|
+
"""返回服务器本地时区的可读名称,仅用于结果展示。"""
|
|
20
|
+
# ZoneInfo 对象带有 key(如 Asia/Shanghai);系统本地时区通常没有
|
|
21
|
+
key = getattr(now.tzinfo, "key", None)
|
|
22
|
+
if key:
|
|
23
|
+
return str(key)
|
|
24
|
+
return now.tzname() or "server-local"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@mcp.tool(
|
|
28
|
+
title="获取当前时间",
|
|
29
|
+
annotations=ToolAnnotations(read_only_hint=True, open_world_hint=False),
|
|
30
|
+
)
|
|
31
|
+
def get_current_time(
|
|
32
|
+
timezone: Annotated[
|
|
33
|
+
str | None,
|
|
34
|
+
Field(
|
|
35
|
+
description=(
|
|
36
|
+
"可选。IANA 时区标识,例如 Asia/Shanghai;"
|
|
37
|
+
"省略时返回服务器本地时间。"
|
|
38
|
+
)
|
|
39
|
+
),
|
|
40
|
+
] = None,
|
|
41
|
+
) -> str:
|
|
42
|
+
"""获取当前时间。
|
|
43
|
+
|
|
44
|
+
参数:
|
|
45
|
+
timezone: IANA 时区名(如 Asia/Shanghai)。不传则使用服务器本地时区。
|
|
46
|
+
|
|
47
|
+
返回:
|
|
48
|
+
ISO 8601 时间字符串,并附带时区名,例如:
|
|
49
|
+
2026-11-24T21:30:00+08:00 (Asia/Shanghai)
|
|
50
|
+
"""
|
|
51
|
+
if timezone is None:
|
|
52
|
+
# 未指定时区:使用服务器本地时区(带当前 UTC 偏移)
|
|
53
|
+
now = datetime.now().astimezone()
|
|
54
|
+
zone_label = _local_zone_label(now)
|
|
55
|
+
else:
|
|
56
|
+
zone_name = timezone.strip()
|
|
57
|
+
if not zone_name:
|
|
58
|
+
raise ToolError(
|
|
59
|
+
"timezone 不能为空字符串;省略该参数表示使用服务器本地时间。"
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
try:
|
|
63
|
+
zone = ZoneInfo(zone_name)
|
|
64
|
+
except (ZoneInfoNotFoundError, ValueError):
|
|
65
|
+
# 传给模型的错误信息要足够具体,便于它改用合法时区重试
|
|
66
|
+
raise ToolError(
|
|
67
|
+
f"无法识别的 IANA 时区 {zone_name!r}。"
|
|
68
|
+
"请传入如 'Asia/Shanghai' 的有效时区名。"
|
|
69
|
+
) from None
|
|
70
|
+
|
|
71
|
+
now = datetime.now(zone)
|
|
72
|
+
zone_label = zone_name
|
|
73
|
+
|
|
74
|
+
return f"{now.isoformat(timespec='seconds')} ({zone_label})"
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def main() -> None:
|
|
78
|
+
"""控制台入口:以 stdio 传输启动 MCP Server。"""
|
|
79
|
+
# 默认 stdio;HTTP 传输可改为 mcp.run(transport="streamable-http")
|
|
80
|
+
mcp.run()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
if __name__ == "__main__":
|
|
84
|
+
main()
|