fix(tools): fall back to string for unsupported MCP parameter types#38788
Open
AnnaSuSu wants to merge 1 commit into
Open
fix(tools): fall back to string for unsupported MCP parameter types#38788AnnaSuSu wants to merge 1 commit into
AnnaSuSu wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
Fixes #<issue number>.Summary
No issue (self-reported crash found by reading the MCP tool-conversion path).
Loading or invoking an MCP tool provider crashes with an unhandled
ValueErrorwhen aremote MCP server declares a parameter whose JSON-schema
typeis not one of the supportedparameter types.
A tool's
inputSchemais supplied verbatim by a third-party MCP server and persisted as-is(only
descriptionis normalized before storage inMCPToolManageService). When that schemauses a non-standard type name — e.g.
"text", a capitalized"String", or a["bogus", "null"]list —
convert_mcp_schema_to_parameterpasses it straight intoToolParameter.ToolParameterType(prop_type), which raises:This propagates out of
MCPToolProviderController.from_entity/from_db, which sits on everyprovider-load path — listing the provider's tools, updating its credentials
(
update_provider_credentials), and invoking a tool viaToolManager.get_mcp_provider_controller. A single malformed tool therefore makes the wholeprovider unusable, and because the bad schema is already stored, the crash repeats on every
subsequent load.
resolve_property_type(added in #33258) was designed to always resolve to a usable type,falling back to
"string"for cyclic schemas, over-depth unions,null, and empty type lists.The two branches that echo the schema's raw
type(case str()and the first non-null entry ofcase list()) are the only ones that don't validate their result against the supported set, soan unsupported name slips through to the enum constructor.
The fix extends that same fallback to the one case it missed: after alias mapping
(
integer/float→number), a type outsideToolParameterTypefalls back to"string",mirroring how every other unresolved type is already handled. Standard types are unaffected —
integerstill resolves tonumber,object/arrayare preserved.Adds a regression test that is red on an unmodified checkout (with the
ValueErrorabove) andgreen with this fix, and confirms the existing
null/anyOf/oneOf/allOf/ depth-limitcases still pass.
Screenshots
N/A — backend-only change.
Checklist
make lint && make type-check(backend) andcd web && pnpm exec vp staged(frontend) to appease the lint godsFrom Claude Code