Skip to main content

MCP-based NTP Time Service

Project description

MCP-NTP 时间服务

这是一个基于MCP(Model Context Protocol)的NTP时间服务,为大模型提供准确的网络时间获取功能。

功能特性

  • 从NTP服务器获取准确的网络时间
  • 支持stdio和sse两种传输模式
  • 提供get_current_time工具,方便大模型获取当前时间
  • 支持环境变量和请求头两种配置NTP服务器的方式
  • 返回详细的时间信息和NTP协议数据

安装

# 使用 uv 安装依赖
uv sync

配置

环境变量配置(stdio模式)

设置NTP_DOMAIN_URL环境变量:

export NTP_DOMAIN_URL="cn.ntp.org.cn"

请求头配置(sse模式)

在请求头中包含ntp_url字段:

ntp_url: cn.ntp.org.cn

使用方法

stdio模式

# 设置环境变量
export NTP_DOMAIN_URL="cn.ntp.org.cn"

# 启动服务
python -m app

sse模式

# 启动服务
python -m app --transport sse --port 18002

# 使用curl测试
curl -H "ntp_url: cn.ntp.org.cn" http://localhost:18002/sse

工具说明

get_current_time

获取当前NTP服务器时间。

参数:

  • ntp_server (可选): NTP服务器地址,如果不提供则使用环境变量或请求头中的配置

返回数据:

{
  "ntp_server": "cn.ntp.org.cn",
  "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="cn.ntp.org.cn"
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

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

mcp_ntp-0.2.1.tar.gz (58.3 kB view details)

Uploaded Source

Built Distribution

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

mcp_ntp-0.2.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file mcp_ntp-0.2.1.tar.gz.

File metadata

  • Download URL: mcp_ntp-0.2.1.tar.gz
  • Upload date:
  • Size: 58.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for mcp_ntp-0.2.1.tar.gz
Algorithm Hash digest
SHA256 fa3103c74f6ced840f2787615e77ffe43a6b46c5b3f2a4ab8832fd006bac6892
MD5 1d817057e7cfdab3fbe3dd178215cc84
BLAKE2b-256 91162c5ec524d625b497ee37ce7e6e98ba524f34c5a1024453bd6574a9f01cdf

See more details on using hashes here.

File details

Details for the file mcp_ntp-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: mcp_ntp-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for mcp_ntp-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1c83967d10a51e2eb5999939a3f571ab4d1d63807c85a9a6384eafc58c5a30a6
MD5 41ed4a9d16282b00c0f69aac95a9724d
BLAKE2b-256 7f06196a4b190857afa27729bdc5df18aebbb4fedd8cafccef7c55d731bf6ba4

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