diff --git a/scripts/discordbot.py b/scripts/discordbot.py index 4be40b7..3f5691e 100644 --- a/scripts/discordbot.py +++ b/scripts/discordbot.py @@ -99,8 +99,13 @@ async def execute_mcp_tool(tool_name: str, arguments: dict) -> str: f"{base_url}/mcp/call_tool", headers=headers, json={ - "name": tool_name, - "arguments": arguments + "jsonrpc": "2.0", + "method": "tools/call", + "params": { + "name": tool_name, + "arguments": arguments + }, + "id": 1 } ) @@ -110,12 +115,26 @@ async def execute_mcp_tool(tool_name: str, arguments: dict) -> str: result = response.json() debug_log(f"MCP tool result: {str(result)[:200]}...") - # MCP returns content in various formats, extract the text + # Handle JSON-RPC response format if isinstance(result, dict): + # Check for JSON-RPC result + if "result" in result: + rpc_result = result["result"] + # MCP tool results have a "content" array + if isinstance(rpc_result, dict) and "content" in rpc_result: + content = rpc_result["content"] + if isinstance(content, list) and len(content) > 0: + # Handle text content blocks + first_content = content[0] + if isinstance(first_content, dict) and "text" in first_content: + return first_content["text"] + return json.dumps(content) + return json.dumps(content) if content else "Tool executed successfully" + return json.dumps(rpc_result) + # Fallback for non-RPC format if "content" in result: content = result["content"] if isinstance(content, list) and len(content) > 0: - # Handle text content blocks first_content = content[0] if isinstance(first_content, dict) and "text" in first_content: return first_content["text"]