Skip to content

The agent that grows with you

fix(mcp): trim the read-only hint reader; the e2e read-only cell passes

Tekniumca398ea39e06
diff --git a/tests/e2e/core/mcp_plugins/test_mcp_stdio_conformance.py b/tests/e2e/core/mcp_plugins/test_mcp_stdio_conformance.py
index 8d540b45dda..105bf2d232d 100644
--- a/tests/e2e/core/mcp_plugins/test_mcp_stdio_conformance.py
+++ b/tests/e2e/core/mcp_plugins/test_mcp_stdio_conformance.py
@@ -58,10 +58,6 @@ UNSUPPORTED_IMAGES = ("svg", "avif", "tiff", "heic", "badb64")
# Open bugs on origin/main: test id -> (the symptom's own message pattern, "#issue reason"). Run-time
# gated around the symptom() check only (known_gate); drop an entry when its fix lands.
KNOWN: dict[str, tuple[str, str]] = {
- "test_untrusted_server_runs_read_only_tool_without_approval": (
- r"^readOnlyHint=true tool was gated on an untrusted server: server got \[\], "
- r"model got .*write-capable MCP tool 'ro_probe'",
- "#121042 readOnlyHint read by camelCase attribute under mcp 2.x; every tool needs approval"),
**{f"test_uncacheable_image_is_reported_to_the_model[{fmt}]": (
rf"^{fmt} image block vanished: the model got no sign the tool returned an image",
"#120227 an MCP image the cache cannot store vanishes from the tool result") for fmt in UNSUPPORTED_IMAGES},
diff --git a/tools/mcp_tool_registration.py b/tools/mcp_tool_registration.py
index 6e2bfd99747..ca6629d315d 100644
--- a/tools/mcp_tool_registration.py
+++ b/tools/mcp_tool_registration.py
@@ -47,18 +47,14 @@ def _normalize_server_trust(value: Any) -> str:
def _annotation_read_only_hint(mcp_tool: Any) -> bool:
- """True only when annotations (SDK object or cache dict) carry ``readOnlyHint is True``; unknown = write-capable.
-
- mcp 2.0 renamed ``ToolAnnotations.readOnlyHint`` to ``read_only_hint`` (camelCase survives only as a
- serialization alias, which pydantic does not apply to attribute access), so a bare camelCase getattr
- returns None on 2.x and every honestly-annotated read tool fails closed as write-capable — the
- untrusted gate then asks before reads too, training the user to click through it. Read both names.
- """
+ """True only when annotations (SDK object or cache dict) carry an exact ``True`` read-only hint;
+ unknown = write-capable. mcp 2.x exposes the attribute as ``read_only_hint`` (camelCase is only a
+ serialization alias), so reading camelCase alone gated every read on an untrusted server."""
annotations = getattr(mcp_tool, "annotations", None)
if isinstance(annotations, dict):
hint = annotations.get("readOnlyHint", annotations.get("read_only_hint"))
else:
- hint = mcp_field(annotations, "read_only_hint", "readOnlyHint") if annotations is not None else None
+ hint = mcp_field(annotations, "read_only_hint", "readOnlyHint")
return hint is True