Add mcp-sdk-plain module: MCP server on the plain Java SDK 2.1.0 over stdio and Streamable HTTP, fat jar, wire transcripts and a Spring AI client
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b5oh78z7gcH6QkxafF
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
server: notes-server 1.0.0
|
||||
protocol: 2025-11-25
|
||||
capabilities: tools=true resources=true prompts=false
|
||||
instructions: Tools: word_stats, divide, explode. Resources: notes://readme and notes://{name}.
|
||||
-- tools/list
|
||||
word_stats required=[text]
|
||||
divide required=[a, b]
|
||||
explode required=null
|
||||
-- tools/call word_stats
|
||||
isError=false text=words=4 chars=19 longest=quick
|
||||
-- tools/call divide 1/0
|
||||
isError=true text=Cannot divide 1.0 by zero.
|
||||
-- tools/call word_stats with a missing argument
|
||||
isError=true text=Tool (word_stats) input validation failed: Validation failed: JSON schema validation errors: [: required property 'text' not found]
|
||||
-- tools/call explode
|
||||
threw McpError: boom from the handler
|
||||
-- resources/list
|
||||
notes://readme text/markdown
|
||||
-- resources/templates/list
|
||||
notes://{name}
|
||||
-- resources/read notes://readme
|
||||
# Notes server
|
||||
Built with the plain MCP Java SDK.
|
||||
-- resources/read notes://todo
|
||||
1. Write the post
|
||||
2. Run the server
|
||||
3. Publish
|
||||
-- resources/read notes://missing
|
||||
threw McpError: No note called missing
|
||||
@@ -0,0 +1,29 @@
|
||||
server: notes-server 1.0.0
|
||||
protocol: 2025-11-25
|
||||
capabilities: tools=true resources=true prompts=false
|
||||
instructions: Tools: word_stats, divide, explode. Resources: notes://readme and notes://{name}.
|
||||
-- tools/list
|
||||
word_stats required=[text]
|
||||
divide required=[a, b]
|
||||
explode required=null
|
||||
-- tools/call word_stats
|
||||
isError=false text=words=4 chars=19 longest=quick
|
||||
-- tools/call divide 1/0
|
||||
isError=true text=Cannot divide 1.0 by zero.
|
||||
-- tools/call word_stats with a missing argument
|
||||
isError=true text=Tool (word_stats) input validation failed: Validation failed: JSON schema validation errors: [: required property 'text' not found]
|
||||
-- tools/call explode
|
||||
threw McpError: boom from the handler
|
||||
-- resources/list
|
||||
notes://readme text/markdown
|
||||
-- resources/templates/list
|
||||
notes://{name}
|
||||
-- resources/read notes://readme
|
||||
# Notes server
|
||||
Built with the plain MCP Java SDK.
|
||||
-- resources/read notes://todo
|
||||
1. Write the post
|
||||
2. Run the server
|
||||
3. Publish
|
||||
-- resources/read notes://missing
|
||||
threw McpError: No note called missing
|
||||
@@ -0,0 +1,19 @@
|
||||
-- POST initialize, Accept: application/json, text/event-stream
|
||||
status 200
|
||||
content-type application/json;charset=utf-8
|
||||
mcp-session-id present: true
|
||||
body: {"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2025-06-18","capabilities":{"logging":{},"resources":{"subscribe":false,"listChanged":true},"tools":{"listChanged":true}},"serverInfo":{"name":"notes-server","version":"1.0.0"},"instructions":"Tools: word_stats, divide, explode. Resources: notes://readme and notes://{name}."}}
|
||||
-- POST tools/list without the Mcp-Session-Id header
|
||||
status 400
|
||||
jsonRpcError: {"code":-32601,"message":"Session ID required in mcp-session-id header"}
|
||||
body also contains a Java stackTrace: true
|
||||
-- POST initialize with Accept: application/json only
|
||||
status 400
|
||||
jsonRpcError: {"code":-32601,"message":"text/event-stream required in Accept header"}
|
||||
body also contains a Java stackTrace: true
|
||||
-- DELETE with the session id ends the session
|
||||
status 200
|
||||
-- POST tools/list on the ended session
|
||||
status 404
|
||||
jsonRpcError: {"code":-32603,"message":"Session not found: <session-id>"}
|
||||
body also contains a Java stackTrace: true
|
||||
@@ -0,0 +1,2 @@
|
||||
client failed: RuntimeException: Client failed to initialize by explicit API call
|
||||
caused by TimeoutException: Did not observe any item or terminal signal within 20000ms in 'map' (and no fallback has been configured)
|
||||
@@ -0,0 +1,3 @@
|
||||
$ printf <3 JSON-RPC lines> | java -jar target/mcp-sdk-plain.jar stdio
|
||||
{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2025-06-18","capabilities":{"logging":{},"resources":{"subscribe":false,"listChanged":true},"tools":{"listChanged":true}},"serverInfo":{"name":"notes-server","version":"1.0.0"},"instructions":"Tools: word_stats, divide, explode. Resources: notes://readme and notes://{name}."}}
|
||||
{"jsonrpc":"2.0","id":2,"result":{"content":[{"type":"text","text":"words=3 chars=13 longest=three"}],"isError":false}}
|
||||
@@ -0,0 +1,14 @@
|
||||
$ curl -i -X POST http://127.0.0.1:18089/mcp (initialize)
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json;charset=utf-8
|
||||
Mcp-Session-Id: <session-id>
|
||||
Transfer-Encoding: chunked
|
||||
|
||||
{"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2025-06-18","capabilities":{"logging":{},"resources":{"subscribe":false,"listChanged":true},"tools":{"listChanged":true}},"serverInfo":{"name":"notes-server","version":"1.0.0"},"instructions":"Tools: word_stats, divide, explode. Resources: notes://readme and notes://{name}."}}
|
||||
|
||||
$ curl -X POST http://127.0.0.1:18089/mcp -H 'Mcp-Session-Id: <session-id>' (tools/call word_stats)
|
||||
id: a76ab1b0-cb40-43f2-9d82-db0fa6c7f29c
|
||||
event: message
|
||||
data: {"jsonrpc":"2.0","id":2,"result":{"content":[{"type":"text","text":"words=3 chars=13 longest=three"}],"isError":false}}
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
clients: 1
|
||||
server: notes-server 1.0.0
|
||||
tool: word_stats
|
||||
tool: divide
|
||||
tool: explode
|
||||
word_stats -> words=5 chars=25 longest=spring
|
||||
Reference in New Issue
Block a user