call sends one JSON-RPC request and returns the `result` object.
(t *testing.T, method string, params any)
| 498 | |
| 499 | // call sends one JSON-RPC request and returns the `result` object. |
| 500 | func (m *mcpProc) call(t *testing.T, method string, params any) map[string]any { |
| 501 | t.Helper() |
| 502 | m.nextID++ |
| 503 | req := map[string]any{"jsonrpc": "2.0", "id": m.nextID, "method": method} |
| 504 | if params != nil { |
| 505 | req["params"] = params |
| 506 | } |
| 507 | require.NoError(t, m.stdin.Encode(req)) |
| 508 | require.True(t, m.stdout.Scan(), "mcp server closed stdout (scan err: %v)", m.stdout.Err()) |
| 509 | var resp struct { |
| 510 | Result map[string]any `json:"result"` |
| 511 | Error any `json:"error"` |
| 512 | } |
| 513 | require.NoError(t, json.Unmarshal(m.stdout.Bytes(), &resp)) |
| 514 | require.Nil(t, resp.Error, "jsonrpc error for %s", method) |
| 515 | return resp.Result |
| 516 | } |
| 517 | |
| 518 | // notify sends a JSON-RPC notification (no response expected). |
| 519 | func (m *mcpProc) notify(t *testing.T, method string) { |
no test coverage detected