Fix MCPToolWrapper._create_signature for schemas with optional-before-required properties#383
Open
OICWS wants to merge 2 commits into
Open
Fix MCPToolWrapper._create_signature for schemas with optional-before-required properties#383OICWS wants to merge 2 commits into
OICWS wants to merge 2 commits 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.
MCPToolWrapper._create_signature raises ValueError for tool schemas with an optional property listed before a required one
Summary
MCPToolWrapper._create_signature(inaisuite/mcp/tool_wrapper.py) buildsthe wrapper's
inspect.Signatureby iterating the tool's JSON Schemaproperties in their original declaration order, placing each as a
required (no-default) or optional (
default=None)inspect.Parameterdepending on whether it's in the schema's
requiredlist — but withoutfirst sorting required parameters ahead of optional ones.
Python's
inspect.Signature/defsyntax requires every non-defaultparameter to precede any default parameter. JSON Schema has no such
ordering constraint —
requiredis just a list, independent ofpropertiesorder — so any tool whose schema lists an optional propertybefore a required one causes construction to fail:
This is not a rare edge case. It's the pattern used by most interaction
tools in the official
@playwright/mcpserver (an optionalhuman-readable
elementdescription listed before the requiredtargetelement reference), including
browser_click,browser_type,browser_hover,browser_drag,browser_take_screenshot,browser_evaluate, andbrowser_select_option.Impact
MCPClient.get_callable_tools()callscreate_mcp_tool_wrapperfor everytool the server reports; when this raises, the calling code (e.g. a
try/except around tool discovery) can end up silently skipping the tool
or the whole server, with no indication to the end user that the failure
is a library bug rather than a misconfigured server. In our case (a
downstream project extending aisuite), connecting to a real
@playwright/mcpserver viaMCPClient.get_callable_tools()returnedzero tools — every one of the schema-order-affected tools failed to
construct.
Minimal repro
Suggested fix
Sort parameters so required ones come first (stable otherwise) before
constructing the
inspect.Signature, e.g. in_create_signature:This only changes construction order, not semantics -- MCP tool calls are
always made with keyword arguments, so parameter position doesn't affect
callers.
Environment
@playwright/mcp@latestserver (npm),version 0.0.78 at time of testing