fix(mcp): simplify tool schemas in BM25 search results to prevent LLM argument misformatting#38914
fix(mcp): simplify tool schemas in BM25 search results to prevent LLM argument misformatting#38914kgabryje wants to merge 2 commits intoapache:masterfrom
Conversation
… argument misformatting
Code Review Agent Run #caa3c4Actionable 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 |
Sequence DiagramThis PR updates the MCP server's BM25 tool search flow so that, before returning search results, it simplifies each tool's input schema by resolving references and collapsing unions, making it easier for the LLM to construct correctly wrapped call_tool arguments. sequenceDiagram
participant LLM
participant MCPServer
participant SchemaSimplifier
LLM->>MCPServer: search_tools query
MCPServer->>MCPServer: rank tools with BM25 search
MCPServer->>SchemaSimplifier: simplify tool input schemas
SchemaSimplifier-->>MCPServer: flat schemas without refs or string unions
MCPServer-->>LLM: search_tools results with simplified schemas
LLM->>MCPServer: call_tool with correctly wrapped request
Generated by CodeAnt AI |
Codecov Report❌ Patch coverage is
❌ Your project check has failed because the head coverage (99.85%) is below the target coverage (100.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #38914 +/- ##
==========================================
- Coverage 65.80% 64.54% -1.26%
==========================================
Files 1823 2536 +713
Lines 73181 130825 +57644
Branches 23448 30339 +6891
==========================================
+ Hits 48156 84440 +36284
- Misses 25025 44916 +19891
- Partials 0 1469 +1469
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:
|
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review Agent Run #863ae9Actionable 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
When the BM25 tool search transform is enabled, the LLM discovers tools via search_tools and invokes them through a call_tool proxy. The tool schemas returned in search results contain raw Pydantic-generated JSON Schema with $ref pointers and anyOf[string, Object] unions (from the @parse_request decorator's str | Model annotation). The LLM reads these schemas as text and must reconstruct the argument structure when calling call_tool — but the indirection of $ref lookups and ambiguity of anyOf unions causes it to sometimes omit the required request wrapper, passing inner properties directly (e.g. {"config": ...} instead of {"request": {"config": ...}}).
This PR adds a schema simplification step in _serialize_tools_without_output_schema that:
its inner properties immediately visible. Field-level metadata (description, default) is preserved
during the collapse.
pattern). All other unions are kept intact.
Before (what the LLM saw):
{"properties": {"request": {"anyOf": [{"type": "string"}, {"$ref": "#/$defs/ListChartsRequest"}]}},
"$defs": {"ListChartsRequest": {"properties": {"filters": {"items": {"$ref": "#/$defs/ChartFilter"}},
...}}, "ChartFilter": {...}}}
After:
{"properties": {"request": {"type": "object", "properties": {"filters": {"type": "array", "items":
{"type": "object", "properties": {"col": ..., "opr": ..., "value": ...}}}, "page": {"type": "integer",
"default": 1}}}}, "required": ["request"]}
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
Unit tests should pass
ADDITIONAL INFORMATION
CodeAnt-AI Description
Make MCP tool search results easier to follow and use
What Changed
Impact
✅ Fewer malformed tool calls✅ Clearer request shapes in search results✅ Less trial and error when invoking MCP tools💡 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.