MCP回声演示
用于演示协议的最小 MCP 实现。
没有外部依赖。没有LLM。只有Python和JSON。
这是达斯吗?
提供三个工具的演示服务器:
hello_world返回一个问候echo返回传递的文本calculate执行计算(a, b, operator)
两个客户:
- CLI客户端 (
cli_run.py– 命令行演示 - GUI客户端 (
gui_run.py)–Tkinter迷你检查器
结构
mcp_echo_demo/
├── code/
│ ├── server.py # MCP Server (stdio)
│ ├── client.py # MCP Client-Klasse (Bibliothek)
│ ├── client_tk.py # Mini-Inspector GUI (Bibliothek)
│ ├── cli_run.py # CLI Demo starten
│ └── gui_run.py # GUI Demo starten
├── config/ # (leer, für Erweiterungen)
└── tests/ # (leer, für Tests)运行
CLI版本:
cd code
python3 cli_run.pyGUI版本(迷你检查器):
cd code
python3 gui_run.py迷你检查器功能
GUI 客户端是一个简化的 MCP 检查器:
- 懒惰连接 – 只需按下按钮即可连接
- 服务器路径可选 启动任何MCP服务器
- 基于 Discovery – 工具动态显示为按钮
- 模式感知 – 基于工具方案的输入对话框
- 连接/分离 服务器生命周期管理
工作流程
- 输入服务器路径(默认:
server.py) - 点击“连接”
- 工具按钮在发现后出现
- 单击工具 → 参数对话框(如有必要)
- 结果显示在输出区域
CLI 版本
Starte Server: .../server.py
--------------------------------------------------
=== Initialize ===
Verbunden mit: echo-server v1.0.0
=== Discovery ===
Verfügbare Tools: 3
- hello_world: Gibt eine freundliche Begrüßung zurück
- echo: Gibt den übergebenen Text zurück
- calculate: Führt eine Berechnung durch
=== Tool Call: echo ===
→ {"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "echo", "arguments": {"text": "MCP ist nur JSON über Pipes!"}}}
← MCP ist nur JSON über Pipes!
=== Tool Call: hello_world ===
→ {"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "hello_world", "arguments": {}}}
← Hallo Welt! Grüße vom MCP Echo Server.
=== Tool Call: calculate ===
→ {"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "calculate", "arguments": {"a": 42, "b": 13, "operator": "*"}}}
← 546.0
--------------------------------------------------
Server beendet.条件
- Python 3.8+
- Tkinter(用于 GUI,包含在 Python stdlib 中)
- 没有外部包
这说明了什么?
- MCP 只是 JSON-RPC –请求控制,响应raus
- 交通可互换 – 在这里 stdio, 也可以是 HTTP 或共享内存
- 不需要LLM 客户端是一个Python脚本
- 客户agnostic – CLI或GUI,服务器不会注意到任何区别
- 叉+管道=Unix基础 没有魔法
- 每个人都可以建造一个检查员 ~200行 Python
测试自己的服务器
Mini Inspector 可以启动任何基于 stdio 的 MCP 服务器:
python3 gui_run.py
# → Pfad zu anderem server.py eingeben
# → Verbinden
# → Tools erscheinen dynamisch继续
许可证
麻省理工学院
