Skip to content

Manual repro steps for PR #7 (tool/prompt name fix in examples/README.md) #8

Description

@yuki3738

PR #7 ([Doc] Use registered callable names in examples/README.md) を手で再現するための cURL 手順メモ。学習用ノート。

前提

0. サーバー起動

別ターミナルで:

$ git checkout fix_tool_name_in_http_server_example   # PR #7 を試すとき
# or
$ git checkout main                                   # 修正前の挙動を見るとき (README は変わらない、登録名は同じ)
$ bundle exec ruby examples/http_server.rb

Listening on http://127.0.0.1:9292 が出れば OK。

1. session 初期化 → SID を取得

$ ACCEPT='Accept: application/json, text/event-stream'

$ SID=$(curl -sS -i http://localhost:9292 \
    -H "$ACCEPT" \
    --json '{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}' \
    | grep -i '^mcp-session-id:' | sed -E 's/^[^:]+: *//' | tr -d '\r')

$ echo "SID=$SID"

2. tools/list で登録名を確認 (PR の根拠)

$ curl -sS http://localhost:9292 \
    -H "$ACCEPT" \
    -H "Mcp-Session-Id: $SID" \
    --json '{"jsonrpc":"2.0","method":"tools/list","id":2}'

期待:

data: {"jsonrpc":"2.0","id":2,"result":{"tools":[{"name":"example_tool",...},{"name":"echo",...}]}}

→ 登録されている tool 名は example_tool (クラス名 ExampleTool ではない)。

3. 旧 README の payload を再現 → Tool not found

$ curl -sS http://localhost:9292 \
    -H "$ACCEPT" \
    -H "Mcp-Session-Id: $SID" \
    --json '{"jsonrpc":"2.0","method":"tools/call","id":3,"params":{"name":"ExampleTool","arguments":{"a":5,"b":3}}}'

期待:

data: {"jsonrpc":"2.0","id":3,"error":{"code":-32602,"message":"Invalid params","data":"Tool not found: ExampleTool"}}

4. 修正後の payload → 成功

$ curl -sS http://localhost:9292 \
    -H "$ACCEPT" \
    -H "Mcp-Session-Id: $SID" \
    --json '{"jsonrpc":"2.0","method":"tools/call","id":4,"params":{"name":"example_tool","arguments":{"a":5,"b":3}}}'

期待:

data: {"jsonrpc":"2.0","id":4,"result":{"content":[{"type":"text","text":"The sum of 5 and 3 is 8"}],"isError":false}}

5. prompt 側の確認

$ curl -sS http://localhost:9292 \
    -H "$ACCEPT" \
    -H "Mcp-Session-Id: $SID" \
    --json '{"jsonrpc":"2.0","method":"prompts/list","id":5}'

期待: "name":"example_prompt" (クラス名 ExamplePrompt ではない)。

ハマりどころメモ

  • Accept header 必須: 上記のとおり。README にも書かれていない別件 doc バグ。
  • SID は 1 セッション 1 個: 上で取った SID を 2〜5 で使い回す。新シェルに移ったら再取得。
  • レスポンスは SSE 形式: data: prefix を剥がしてから jq / python -m json.tool に渡す。
  • set -e + パイプ注意: SSE 出力を json parser にそのまま渡すと parse 失敗で全部止まる。raw のまま見るのが楽。

参考

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions