aminghadersohi opened a new pull request, #38775:
URL: https://github.com/apache/superset/pull/38775
### SUMMARY
When the BM25/regex search transform's `call_tool` proxy forwards arguments
to the actual tool, dict/list values for parameters declared as `str |
SomeModel` (anyOf/oneOf with a string variant) cause `TypeError: encoding
without a string argument` because the MCP transport calls `bytes(dict,
'utf-8')`.
This adds `_normalize_call_tool_arguments()` which JSON-serializes dict/list
values when the target tool's schema accepts both string and object types. The
custom `_make_call_tool` override now looks up the target tool's schema before
forwarding, preventing the encoding error.
### BEFORE/AFTER SCREENSHOTS OR COVERAGE AREA
**Before**: When an LLM sends `call_tool(name="save_sql_query",
arguments={"request": {"database_id": 1, ...}})` through the BM25 search
transform, the dict value for `request` is forwarded as-is. Since the
underlying tool declares `request: str | SaveSQLQueryRequest`, the MCP
transport attempts `bytes(dict, 'utf-8')` and fails.
**After**: The `call_tool` proxy looks up the target tool's schema, detects
that `request` has `anyOf: [{type: string}, {$ref: ...}]`, and JSON-serializes
the dict to a string before forwarding. The tool's `@parse_request` decorator
then deserializes it back.
### TESTING INSTRUCTIONS
- 16 unit tests in
`tests/unit_tests/mcp_service/test_tool_search_transform.py`
- 8 new tests for `_normalize_call_tool_arguments`:
- Dict with anyOf string → serialized
- Dict with oneOf string → serialized
- Dict without string variant → left as dict
- Non-dict values → unchanged
- None arguments → None
- Non-dict schema → unchanged
- List with anyOf string → serialized
- Unknown keys → unchanged
### ADDITIONAL INFORMATION
- Requires FastMCP >= 3.1.0 (`_make_call_tool` is a private API)
- Related to the BM25 tool search transform that reduces initial context by
~70%
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]