use uv to run test, more fixes
This commit is contained in:
@@ -30,11 +30,15 @@ class McpClient:
|
||||
except subprocess.TimeoutExpired:
|
||||
self._proc.kill()
|
||||
|
||||
@property
|
||||
def returncode(self):
|
||||
return self._proc.poll()
|
||||
|
||||
@property
|
||||
def stderr(self):
|
||||
return self._proc.stderr
|
||||
|
||||
def send_request(self, method: str, params: dict | None = None) -> dict:
|
||||
def send_request(self, method: str, params: dict | None = None, timeout: float = 60.0) -> dict:
|
||||
self._next_id += 1
|
||||
req = {
|
||||
"jsonrpc": "2.0",
|
||||
@@ -45,14 +49,17 @@ class McpClient:
|
||||
line = json.dumps(req)
|
||||
self._proc.stdin.write(line + "\n")
|
||||
self._proc.stdin.flush()
|
||||
return self._read_response(self._next_id)
|
||||
return self._read_response(self._next_id, timeout=timeout)
|
||||
|
||||
def _read_response(self, expected_id: int, timeout: float = 60.0) -> dict:
|
||||
deadline = time.monotonic() + timeout
|
||||
while time.monotonic() < deadline:
|
||||
line = self._proc.stdout.readline()
|
||||
if not line:
|
||||
raise RuntimeError("Bridge process terminated")
|
||||
stderr = self._proc.stderr.read()
|
||||
rc = self._proc.poll()
|
||||
raise RuntimeError(
|
||||
f"Bridge process terminated (rc={rc}, stderr: {stderr[-500:] if stderr else 'none'})")
|
||||
resp = json.loads(line)
|
||||
rid = resp.get("id")
|
||||
if rid == expected_id:
|
||||
@@ -74,8 +81,8 @@ class McpClient:
|
||||
self._initialized = True
|
||||
return resp
|
||||
|
||||
def call_tool(self, name: str, arguments: dict | None = None) -> dict:
|
||||
resp = self.send_request("tools/call", {"name": name, "arguments": arguments or {}})
|
||||
def call_tool(self, name: str, arguments: dict | None = None, timeout: float = 60.0) -> dict:
|
||||
resp = self.send_request("tools/call", {"name": name, "arguments": arguments or {}}, timeout=timeout)
|
||||
content = resp.get("result", {}).get("content", [])
|
||||
if content and content[0].get("type") == "text":
|
||||
text = content[0]["text"]
|
||||
|
||||
Reference in New Issue
Block a user