MCP-NTP 时间服务
这是一个基于MCP(Model Context Protocol)的NTP时间服务,为大模型提供准确的网络时间获取功能。
功能特性
- 从NTP服务器获取准确的网络时间
- 支持stdio和sse两种传输模式
- 提供
get_current_time工具,方便大模型获取当前时间 - 支持环境变量和请求头两种配置NTP服务器的方式
- 返回详细的时间信息和NTP协议数据
安装
需要 Python 3.10 至 3.14;服务固定使用 MCP Python SDK 2.2.0。
# 使用 uv 安装依赖
uv sync
配置
环境变量配置(stdio模式)
设置NTP_DOMAIN_URL环境变量:
export NTP_DOMAIN_URL="ntp.aliyun.com"
请求头配置(sse模式)
在请求头中包含ntp_url字段:
ntp_url: ntp.aliyun.com
使用方法
stdio模式
# 设置环境变量
export NTP_DOMAIN_URL="ntp.aliyun.com"
# 启动服务
python -m app
sse模式
# 启动服务
python -m app --transport sse --port 8080
# 使用curl测试
curl -H "ntp_url: ntp.aliyun.com" http://localhost:8080/sse
工具说明
get_current_time
获取当前NTP服务器时间。
参数:
ntp_server(可选): NTP服务器地址,如果不提供则使用环境变量或请求头中的配置
返回数据:
{
"ntp_server": "ntp.aliyun.com",
"ntp_timestamp": 1703123456.789,
"ntp_time": "2023-12-21T10:30:56.789",
"local_system_time": "2023-12-21T10:30:56.789",
"time_offset": 0.123,
"response_delay": 0.045
}
调试
可以使用提供的测试NTP服务器进行调试:
export NTP_DOMAIN_URL="ntp.aliyun.com"
python -m app -v
开发
项目结构
mcp-ntp/
├── app/
│ ├── __init__.py # 主入口
│ ├── server.py # MCP服务器实现
│ ├── client.py # NTP客户端
│ └── config.py # 配置管理
├── pyproject.toml # 项目配置
└── README.md # 说明文档
添加新的NTP服务器
在client.py中的get_current_time函数可以轻松扩展支持更多NTP服务器配置。
许可证
MIT License
Metadata
Release files for mcp-ntp 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mcp_ntp-0.3.0.tar.gz | 72.5 kB | Without provenance | Details for mcp_ntp-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mcp_ntp-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for mcp_ntp-0.3.0-py3-none-any.whl |
Total release size: 81.5 kB
Release files / mcp_ntp-0.3.0.tar.gz
| Download URL | mcp_ntp-0.3.0.tar.gz |
|---|---|
| Size | 72.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
618c71e051da9efcd5914f0d96e31eecf0f56d4bd297aa2cc91985bfa166579a
|
|
BLAKE2b-256 checksum How to use checksums |
73f1269a034e0ce83439b372ba001f774c7e21693360e0455b1c97f90ad172f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.20
|
Release files / mcp_ntp-0.3.0-py3-none-any.whl
| Download URL | mcp_ntp-0.3.0-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e7e52765c749626edaebcedf20511a026244e42f8701a5e1b553c3ce45f058c8
|
|
BLAKE2b-256 checksum How to use checksums |
0debf6c7e02939766e042d49ff17c33897d37f28c409c302bb9372d5dd55471e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.20
|
Security for mcp-ntp 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.