fix(mcp): preserve $defs in McpWorkbench.list_tools() for $ref resolution#7594
Open
octo-patch wants to merge 1 commit intomicrosoft:mainfrom
Open
fix(mcp): preserve $defs in McpWorkbench.list_tools() for $ref resolution#7594octo-patch wants to merge 1 commit intomicrosoft:mainfrom
octo-patch wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…lution When an MCP tool's inputSchema contains \$defs for reusable type definitions, the previous ParametersSchema construction only extracted properties and required fields, silently dropping \$defs. This left any \$ref entries in properties unresolvable when the schema was forwarded to the model client, causing the LLM to receive an incomplete function schema. Fix: include \$defs from inputSchema in the parameters schema dict when present, so model clients can resolve \$ref entries correctly. Schemas without \$defs are unaffected. Fixes microsoft#6663
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.
Fixes #6663
Problem
When an MCP tool's
inputSchemacontains$defsfor reusable type definitions,McpWorkbench.list_tools()only extractedproperties,required, andadditionalPropertiesinto theParametersSchema, silently dropping$defs.This means any properties that reference types via
$ref: "#/$defs/SomeName"areforwarded to the model client with unresolvable references — the LLM sees e.g.
{"$ref": "#/$defs/Name"}but without the$defsdict it cannot know the actualtype. This is particularly common with MCP servers whose tools share enums or
sub-schemas across parameters.
Solution
Include
$defsfrominputSchemain the outgoingParametersSchemadict whenpresent. OpenAI's
FunctionParameterstype isDict[str, object], so it accepts$defsand will forward them to the API where they can be used to resolve$refentries in the properties. Schemas without
$defsare unaffected.The change is a two-line addition in
_workbench.pyplus a matching test.Changes
python/packages/autogen-ext/src/autogen_ext/tools/mcp/_workbench.py: preserve$defswhen buildingParametersSchemainlist_tools()python/packages/autogen-ext/tests/tools/test_mcp_workbench_overrides.py: addtests for schemas with and without
$defsTesting
test_mcp_workbench_list_tools_preserves_defs: verifies$defsisforwarded and
$refentries in properties are intacttest_mcp_workbench_list_tools_without_defs: verifies unchanged behaviorfor schemas that don't use
$defs