fix(mcp): missing params in MCP tool call logs - #42660
Conversation
Code Review Agent Run #43ec0aActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #42660 +/- ##
==========================================
- Coverage 65.45% 65.43% -0.03%
==========================================
Files 2810 2810
Lines 159362 159422 +60
Branches 36374 36382 +8
==========================================
+ Hits 104308 104315 +7
- Misses 53012 53064 +52
- Partials 2042 2043 +1
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:
|
aminghadersohi
left a comment
There was a problem hiding this comment.
Verified the fix at HEAD (1414752).
What's logged & sensitivity: the tool-call arguments dict flows only into event_logger curated_payload["params"] (actions mcp_tool_call / mcp_response_size_exceeded) — the human-readable logger.info line at middleware.py:428 still logs only tool/ids/duration, never params. Both param sites route through _sanitize_params, which masks password/token/api_key/secret/credentials/authorization/cookie (case-insensitive, recursing into nested arguments). Non-sensitive args (SQL, dataset ids, search terms) are captured, which is this middleware's intended audit purpose and stays within the operator log-sink trust boundary. No new secret-in-logs class.
Correctness: the real MCP CallToolRequestParams exposes tool args as .arguments, not .params, so the old getattr(context.message, "params", {}) always resolved to {} — params, dashboard_id, slice_id and dataset_id all logged empty. Swapping to .arguments at both sites fixes this; or {} still guards the falsy/None case. Not double-logged, correct field.
Tests: the new regression test uses the real mt.CallToolRequestParams SDK type (a MagicMock auto-vivifies .params and hides the bug), pinning params == {"dashboard_id": 7} and dashboard_id == 7. Confirmed it fails when the 2-line prod change is reverted. The .params→.arguments churn in test_middleware.py is necessary mechanical alignment, not vacuous.
CI green (full run, all required checks pass; mergeable). No unresolved threads.
SUMMARY
LoggingMiddleware and ResponseSizeGuardMiddleware extracted tool call parameters via getattr(context.message, "params", {}). The real MCP SDK type for a tools/call request (mcp.types.CallToolRequestParams) has no params attribute — it exposes name and arguments — so the getattr fallback always silently returned {}. As a result, every MCP tool call log recorded params: {} and dashboard_id/slice_id/dataset_id as null, regardless of what the caller actually sent, making the audit logs useless for debugging or analytics.
Fixed both call sites to read context.message.arguments instead. Also updated the existing unit test mocks, which had been setting context.message.params on MagicMock objects — mirroring the same wrong attribute name as the bug, which is why the regression went undetected — and added a regression test that constructs a real mcp.types.CallToolRequestParams object to catch this class of attribute-name mismatch going forward.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before:
After:
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION