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:
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
# Starts the fat jar in HTTP mode and drives it with curl. Usage: scripts/curl-http.sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
PORT=18089
|
||||
URL=http://127.0.0.1:$PORT/mcp
|
||||
OUT=output/06-fat-jar-curl.txt
|
||||
java -jar target/mcp-sdk-plain.jar http $PORT >/dev/null 2>&1 &
|
||||
PID=$!
|
||||
trap 'kill $PID 2>/dev/null || true' EXIT
|
||||
for i in $(seq 1 40); do curl -s -o /dev/null "http://127.0.0.1:$PORT/" && break; sleep 0.5; done
|
||||
H=(-H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream')
|
||||
{
|
||||
echo "\$ curl -i -X POST $URL (initialize)"
|
||||
RESP=$(curl -s -i "${H[@]}" -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"curl","version":"0"}}}' "$URL" | tr -d '\r')
|
||||
SID=$(echo "$RESP" | awk -F': ' 'tolower($1)=="mcp-session-id"{print $2}')
|
||||
echo "$RESP" | sed "s/$SID/<session-id>/" | grep -iv '^date:\|^server:'
|
||||
echo
|
||||
echo "\$ curl -X POST $URL -H 'Mcp-Session-Id: <session-id>' (tools/call word_stats)"
|
||||
curl -s "${H[@]}" -H "Mcp-Session-Id: $SID" -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"word_stats","arguments":{"text":"one two three"}}}' "$URL"
|
||||
echo
|
||||
} > "$OUT"
|
||||
cat "$OUT"
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
# Talks to the fat jar the way Claude Desktop does: newline-delimited JSON-RPC on stdin, responses on stdout.
|
||||
# Usage: scripts/raw-stdio.sh (run `mvn -pl mcp-sdk-plain package` first)
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
OUT=output/05-fat-jar-raw-stdio.txt
|
||||
{
|
||||
echo '$ printf <3 JSON-RPC lines> | java -jar target/mcp-sdk-plain.jar stdio'
|
||||
(
|
||||
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"raw","version":"0"}}}'
|
||||
printf '%s\n' '{"jsonrpc":"2.0","method":"notifications/initialized"}'
|
||||
printf '%s\n' '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"word_stats","arguments":{"text":"one two three"}}}'
|
||||
sleep 3
|
||||
) | java -jar target/mcp-sdk-plain.jar stdio 2>/dev/null
|
||||
} > "$OUT"
|
||||
cat "$OUT"
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regenerates every file in output/: tests write 01-04, the two scripts write 05-06 against the packaged jar.
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
mvn -B -q -f ../pom.xml -pl mcp-sdk-plain package
|
||||
bash scripts/raw-stdio.sh
|
||||
bash scripts/curl-http.sh
|
||||
Reference in New Issue
Block a user