feat(mcp_client): Implement ExternalMCPManager and StdioMCPServer with tests
This commit is contained in:
47
scripts/mock_mcp_server.py
Normal file
47
scripts/mock_mcp_server.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import sys
|
||||
import json
|
||||
|
||||
def main():
|
||||
while True:
|
||||
line = sys.stdin.readline()
|
||||
if not line:
|
||||
break
|
||||
try:
|
||||
req = json.loads(line)
|
||||
method = req.get("method")
|
||||
req_id = req.get("id")
|
||||
|
||||
if method == "tools/list":
|
||||
resp = {
|
||||
"jsonrpc": "2.0",
|
||||
"id": req_id,
|
||||
"result": {
|
||||
"tools": [
|
||||
{"name": "echo", "description": "Echo input", "inputSchema": {"type": "object"}}
|
||||
]
|
||||
}
|
||||
}
|
||||
elif method == "tools/call":
|
||||
name = req["params"].get("name")
|
||||
args = req["params"].get("arguments", {})
|
||||
if name == "echo":
|
||||
resp = {
|
||||
"jsonrpc": "2.0",
|
||||
"id": req_id,
|
||||
"result": {
|
||||
"content": [{"type": "text", "text": f"ECHO: {args}"}]
|
||||
}
|
||||
}
|
||||
else:
|
||||
resp = {"jsonrpc": "2.0", "id": req_id, "error": {"message": "Unknown tool"}}
|
||||
else:
|
||||
resp = {"jsonrpc": "2.0", "id": req_id, "error": {"message": "Unknown method"}}
|
||||
|
||||
sys.stdout.write(json.dumps(resp) + "\n")
|
||||
sys.stdout.flush()
|
||||
except Exception as e:
|
||||
sys.stderr.write(f"Error: {e}\n")
|
||||
sys.stderr.flush()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user