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

Method request

tests/integration/test_mcp.py:121–136  ·  view source on GitHub ↗

Send a JSON-RPC request and return the result (raises MCPError on error).

(self, method: str, params: Optional[dict] = None)

Source from the content-addressed store, hash-verified

119 pass
120
121 def request(self, method: str, params: Optional[dict] = None) -> Any:
122 """Send a JSON-RPC request and return the result (raises MCPError on error)."""
123 req_id = self._next_id()
124 self._send(
125 {"jsonrpc": "2.0", "id": req_id, "method": method, "params": params or {}}
126 )
127 deadline = time.time() + self.timeout
128 while True:
129 response = self._recv(deadline)
130 if response.get("id") == req_id:
131 if "error" in response:
132 err = response["error"]
133 raise MCPError(
134 err.get("code", -1), err.get("message", ""), err.get("data")
135 )
136 return response.get("result")
137
138 def notify(self, method: str, params: Optional[dict] = None) -> None:
139 """Send a JSON-RPC notification (no response expected)."""

Callers 15

initializeMethod · 0.95
tools_listMethod · 0.95
tools_callMethod · 0.95
resources_listMethod · 0.95
resources_readMethod · 0.95
prompts_listMethod · 0.95
prompts_getMethod · 0.95
test_ping_respondsMethod · 0.80

Calls 5

_next_idMethod · 0.95
_sendMethod · 0.95
_recvMethod · 0.95
MCPErrorClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected