文章目錄
- 初始化
- 調用
mcp server使用modelcontextprotocol 的java sdk編寫
初始化
1.網頁訪問http://localhost:8090/sse,此頁面保持開啟,會不斷接收到sse事件.
會返回一個endpoint,例如/mcp/message?sessionId=111
2.初始化請求,postman發送post請求
url:http://localhost:8090/mcp/message?sessionId=111
body: {"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"Cline","version":"3.26.1"}},"jsonrpc":"2.0","id":0}
3.notify請求,告知server client端初始化已完成
url:http://localhost:8090/mcp/message?sessionId=111
{"method":"notifications/initialized","jsonrpc":"2.0"}
調用
初始化完成后,才能調用tool/list和tool/call接口.所有接口請求時要保持sessionId一致.通過mcp/message發送請求后,響應結果在網頁的http://localhost:8090/sse查看.
url:http://localhost:8090/mcp/message?sessionId=111
body:{"method":"tools/list","jsonrpc":"2.0","id":2}
調用工具
url:http://localhost:8090/mcp/message?sessionId=111
{"method":"tools/call","params":{"name":"getOrderDetail","arguments":{"orderId":"26222"}},"jsonrpc":"2.0","id":4}