From c658afdc61be87ea6ed162d5a58b4e3ff2b566fd Mon Sep 17 00:00:00 2001 From: Oscar Perez Date: Wed, 18 Nov 2026 15:21:03 +0100 Subject: [PATCH] fix(mcp): a guessed tool name through call_tool is no Sentry issue FastMCP 4's call_tool checks the name itself and re-wraps its NotFoundError in a ToolError. is_expected_failure accepted a wrapped LateError or FastMCPError, but FastMCP 4's NotFoundError is not a FastMCPError, so a guessed name counted as a bug: Sentry ZERNIO-MCP-S (8 events from Cursor) and a traceback in the server log. The agent's answer was already right ("Closest tools: ..."); only the reporting was wrong. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + src/late/mcp/telemetry.py | 5 +++-- tests/test_mcp_telemetry.py | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41788522..5ab1159f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **The MCP server runs on FastMCP 4 and MCP SDK 2.** The `mcp` extra now needs Python 3.11 or later, as FastMCP 4 does: on Python 3.10 it installs without FastMCP and the MCP server cannot run. The SDK itself still supports 3.10. Behavior FastMCP 4 changed is kept: guessed tool names sent through `call_tool` get the closest tools again, a result holding half an emoji is repaired instead of failing the call, and a pydantic error inside a tool logs where and why it failed, never the response values. The protected-resource metadata override is gone, since MCP SDK 2 renders the issuer without a trailing slash. ### Fixed +- **A guessed tool name sent through `call_tool` opened a Sentry issue.** FastMCP 4's `call_tool` checks the name itself and wraps its `NotFoundError` in a `ToolError`, and FastMCP 4's `NotFoundError` is not a `FastMCPError`, so the failure counted as a bug: Sentry ZERNIO-MCP-S (8 Cursor guesses) and a traceback in the server log. It is an expected failure again; the agent still gets the closest tool names. - **A rate-limited MCP tool call did not say how long to wait, so agents retried into the limit.** 429s were 84% of tool errors (433,000 in the week to Nov 18). The SDK replaced the API's 429 body with "Rate limit exceeded" and dropped `Retry-After`, and for a platform quota (Meta, Google, Reddit) it quoted the Zernio API's own reset time, which says nothing about when the platform accepts requests again. `LateRateLimitError` now keeps the API's message, `code`, `platform` and `details`, and adds `retry_after` (seconds, from `Retry-After` as seconds or a date). The MCP server and the ChatGPT server tell the agent to wait that long, or not to retry an exhausted platform quota, and `mcp_tool_call` logs `retry_after_s`. - **`pip install zernio-sdk` without extras could not import the models.** `EmailStr` fields need `email-validator`, which only arrived through FastMCP. The SDK now depends on `pydantic[email]`. diff --git a/src/late/mcp/telemetry.py b/src/late/mcp/telemetry.py index 1d79c51b..dd6f79b8 100644 --- a/src/late/mcp/telemetry.py +++ b/src/late/mcp/telemetry.py @@ -113,6 +113,7 @@ def quiet_routine_logs() -> None: def is_expected_failure(exc: Exception) -> bool: if isinstance(exc, ToolError) and exc.__cause__ is not None: # A generated tool re-wraps what it raised itself, e.g. the refusal - # of a file too large to return. - return isinstance(exc.__cause__, (LateError, FastMCPError)) + # of a file too large to return, and FastMCP 4's call_tool re-wraps + # the NotFoundError of a guessed name (not a FastMCPError). + return isinstance(exc.__cause__, (LateError, FastMCPError, NotFoundError)) return isinstance(exc, (FastMCPError, NotFoundError, LateError)) diff --git a/tests/test_mcp_telemetry.py b/tests/test_mcp_telemetry.py index 1e03ecad..d0f1863a 100644 --- a/tests/test_mcp_telemetry.py +++ b/tests/test_mcp_telemetry.py @@ -279,6 +279,22 @@ async def test_a_tool_behind_call_tool_is_one_sentry_transaction(sentry_events) assert transaction["tags"]["mcp.via"] == "call_tool" +async def test_a_guessed_name_through_call_tool_opens_no_sentry_issue( + sentry_events, quieted_fastmcp_logs +) -> None: + # FastMCP 4's call_tool checks the name itself and re-wraps its NotFoundError + # in a ToolError: 8 Cursor guesses became Sentry issue ZERNIO-MCP-S. + async with Client(_proxied_server()) as client: + await client.call_tool( + "call_tool", + {"name": "lead_gen_list_forms", "arguments": {}}, + raise_on_error=False, + ) + + assert sentry_events.payloads("event") == [] + assert quieted_fastmcp_logs.records == [] + + async def test_a_direct_call_is_tagged_direct_with_its_caller( sentry_events, monkeypatch ) -> None: