About MCP 时间服务器示例 (MCP Time Server Demo)
A TypeScript MCP server demo for clients that need current-time lookups. It accepts an optional time zone and falls back to the server's local time when none is supplied or the zone is invalid.
Key features
- 01Get the current time
- 02Accept an optional IANA time zone
- 03Fall back to local time for invalid zones
- 04Communicate over standard input and output
Use cases
- 01Query the current time from an MCP client
- 02Retrieve time for a specified time zone
- 03Test the time tool with MCP Inspector
MCP support
The MCP server exposes current-time lookup through the `getCurrentTime` tool and communicates over standard input and output. It can integrate with MCP-compatible clients.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEMCP 时间服务器示例 (MCP Time Server Demo)
这是一个简单的基于模型上下文协议 (MCP) 的服务器示例,使用 TypeScript 和 @modelcontextprotocol/sdk 构建。
它提供了一个工具,用于获取当前时间,并可以选择性地指定时区。
初始构建提示 (Initial Build Prompt)
需求
基于提供的 MCP 相关资料,帮我构建一个 MCP Server,需求如下:
- 提供一个获取当前时间的工具
- 接收时区作为参数(可选)
- 编写清晰的注释和说明
- 要求功能简洁、只包含关键功能
- 使用 TypeScript 编写
请参考下面四个资料:
[参考资料 1] MCP 基础介绍
[参考资料 2] MCP 核心架构
[参考资料 3] MCP Server 开发指引
[参考资料 4] MCP Typescript SDK 文档
功能特点
getCurrentTime工具: 获取当前时间。- 支持可选的
timezone参数 (IANA 时区标识符,例如America/New_York,Asia/Shanghai)。 - 如果未提供时区或时区无效,则返回服务器本地时间。
- 支持可选的
- MCP 兼容: 可以与任何支持 MCP 的客户端(如 Claude Desktop 或 MCP Inspector)集成。
- 基于 Stdio: 使用标准输入/输出进行通信,易于集成。
先决条件
安装
- 克隆或下载此仓库。
- 在项目根目录打开终端,运行以下命令安装依赖项:
npm install
使用
1. 编译项目
由于项目使用 TypeScript 编写,需要先将其编译为 JavaScript:
npm run build
2. 运行服务器
npm start
使用 MCP Inspector 测试 (Testing with MCP Inspector)
- 下载并安装 MCP Inspector。
- 启动 MCP Inspector。
- 在 MCP Inspector 中创建一个新的 MCP 会话。
- 在 MCP Inspector 中,选择
Tools->Import Tool,然后选择tools/getCurrentTime.ts。 - 点击
Import按钮,然后在Tools列表中找到getCurrentTime工具。 - 点击
getCurrentTime工具,然后点击Run按钮。 - 查看输出结果。
贡献
欢迎贡献!请在 issues 或 pull requests 中提出问题或建议。
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.