import json
from unittest.mock import patch
from server.mcp_server import handle_tool_call
def test_mcp_tool_call_set_parameter(capsys):
"""Test that a tool call is executed and produces correct toolResult."""
# Patch the TOOL_FUNCTIONS entry *inside mcp_server*
with patch("server.mcp_server.TOOL_FUNCTIONS", {"setParameter": lambda **kwargs: {"ok": True}}):
msg = {
"type": "toolCall",
"tool": "setParameter",
"arguments": {"param": "cutoff", "value": 0.5}
}
handle_tool_call(msg)
# Check printed toolResult
stdout = capsys.readouterr().out
result = json.loads(stdout)
assert result["type"] == "toolResult"
assert result["tool"] == "setParameter"
assert result["result"] == {"ok": True}