Skip to content

Commit 940c4e5

Browse files
authored
fix(code-mode): prefer snake case mcp tool annotations fields over camel case ones (#373)
* fix: fail closed for unannotated MCP tools * fix: preserve MCP tool annotation behavior --------- Co-authored-by: MTEnt <29636429+MTEnt@users.noreply.github.com>
1 parent 16feb29 commit 940c4e5

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@truefoundry/trueforge-core': patch
3+
'@truefoundry/trueforge': patch
4+
---
5+
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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,14 @@ def _is_destructive(tool: Tool) -> bool:
225225
annotations = tool.annotations
226226
if annotations is None:
227227
return False
228-
return bool(annotations.destructiveHint) or (not annotations.readOnlyHint and annotations.readOnlyHint is not None)
228+
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)
229236

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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ def _is_destructive(tool: dict[str, Any]) -> bool:
181181
return False
182182
if not isinstance(annotations, dict):
183183
return False
184-
destructive = annotations.get("destructiveHint")
185-
read_only = annotations.get("readOnlyHint")
184+
185+
read_only = annotations.get("read_only_hint", annotations.get("readOnlyHint"))
186+
destructive = annotations.get("destructive_hint", annotations.get("destructiveHint"))
186187
return bool(destructive) or (not read_only and read_only is not None)
187188

188189

0 commit comments

Comments
 (0)