Skip to content

Code Mode destructive-tool gate fails open on unannotated tools (and errors on annotated ones with mcp >=2.0) #318

Closed

Description

@chiruu12

_is_destructive() in packages/trueforge-core/src/core/sandbox/scripts/mcp_client.py decides whether a tool is blocked from running in Code Mode (destructive tools are supposed to be pushed to the direct-call approval flow). It has two problems.

def _is_destructive(tool: Tool) -> bool:
    annotations = tool.annotations
    if annotations is None:
        return False
    return bool(annotations.destructiveHint) or (not annotations.readOnlyHint and annotations.readOnlyHint is not None)

1. Fails open on tools without annotations. Most MCP servers ship tools with no annotations at all. For those, this returns False, so a genuinely destructive tool runs in Code Mode without ever hitting the approval flow. The MCP spec defaults destructiveHint to true (destructive unless the server says otherwise), so absence of annotations should be treated as destructive, not safe. The function's second clause already tries to treat a non-read-only tool as destructive, but the annotations is None guard and the readOnlyHint is not None check short-circuit that for the unannotated case.

Repro:

from mcp.types import Tool
t = Tool(name="delete_file", inputSchema={"type": "object"})   # no annotations
assert _is_destructive(t) is False   # runs in Code Mode with no approval

2. Raises AttributeError on annotated tools with mcp >=2.0. The code reads annotations.destructiveHint / annotations.readOnlyHint, but the mcp Python SDK renamed these fields to destructive_hint / read_only_hint in 2.0. Attribute access on the camelCase names raises, so any tool that declares annotations breaks the gate:

t = Tool.model_validate({"name": "delete_file", "inputSchema": {"type": "object"},
                         "annotations": {"destructiveHint": True, "readOnlyHint": False}})
_is_destructive(t)   # AttributeError: 'ToolAnnotations' object has no attribute 'destructiveHint'

Expected: unannotated or unset-hint tools are treated as destructive (fail safe), and annotated tools are read via the SDK's actual field names.

Actual: unannotated destructive tools bypass the Code Mode approval gate; annotated tools raise AttributeError on mcp >=2.0.

Environment: reproduced against mcp==2.0.0, tool annotation defaults per the MCP spec.

Happy to open a PR: read the hints via the SDK field names (handling both casings for compatibility) and default to destructive when destructiveHint is unset and the tool is not explicitly read-only.

Activity

  1. chiragjn commented on Aug 26, 2026

    @chiragjn
    Member

    We will only address 2. in #373

    For 1. we will think of introducing a feature flag like TREAT_UNANNOTATED_TOOLS_AS_DESTRUCTIVE with default false. We will get back after an internal discussion

  2. self-assigned this
    on Aug 26, 2026
  3. chiragjn commented on Sep 25, 2026

    @chiragjn
    Member

    For now, we have decided to not change the behavior for unnotated tools

    Most MCP Servers out in the wild do not have proper tool annotations - in which case the harness would have to trigger approval on every single tool regardless it is destructive or not. We explicitly call out our policy to not gate unannotated tools by default in our docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions