最简单的MCP服务器
这是一个基于Python实现的最简单的MCP(Model Context Protocol)服务器,提供了基础的工具函数。
功能特性
该MCP服务器包含以下工具:
1. echo - 消息回显
- 功能: 回显输入的消息
- 参数:
message(字符串) - 要回显的消息 - 示例: 输入 "Hello World" 会返回 "回显: Hello World"
2. calculate - 数学计算
- 功能: 执行简单的数学表达式
- 参数:
expression(字符串) - 数学表达式 - 示例: 输入 "2 + 3 * 4" 会返回 "计算结果: 2 + 3 * 4 = 14"
3. get_time - 获取时间
- 功能: 获取当前系统时间
- 参数: 无
- 示例: 返回当前时间,如 "当前时间: 2024-01-15 14:30:25"
4. reverse_text - 文本反转
- 功能: 反转输入的文本内容
- 参数:
text(字符串) - 要反转的文本 - 示例: 输入 "Hello" 会返回 "反转结果: olleH"
安装和运行
环境要求
- Python 3.13+
- 已安装
mcp[cli]包
运行方式
方式1: 直接运行
python mcp_rs_publish/command.py
方式2: 作为模块运行
python -m mcp_rs_publish.command
方式3: 使用项目脚本
mcp_rs_publish
配置说明
在 config.json 文件中配置MCP服务器:
{
"mcpServers": {
"simple-mcp-server": {
"command": "python",
"args": ["-m", "mcp_rs_publish.command"],
"env": {
"PYTHONPATH": "."
}
}
}
}
技术架构
- 框架: 使用
mcpPython库 - 通信: 基于stdio的标准输入输出通信
- 异步: 使用
asyncio实现异步处理 - 日志: 内置日志系统,便于调试
扩展开发
要添加新的工具,只需在 SimpleMCPServer 类的 _setup_handlers 方法中:
- 在
handle_list_tools中添加工具定义 - 在
handle_call_tool中添加工具实现逻辑
注意事项
- 数学计算功能使用
eval()函数,请确保输入安全 - 服务器使用stdio通信,适合与支持MCP协议的客户端集成
- 所有工具调用都是异步的,支持并发处理
许可证
本项目采用MIT许可证。
Metadata
Release files for mcp-rs-publish 0.1.7
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 | |
|---|---|---|---|---|
| mcp_rs_publish-0.1.7.tar.gz | 2.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcp_rs_publish-0.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.2 kB
Release files / mcp_rs_publish-0.1.7.tar.gz
| Download URL | mcp_rs_publish-0.1.7.tar.gz |
|---|---|
| Size | 2.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6eb7acc00738f4852a8c23930e05e8f38a97902f69a6215e545e2ebdaf9b98a9
|
|
BLAKE2b-256 checksum How to use checksums |
bbbb6bb6005b207a6079d7d16f4fdce50c773b085422df46986d15403d8c58fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / mcp_rs_publish-0.1.7-py3-none-any.whl
| Download URL | mcp_rs_publish-0.1.7-py3-none-any.whl |
|---|---|
| Size | 3.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c099bfc1c07ee047a5fadecc03cbab970a47b67357d2f3042d33bcf31e81a55c
|
|
BLAKE2b-256 checksum How to use checksums |
54f8476e63e02332c2c1e5132b0b80d24e1e3c3f7dda7ef7a24ed71b53a37320
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for mcp-rs-publish 0.1.7
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.