Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mcp_servers/multi_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ async def route_tool_call(self, tool_name: str, arguments: dict):
"write_workspace_file",
}:
arguments = dict(arguments or {})
arguments.setdefault("workspace_root", trace_context["workspace"])
arguments["workspace_root"] = trace_context["workspace"]

# Get or create circuit breaker for this tool
breaker = get_breaker(tool_name, failure_threshold=5, recovery_timeout=60.0)
Expand Down
30 changes: 30 additions & 0 deletions tests/test_mockehr_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,33 @@ async def _fake_call_tool(server_name, tool_name, arguments):
assert called["server"] == "mockehr"
assert result["ok"] is True


def test_route_tool_call_forces_trusted_workspace_root():
mm = MultiMCP()
mm.tools = {"sandbox": [_DummyTool("write_workspace_file")]}
mm.sessions = {"sandbox": object()}
called = {"arguments": None}

async def _fake_call_tool(server_name, tool_name, arguments):
called["arguments"] = arguments
return {"ok": True}

mm.call_tool = _fake_call_tool # type: ignore[assignment]
token = mm.set_trace_context({"workspace": "/trusted/workspace"})
try:
result = asyncio.run(
mm.route_tool_call(
"write_workspace_file",
{
"workspace_root": "/workspace",
"path": "config/settings.json",
"content": "{}",
},
)
)
finally:
mm.reset_trace_context(token)

assert result["ok"] is True
assert called["arguments"]["workspace_root"] == "/trusted/workspace"

Loading