mcp server demo
如何通信
1.http://localhost:8090/sse
输出:
event:endpoint
data:/mcp/message?sessionId=8a57c258-068f-4c52-b08d-d69ac85c583e
此时内页会进入等待通道已经建立
2.获取tools列表【路径是上面返回data】
curl --location --request POST 'http://localhost:8090/mcp/message?sessionId=8a57c258-068f-4c52-b08d-d69ac85c583e' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "notifications/initialized"
}'
或
curl --location --request POST 'http://localhost:8090/mcp/message?sessionId=8a57c258-068f-4c52-b08d-d69ac85c583e' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "tools/list",
"id": "e60983d1-1",
"params": {}
}'
3.sse页面返回内容
event:endpoint
data:/mcp/message?sessionId=8a57c258-068f-4c52-b08d-d69ac85c583e
event:message
data:{"jsonrpc":"2.0","id":"e60983d1-1","result":{"tools":[{"name":"add","description":"加法","inputSchema":{"type":"object","properties":{"a":{"type":"integer","format":"int32","description":"第一个参数"},"b":{"type":"integer","format":"int32","description":"第二个参数"}},"required":["a","b"],"additionalProperties":false}},{"name":"owner_getByUserName","description":"根据名称返回年龄","inputSchema":{"type":"object","properties":{"name":{"type":"string","description":"名称"}},"required":["name"],"additionalProperties":false}}]}}