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
连接失败
- 确保服务器已启动
- 检查端口是否正确
- 防火墙是否允许相应端口
- 查看服务器控制台输出的错误信息
Metadata
Release files for src_mcp 0.1.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 | |
|---|---|---|---|---|
| src_mcp-0.1.0.tar.gz | 4.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| src_mcp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.4 kB
Release files / src_mcp-0.1.0.tar.gz
| Download URL | src_mcp-0.1.0.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
47130e5237dffeb2ce8c779e05c6176c994defbcb7448c30303f38fdb1a46784
|
|
BLAKE2b-256 checksum How to use checksums |
efb2d7dfb991a3eee5272b8dce29f238a17a81804c4b95e41996fe93d239c5bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.14.0 Windows/11
|
Release files / src_mcp-0.1.0-py3-none-any.whl
| Download URL | src_mcp-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3e23c165c08d64172ac1f11afb4a1ff1b53d3e3f0e7cf0f49ad3fb9c2c9f5fd3
|
|
BLAKE2b-256 checksum How to use checksums |
4aca062eda4fcf397995d511e6b00d9dbc7a5884230844de5874d5a07be5918f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.14.0 Windows/11
|
Security for src_mcp 0.1.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.