MCPcopy Create free account
hub / github.com/IBM/mcp-cli / mock_execute

Function mock_execute

examples/tools/demo_tool_execution.py:109–131  ·  view source on GitHub ↗
(tool_name, arguments, server_index=0)

Source from the content-addressed store, hash-verified

107
108 # Mock the execute_tool method
109 async def mock_execute(tool_name, arguments, server_index=0):
110 if tool_name == "echo":
111 return {"echoed": arguments.get("message", "")}
112 elif tool_name == "calculate":
113 op = arguments.get("operation")
114 a = arguments.get("a", 0)
115 b = arguments.get("b", 0)
116 if op == "add":
117 return {"result": a + b}
118 elif op == "subtract":
119 return {"result": a - b}
120 elif op == "multiply":
121 return {"result": a * b}
122 elif op == "divide":
123 return {"result": a / b if b != 0 else "Error: Division by zero"}
124 elif tool_name == "query_database":
125 return {
126 "rows": [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}],
127 "count": 2,
128 }
129 elif tool_name == "list_files":
130 return {"files": ["file1.txt", "file2.py", "data.json"]}
131 return {"error": "Unknown tool"}
132
133 tool_manager.execute_tool = mock_execute
134

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected