A Model Context Protocol (MCP) time server with timezone support
Project description
My MCP Server
这是一个自定义的 MCP (Model Context Protocol) 服务器,支持三种传输方式,可以与 Cherry Studio 等 AI 客户端配合使用。
三种传输方式
| 模式 | 传输方式 | 适用场景 | 端口 |
|---|---|---|---|
| STUDIO | stdio | 桌面应用本地配置(如 Cherry Studio) | 无 |
| SSE | Server-Sent Events | 需要实时推送的场景 | 8080 |
| StreamableHttp | HTTP RESTful API | Web 应用和 HTTP 交互 | 3000 |
功能
所有模式都提供以下工具:
hello_world- 返回问候消息echo- 回显消息(用于测试)get_time- 获取当前时间calculate- 执行数学计算store_data- 存储数据retrieve_data- 检索数据
安装
- 创建虚拟环境:
python -m venv venv
venv\Scripts\activate
- 安装依赖:
pip install -e .
- 安装额外的 HTTP 服务器依赖(用于 SSE 和 HTTP 模式):
pip install uvicorn starlette
运行
方式一:使用启动菜单(推荐)
start.bat
根据提示选择要启动的模式。
方式二:直接运行特定模式
STUDIO 模式(stdio):
python server_studio.py
SSE 模式:
python server_sse.py
StreamableHttp 模式:
python server_streamable.py
在 Cherry Studio 中配置
STUDIO 模式(stdio)
- 打开 Cherry Studio
- 进入「设置」→「MCP 服务器」
- 点击「添加服务器」
- 选择「命令」方式
- 配置以下信息:
- 命令:
python - 参数:
C:\Users\ASUS\Documents\trae_projects\4\my-mcp-server\server_studio.py - 环境变量:(可选)
- 命令:
- 点击「保存」
SSE 模式
- 先启动服务器:
python server_sse.py - 打开 Cherry Studio
- 进入「设置」→「MCP 服务器」
- 点击「添加服务器」
- 选择「URL」方式
- 配置以下信息:
- URL:
http://localhost:8080/sse
- URL:
- 点击「保存」
StreamableHttp 模式
- 先启动服务器:
python server_streamable.py - 打开 Cherry Studio
- 进入「设置」→「MCP 服务器」
- 点击「添加服务器」
- 选择「URL」方式
- 配置以下信息:
- URL:
http://localhost:3000/mcp
- URL:
- 点击「保存」
测试连接
启动服务器后,可以使用以下方法测试:
- STUDIO 模式:在 Cherry Studio 中添加服务器后,查看工具列表是否包含上述工具
- SSE 模式:访问 http://localhost:8080/messages 查看服务器状态
- StreamableHttp 模式:访问 http://localhost:3000/health 查看服务器状态
添加自定义工具
编辑对应的服务器文件,在 main() 函数之前使用 @app.tool() 装饰器添加自定义工具:
@app.tool()
def your_tool_name(param1: str, param2: int) -> str:
"""工具描述"""
# 工具实现
return "结果"
文件结构
my-mcp-server/
├── server_studio.py # STUDIO 模式 (stdio)
├── server_sse.py # SSE 模式
├── server_streamable.py # StreamableHttp 模式
├── start.bat # 启动菜单
├── pyproject.toml # 项目配置
└── README.md # 说明文档
故障排除
端口被占用
如果启动时提示端口被占用,可以修改对应文件中的端口号:
- SSE 模式:修改
server_sse.py中的port=8080 - StreamableHttp 模式:修改
server_streamable.py中的port=3000
连接失败
- 确保服务器已启动
- 检查端口是否正确
- 防火墙是否允许相应端口
- 查看服务器控制台输出的错误信息
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
src_mcp-0.1.0.tar.gz
(4.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file src_mcp-0.1.0.tar.gz.
File metadata
- Download URL: src_mcp-0.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.14.0 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47130e5237dffeb2ce8c779e05c6176c994defbcb7448c30303f38fdb1a46784
|
|
| MD5 |
f2dd4fd8c301d4b77da430bea5e1fd94
|
|
| BLAKE2b-256 |
efb2d7dfb991a3eee5272b8dce29f238a17a81804c4b95e41996fe93d239c5bb
|
File details
Details for the file src_mcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: src_mcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.14.0 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e23c165c08d64172ac1f11afb4a1ff1b53d3e3f0e7cf0f49ad3fb9c2c9f5fd3
|
|
| MD5 |
419c91938fb21533fcea4246e0525c4a
|
|
| BLAKE2b-256 |
4aca062eda4fcf397995d511e6b00d9dbc7a5884230844de5874d5a07be5918f
|