Skip to content

Commit 04154d1

Browse files
committed
fix: preserve MCP tool annotation behavior
1 parent 60850ef commit 04154d1

5 files changed

Lines changed: 13 additions & 171 deletions

File tree

‎.changeset/code-mode-destructive-defaults.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
'@truefoundry/trueforge': patch
44
---
55

6-
Fail closed when Code Mode receives MCP tools with missing or incomplete annotations, and accept both MCP Python SDK hint casings.
6+
Prefer MCP Python SDK 2.0 snake_case tool annotation fields, with camelCase fallback for older SDKs, without changing destructive-tool detection behavior.

‎packages/trueforge-core/src/core/sandbox/scripts/mcp_client.py‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,15 @@ async def _get_tool(server: str, tool_name: str) -> Tool | None:
224224
def _is_destructive(tool: Tool) -> bool:
225225
annotations = tool.annotations
226226
if annotations is None:
227-
return True
228-
229-
read_only = getattr(annotations, "read_only_hint", None)
230-
if read_only is None:
231-
read_only = getattr(annotations, "readOnlyHint", None)
232-
if read_only is True:
233227
return False
234228

235-
destructive = getattr(annotations, "destructive_hint", None)
236-
if destructive is None:
237-
destructive = getattr(annotations, "destructiveHint", None)
238-
return destructive is not False
229+
destructive = getattr(
230+
annotations, "destructive_hint", getattr(annotations, "destructiveHint", None)
231+
)
232+
read_only = getattr(
233+
annotations, "read_only_hint", getattr(annotations, "readOnlyHint", None)
234+
)
235+
return bool(destructive) or (not read_only and read_only is not None)
239236

240237
async def _ensure_non_destructive(server: str, tool_name: str) -> None:
241238
tool = await _get_tool(server, tool_name)

‎packages/trueforge-core/tests/core/sandbox/scripts/mcpClientPolicy.test.ts‎

Lines changed: 0 additions & 89 deletions
This file was deleted.

‎packages/trueforge/src/sandbox/local/scripts/mcp_client_local.py‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,14 @@ async def _get_tool(server: str, tool_name: str) -> dict[str, Any] | None:
177177

178178
def _is_destructive(tool: dict[str, Any]) -> bool:
179179
annotations = tool.get("annotations")
180+
if annotations is None:
181+
return False
180182
if not isinstance(annotations, dict):
181-
return True
182-
183-
read_only = annotations.get("read_only_hint")
184-
if read_only is None:
185-
read_only = annotations.get("readOnlyHint")
186-
if read_only is True:
187183
return False
188184

189-
destructive = annotations.get("destructive_hint")
190-
if destructive is None:
191-
destructive = annotations.get("destructiveHint")
192-
return destructive is not False
185+
read_only = annotations.get("read_only_hint", annotations.get("readOnlyHint"))
186+
destructive = annotations.get("destructive_hint", annotations.get("destructiveHint"))
187+
return bool(destructive) or (not read_only and read_only is not None)
193188

194189

195190
async def _ensure_non_destructive(server: str, tool_name: str) -> None:

‎packages/trueforge/tests/unit/sandbox/local/scripts/mcpClientPolicy.test.ts‎

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)