fix(mcp): remove @parse_request decorator for cleaner tool schemas#38918
Conversation
The @parse_request decorator was a workaround for a Claude Code double-serialization bug (GitHub issue apache#5504) that wrapped tool parameters in a confusing anyOf [string, object] schema under a "request" key. This caused two problems reported by users: 1. LLMs frequently forgot the "request" wrapper, sending flat params like {"chart_id": 62} instead of {"request": {"identifier": 62}} 2. LLMs used wrong parameter names (e.g. "title" vs "dashboard_title") because the schema was unclear With FastMCP 3.1, Tool.from_function handles Pydantic BaseModel parameters natively, making @parse_request unnecessary. Changes: - Remove @parse_request decorator and import from all 19 tool files - Add Context injection in mcp_auth_hook (previously done by @parse_request) via _needs_ctx detection and _inject_ctx helper - Add default value for get_instance_info's empty request model - Remove from __future__ import annotations from execute_sql and save_sql_query (string annotations prevent FastMCP from recognizing the Context parameter, causing tool registration failures)
Code Review Agent Run #d3c6b4Actionable Suggestions - 0Additional Suggestions - 5
Filtered by Review RulesBito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
Review 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 #38918 +/- ##
==========================================
- Coverage 65.81% 64.51% -1.31%
==========================================
Files 1823 2536 +713
Lines 73196 130755 +57559
Branches 23460 30338 +6878
==========================================
+ Hits 48175 84353 +36178
- Misses 25021 44939 +19918
- Partials 0 1463 +1463
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Ruff B008 disallows function calls in argument defaults. Move the GetSupersetInstanceInfoRequest() default to a module-level singleton.
- Pass mock_ctx explicitly in save_sql_query tests since ctx is now a regular parameter (not injected by @parse_request) - Remove test_get_schema_with_json_string_request test that was testing @parse_request JSON string handling (no longer exists)
Code Review Agent Run #881fe2Actionable 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 |
User description
SUMMARY
The
@parse_requestdecorator was originally added as a workaround for a Claude Code double-serialization bug (fastmcp#5504) that wrapped tool parameters in a confusinganyOf [string, object]schema under arequestkey. This caused two problems reported by users:requestwrapper, sending flat params like{"chart_id": 62}instead of{"request": {"identifier": 62}}, causing validation errors before self-correctingtitlevsdashboard_title) because theanyOfschema was unclear to modelsWith FastMCP 3.1,
Tool.from_functionhandles PydanticBaseModelparameters natively, generating clean JSON schemas. This makes@parse_requestunnecessary.Changes:
@parse_requestdecorator and its import from all 19 tool filesContextinjection inmcp_auth_hook(previously handled by@parse_request) via_needs_ctxdetection and_inject_ctxhelperget_instance_info's empty request model (previously handled by@parse_request)from __future__ import annotationsfromexecute_sqlandsave_sql_query(string annotations prevent FastMCP from recognizing theContextparameter, causing silent tool registration failures)Schema improvement (before → after):
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A - Backend-only change affecting MCP tool JSON schemas.
TESTING INSTRUCTIONS
python -m superset.mcp_service.server)get_instance_info(no args needed)list_chartswith{"request": {"page": 1, "page_size": 5}}execute_sqlwith{"request": {"database_id": 1, "sql": "SELECT 1"}}save_sql_querywith{"request": {"database_id": 1, "label": "Test", "sql": "SELECT 1"}}anyOf [string, object]patternsADDITIONAL INFORMATION
CodeAnt-AI Description
Make MCP tool inputs simpler and more reliable
What Changed
requestwrapper, which reduces validation errors from LLM clientsImpact
✅ Fewer tool input validation errors✅ Cleaner MCP tool schemas for LLM clients✅ Fewer missing-tool failures in SQL Lab actions💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.