Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -90,15 +90,30 @@ TOOLS = [
|
|
| 90 |
]
|
| 91 |
|
| 92 |
def call_mcp_tool(tool_name, parameters):
|
| 93 |
-
"""Call MCP tool via
|
| 94 |
try:
|
| 95 |
-
# MCP
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
-
response = requests.post(
|
| 100 |
response.raise_for_status()
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
except Exception as e:
|
| 103 |
return {"error": str(e)}
|
| 104 |
|
|
|
|
| 90 |
]
|
| 91 |
|
| 92 |
def call_mcp_tool(tool_name, parameters):
|
| 93 |
+
"""Call MCP tool via JSON-RPC protocol"""
|
| 94 |
try:
|
| 95 |
+
# MCP uses JSON-RPC 2.0 protocol
|
| 96 |
+
payload = {
|
| 97 |
+
"jsonrpc": "2.0",
|
| 98 |
+
"id": 1,
|
| 99 |
+
"method": "tools/call",
|
| 100 |
+
"params": {
|
| 101 |
+
"name": tool_name,
|
| 102 |
+
"arguments": parameters
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
|
| 106 |
+
response = requests.post(MCP_URL, json=payload, timeout=60)
|
| 107 |
response.raise_for_status()
|
| 108 |
+
result = response.json()
|
| 109 |
+
|
| 110 |
+
# Extract result from JSON-RPC response
|
| 111 |
+
if "result" in result:
|
| 112 |
+
return result["result"]
|
| 113 |
+
elif "error" in result:
|
| 114 |
+
return {"error": result["error"]}
|
| 115 |
+
else:
|
| 116 |
+
return result
|
| 117 |
except Exception as e:
|
| 118 |
return {"error": str(e)}
|
| 119 |
|