Repository navigation
fix(mcp): keep isError through call_tool and test native tool surface parity - #45081
Conversation
…ibility mode Add tests that build the native and compatibility (search_tools/call_tool) surfaces from the registered tools and the default middleware stack, and check that both expose the same definitions, results, validation errors, and authorization decisions: RBAC, token scopes, restricted-principal policy, and permission revocation. Record a measured native catalog inventory (per-tool annotations, description and schema sizes, list entry sizes with structured output disabled and enabled, catalog totals) and fail on unreviewed growth. Fix LoggingMiddleware dropping isError when it rewraps a returned error result. Calls forwarded by the call_tool proxy return their converted error as a result, so permission and validation errors reached clients as successful results and were logged as successes. Document the native and compatibility discovery modes, migration, and mixed-version rollout.
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
CodeAnt PR Risk: Low Risk
Assessed commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #45081 +/- ##
=======================================
Coverage 82.85% 82.85%
=======================================
Files 3017 3017
Lines 192909 192923 +14
Branches 44974 44976 +2
=======================================
+ Hits 159836 159850 +14
Misses 30034 30034
Partials 3039 3039
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
AI review at head e388bdaVerdict: CLEAN Reviewed the full five-file diff against master for correctness, regressions, security (against SECURITY.md), and test coverage. No actionable findings. Preserving Validation:
No fixes or commits needed; worktree remains clean. Local Superset HTTP health was unavailable, so no live HTTP deployment validation was performed; protocol contract tests ran successfully using the in-process MCP client. |
Acceptance test at head e388bdaSetup. Local Python 3.11 venv from The PR also runs green locally: the two test files pass, 93 passed. Swapping
Observation, not blocking: a tool removed by a service flag, called by name, returns Verdict: PASS. No changes pushed. |
rebenitez1802
left a comment
There was a problem hiding this comment.
Request changes: the isError fix works, but introduces incorrect error metrics for proxied failures. All 93 focused tests passed.
🟡 Medium — Proxy validation failures inflate error metrics
At middleware.py:891–894, the outer proxy marks returned errors unsuccessful but loses the inner user-error classification. Reproduced with get_chart_type_schema({}): direct calls increment only .warning, while call_tool increments both .warning and .error, incorrectly counting ordinary validation failures as errors. Fix: suppress redundant proxy outcome metrics or preserve the inner classification, and add a proxy metrics regression test.
A failure forwarded by the call_tool proxy is returned as an error result rather than raised, so the proxy's own call was counted as a system error in addition to the warning or error the proxied tool had already recorded. Skip the proxy-level outcome and timing metrics for such a returned failure; the result still reports isError and the call is still audited as failed. Add tests that compare the metrics of direct and proxied validation and permission failures, direct failures with and without the proxy installed, and proxied successes.
|
Addressed in 61efcbd. The proxy-level outcome and timing metrics are now skipped when Added tests covering a proxied validation failure and a proxied permission failure ( |
The managed-dashboard refusal fields added to the dashboard tool outputs grow their recorded output schemas.
rebenitez1802
left a comment
There was a problem hiding this comment.
Request changes: the default proxy issue is fixed, but remains with customized proxy names. All 97 focused tests passed.
🟡 Medium — Configured proxy names bypass the metrics fix
At middleware.py:861, suppression depends on mcp_tool, which is populated only for literal call_tool. Reproduced with call_tool_name="invoke_tool": invalid get_chart_type_schema arguments emit both get_chart_type_schema.warning and invoke_tool.error, falsely increasing aggregate error counts. Fix: recognize the configured proxy name and cover it in the metrics regression tests.
…ied failures The proxied-failure metrics suppression keyed on the proxy being literally named call_tool, so a renamed proxy (call_tool_name in MCP_TOOL_SEARCH_CONFIG) counted a forwarded validation failure a second time as an error. Resolve the proxy name from the same setting the proxy is registered under, and cover default and custom names in the metrics tests.
|
@rebenitez1802 Fixed in b301ec3. The proxied-failure suppression now resolves the proxy name from The regression test in |
rebenitez1802
left a comment
There was a problem hiding this comment.
Request changes: the isError fix and the round-1/round-2 metric fixes all landed correctly, but the de-dup guard is only half-symmetric — successful proxied calls are still double-counted, and the new test hides it behind set().
Both prior comments resolved. The isError rebuild now preserves is_error (middleware.py:932), returned error results are classified as failures (middleware.py:920-923), and the configured proxy name is honored everywhere via _call_tool_proxy_name() (middleware.py:540, 682, 853) — consistent with the registration source at server.py:1105. test_forwarded_failure_through_renamed_proxy_is_not_recounted and test_proxied_failure_is_counted_once_under_any_configured_proxy_name[invoke_tool] cover exactly the renamed-proxy case I raised in round 2. 👍
Two findings inline below.
Suppress redundant proxy counters and timings for successful as well as failed calls, while retaining metrics for proxy-level exceptions. Assert exact success metric lists and cover default and configured proxy names.
rebenitez1802
left a comment
There was a problem hiding this comment.
Approve: both round-2 findings fixed exactly, and the metric de-dup is now symmetric and well covered. No blocking issues.
🟡 Medium (successful proxied calls double-counted) — resolved. The guard at middleware.py:895 is now if mcp_tool is not None and raised_is_user_error is None: return, so the outer proxy pass skips the redundant emission for both successes and failures, while a genuine proxy-level raise (raised_is_user_error set) is still counted. Docstring generalized to "An outcome the call_tool proxy merely forwards…".
🟢 Low (test masked the bug with set()) — resolved. test_proxied_success_metrics_are_unchanged now asserts proxied_keys == direct_keys and compares timing (proxied_timing == direct_timing) instead of collapsing duplicates through set(). A new test_proxied_success_is_counted_once_under_any_configured_proxy_name[call_tool, invoke_tool] pins the once-only success count under a renamed proxy too.
The mock-based unit test I'd flagged as needing rework was handled: test_metric_uses_resolved_tool_name_for_call_tool_proxy became test_forwarded_success_is_not_recounted_by_call_tool_proxy (asserts incr/timing not called), and a new test_proxy_level_exception_is_still_counted[warning, error] confirms the de-dup never suppresses an exception raised by the proxy itself.
Failure and success paths are now consistently counted once on every discovery surface. Nice work. (Note: I couldn't run the focused suite locally due to a stale-venv version skew unrelated to this PR; relying on the reported pass and CI.)
SUMMARY
The MCP service serves one set of registered tools in two discovery shapes, both built from
build_middleware_list():MCP_TOOL_SEARCH_CONFIG["enabled"] = True.tools/listreturns the pinned tools plussearch_tools/call_tool.enabled = False.tools/listreturns every permitted tool under its real name.Neither shape had a contract test for the native surface or for parity between the two. This PR adds those tests, records a measured inventory of the native catalog, and fixes one parity bug they found. No default changes.
Fix:
call_toollostisError.LoggingMiddlewarerebuilds theToolResultto attachmcp_call_id, and the rebuild droppedis_error. A direct call raises at that layer, so the flag survived. A call forwarded by thecall_toolproxy is different: its inner middleware chain has already turned the exception into an error result. The outer rebuild then turned that into a success, so a permission denial or validation error sent throughcall_toolreached the client withisError: false. It was also logged as successful. The rebuild now keepsis_error, and a returned error result is logged as a failure.Native inventory (
native_tool_inventory.json): for each registered tool it records the annotations, description length, input/output schema size, and the fulltools/listentry size with structured output disabled and enabled, plus catalog totals. These are measured from the canonical definitions over the MCP protocol, not maintained by hand. Sizes may shrink; growth past 2% or 200 bytes fails until the report is regenerated withSUPERSET_MCP_UPDATE_TOOL_INVENTORY=1. Measured on this branch: 79 tools. The full native listing is 218,156 bytes text-only and 524,788 bytes structured. The largest entry ismanage_native_filtersat 10,916 bytes text-only andgenerate_chartat 28,070 bytes structured. The longest description isgenerate_chartat 6,688 characters.Contract tests (
test_native_tool_surface.py), all checked on the native path, a direct named call in compatibility mode, and thecall_toolproxy:tools/listlists every registered tool exactly once, as one deterministic page with no cursor and no synthetic tools.dereference_schemas.outputSchemais present for every tool only whenMCP_STRUCTURED_OUTPUT_ENABLED = True.$ref.ALLOWED_UNPROTECTEDrun for every caller, as designed.structuredContenton all three paths under both structured-output settings, and the structured result validates against the advertised schema.tools/listvssearch_tools) and the same denial. A hidden tool named directly or throughcall_toolis rejected.MCP_DISABLED_TOOLS, is unreachable and absent from search.Docs:
mcp-server.mdxnow describes both discovery modes and authorization in each. It adds migration steps and mixed-version and multi-pod rollout notes, and states that compatibility mode remains supported and any default change will be listed inUPDATING.md. It also removes a stale reference to middleware classes that do not exist; the service applies no rate limiting of its own.Known differences, kept unchanged and documented:
tools/listfails open whilesearch_toolsshows only permission-free tools. Protected calls are rejected either way.idempotentHintunset.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable; MCP protocol behavior and tests only.
TESTING INSTRUCTIONS
PYTHONPATH="$PWD/superset-core/src" pytest -q \ tests/unit_tests/mcp_service/test_native_tool_surface.py \ tests/unit_tests/mcp_service/test_middleware_logging.pyWithout the
LoggingMiddlewarechange, 7 of the 17 surface tests fail because proxied errors arrive withisError: false.ADDITIONAL INFORMATION