Read lines until we get the JSON-RPC response matching request_id. The server may send raw data events ({"data": "..."}) interleaved with JSON-RPC responses. These are silently skipped.
(self, request_id)
| 81 | return json.loads(line.decode("utf-8")) |
| 82 | |
| 83 | def _read_response(self, request_id): |
| 84 | """Read lines until we get the JSON-RPC response matching request_id. |
| 85 | |
| 86 | The server may send raw data events ({"data": "..."}) interleaved |
| 87 | with JSON-RPC responses. These are silently skipped. |
| 88 | """ |
| 89 | while True: |
| 90 | msg = self._read_line() |
| 91 | |
| 92 | # Skip raw data events from the server |
| 93 | if "data" in msg and "jsonrpc" not in msg: |
| 94 | continue |
| 95 | |
| 96 | # Match by request id if present |
| 97 | if msg.get("id") == request_id: |
| 98 | return msg |
| 99 | |
| 100 | # Accept any JSON-RPC response if id doesn't match |
| 101 | # (shouldn't happen in sequential usage, but be safe) |
| 102 | if "jsonrpc" in msg: |
| 103 | return msg |
| 104 | |
| 105 | def initialize(self): |
| 106 | """Initialize MCP session""" |
no test coverage detected