MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / _read_response

Method _read_response

examples/MCP Client/client.py:83–103  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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"""

Callers 1

send_requestMethod · 0.95

Calls 2

_read_lineMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected