mcp sse curl 测试方式

TwoAdmin 2025-9-19 92 9/19

`# Liu XC Personal MCP Server

一个基于 MCP (Model Context Protocol) 的实现twoadmin相关功能。
authenticated为示例,其他功能照猫画虎即可
目前需要实现信息
基础信息
推荐职位

发起调用

curl -X POST http://localhost:8081/tools/call \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-8X2dK9mQpR7sT4uV6wY1zA3bC5eF7gH2jL4nM6oP8qR9tS1uV3wX5yZ7" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "authenticated",
"arguments": {
"userId": "333",
"message": "Hello JSON-RPC"
}
}
}'

查看工具列表


curl -X POST http://localhost:8081/tools/call \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list"
}'

测试 SSE 端点


// 基本测试
curl -N http://localhost:8080/sse

// 带有认证头部的测试如果需要认证
curl -N -H "Authorization: Bearer your-token" http://localhost:8080/sse

// 详细输出,显示请求头
curl -N -v http://localhost:8080/sse

根据sessionId 查询工具列表


curl -X POST 'http://localhost:8080/message?sessionId=09e2bd7a-0e30-461f-9376-698bfe0da065' \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tools/list",
"id": 1
}'

//返回
event: message
data: {"jsonrpc":"2.0","id":1,"result":{"tools":[{"annotations":{"readOnlyHint":false,"destructiveHint":true,"idempotentHint":false,"openWorldHint":true},"description":"执行带认证的HTTP请求","inputSchema":{"properties":{"message":{"description":"要发送的消息内容","type":"string"}},"required":["message"],"type":"object"},"nted"}]}}

根据sessionId 调用authenticated


curl -X POST 'http://localhost:8080/message?sessionId=e14b07c9-b548-4d85-a62b-6fee073a5197' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-8X2dK9mQpR7sT4uV6wY1zA3bC5eF7gH2jL4nM6oP8qR9tS1uV3wX5yZ7" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "authenticated",
"arguments": {
"userId": "333",
"message": "Hello JSON-RPC"
}
}
}'


//返回
event: message
data: {"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"{\n \"success\": true, \n \"data\":{\n\t\t\t\"name\": \"李四\",\n\t\t\t\"erId\": 5,\n\t\t\t\"experience_years\": 5,\n\t\t\t\"skills\": [\"Python\", \"Machine Learning\", \"Data Analysis\", \"SQL\"],\n\t\t\t\"resume_summary\": \"一位拥有验的数据科学家,擅长使用Python进行模型开发和数据分析。在电商推荐系统项目中有成功经验。希望能找到一个高级算法工程师的职位。\",\n\t\t\t\"education\": \"计算机科学硕士\"\n }\n }"}]}}
- THE END -
Tag:

TwoAdmin

9月20日14:47

最后修改:2025年9月20日
0

非特殊说明,本博所有文章均为博主原创。