mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2026-09-19 17:25:07 +02:00
fixed mcp stdio server tool listing (#1950)
This commit is contained in:
+11
-1
@@ -498,13 +498,15 @@ class MCPStdioClient:
|
|||||||
finally:
|
finally:
|
||||||
self.alive = False
|
self.alive = False
|
||||||
|
|
||||||
def send(self, message: dict) -> dict: # Send JSON-RPC request and wait for one response.
|
def send(self, message: dict, await_response=True) -> dict: # Send JSON-RPC request and wait for one response.
|
||||||
line = json.dumps(message)
|
line = json.dumps(message)
|
||||||
with self.lock:
|
with self.lock:
|
||||||
if self.process.stdin.closed:
|
if self.process.stdin.closed:
|
||||||
raise RuntimeError("MCP server stdin is closed")
|
raise RuntimeError("MCP server stdin is closed")
|
||||||
self.process.stdin.write(line + "\n")
|
self.process.stdin.write(line + "\n")
|
||||||
self.process.stdin.flush()
|
self.process.stdin.flush()
|
||||||
|
if not await_response:
|
||||||
|
return None
|
||||||
response = self.process.stdout.readline()
|
response = self.process.stdout.readline()
|
||||||
if not response:
|
if not response:
|
||||||
errmsg = "\n".join(self.stderr_buffer[-10:])
|
errmsg = "\n".join(self.stderr_buffer[-10:])
|
||||||
@@ -7658,16 +7660,24 @@ def load_mcp_async(args):
|
|||||||
"clientInfo": {"name": "koboldcpp", "version": "1.0.0"}
|
"clientInfo": {"name": "koboldcpp", "version": "1.0.0"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
notif_payload = {
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"method": "notifications/initialized"
|
||||||
|
}
|
||||||
toolget_payload = {
|
toolget_payload = {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"id": random.randint(100000, 999999),
|
"id": random.randint(100000, 999999),
|
||||||
"method": "tools/list",
|
"method": "tools/list",
|
||||||
"params": {}
|
"params": {}
|
||||||
}
|
}
|
||||||
|
|
||||||
resp1 = conn["client"].send(init_payload)
|
resp1 = conn["client"].send(init_payload)
|
||||||
if "result" not in resp1:
|
if "result" not in resp1:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
conn["client"].send(notif_payload, await_response=False)
|
||||||
resp2 = conn["client"].send(toolget_payload)
|
resp2 = conn["client"].send(toolget_payload)
|
||||||
|
|
||||||
if "result" not in resp2 or "tools" not in resp2["result"]:
|
if "result" not in resp2 or "tools" not in resp2["result"]:
|
||||||
continue
|
continue
|
||||||
with mcp_lock:
|
with mcp_lock:
|
||||||
|
|||||||
Reference in New Issue
Block a user