MCP服务器流HTTP-卷曲测试
使用HTTP流传输的模型上下文协议(MCP)服务器的测试客户端。该项目专门用于测试curl与MCP流式HTTP服务器的交互。
概述
该项目提供了一个bash脚本来测试使用HTTP流作为传输层的MCP服务器实现。它演示了使用curl的完整MCP协议握手和工具调用流程。
仓库
此测试设置适用于以下MCP Rust SDK示例: https://github.com/modelcontextprotocol/rust-sdk
构建示例
要构建可流式传输的HTTP计数器服务器示例:
cargo build --example servers_counter_streamhttp --package mcp-server-examples要构建可流式传输的HTTP客户端示例:
cargo build --example clients_streamable_http --package mcp-client-examples特性
- MCP协议支持:实施MCP 2025-03-26协议版本
- 会话管理:使用处理基于会话的通信
Mcp-Session-Id标头 - HTTP流:用途
text/event-stream用于实时通信 - JSON-RPC 2.0:遵循JSON-RPC 2.0规范进行消息格式化
先决条件
bashcurlyq(用于JSON处理)- 运行在上的MCP服务器
http://127.0.0.1:8000/mcp
用法
运行测试脚本:
./test.sh测试脚本的作用
该脚本执行以下MCP协议操作:
1.初始化连接
发送 initialize 请求与MCP服务器建立连接:
- 将协议版本设置为
2025-03-26 - 将客户标识为
curl-test v1.0.0 - 从响应标头中捕获会话ID
2.发送初始化通知
使用通知服务器初始化已完成 notifications/initialized 方法。
3.列出可用工具
使用从服务器请求可用工具列表 tools/list:
- 将响应保存到
tools.json - 用途
yq格式化输出
4.调用工具
调用 get_value 工具作为工具执行的演示。
输出文件
- headers.txt:包含初始化请求中的HTTP响应标头
- tools.json:包含服务器上可用工具的格式化列表
MCP协议流
sequenceDiagram
participant Client
participant Server
Client->>+Server: initialize
Server-->>-Client: session-id
Client->>Server: notifications/initialized
Client->>+Server: tools/list
Server-->>-Client: tools list
Client->>+Server: tools/call
Server-->>-Client: tool result样品运行
./test.sh
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2024-11-05",
"capabilities": {
"prompts": {},
"resources": {},
"tools": {}
},
"serverInfo": {
"name": "rmcp",
"version": "0.13.0"
},
"instructions": "This server provides counter tools and prompts. Tools: increment, decrement, get_value, say_hello, echo, sum. Prompts: example_prompt (takes a message), counter_analysis (analyzes counter state with a goal)."
}
}
Session ID: c7007081-f2ba-44c5-a148-93f4aadadaa1
{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [
{
"type": "text",
"text": "0"
}
],
"isError": false
}
}
配置
要针对其他MCP服务器进行测试,请修改 URL 变量in test.sh:
URL="http://your-server:port/mcp"许可证
这是一个MCP服务器实现的测试/示例项目。
