Skip to content

fix(mcp): preserve $defs in McpWorkbench.list_tools() for $ref resolution#7594

Open
octo-patch wants to merge 1 commit intomicrosoft:mainfrom
octo-patch:fix/mcp-workbench-defs-schema-support
Open

fix(mcp): preserve $defs in McpWorkbench.list_tools() for $ref resolution#7594
octo-patch wants to merge 1 commit intomicrosoft:mainfrom
octo-patch:fix/mcp-workbench-defs-schema-support

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #6663

Problem

When an MCP tool's inputSchema contains $defs for reusable type definitions,
McpWorkbench.list_tools() only extracted properties, required, and
additionalProperties into the ParametersSchema, silently dropping $defs.

This means any properties that reference types via $ref: "#/$defs/SomeName" are
forwarded to the model client with unresolvable references — the LLM sees e.g.
{"$ref": "#/$defs/Name"} but without the $defs dict it cannot know the actual
type. This is particularly common with MCP servers whose tools share enums or
sub-schemas across parameters.

Solution

Include $defs from inputSchema in the outgoing ParametersSchema dict when
present. OpenAI's FunctionParameters type is Dict[str, object], so it accepts
$defs and will forward them to the API where they can be used to resolve $ref
entries in the properties. Schemas without $defs are unaffected.

The change is a two-line addition in _workbench.py plus a matching test.

Changes

  • python/packages/autogen-ext/src/autogen_ext/tools/mcp/_workbench.py: preserve
    $defs when building ParametersSchema in list_tools()
  • python/packages/autogen-ext/tests/tools/test_mcp_workbench_overrides.py: add
    tests for schemas with and without $defs

Testing

  • Added test_mcp_workbench_list_tools_preserves_defs: verifies $defs is
    forwarded and $ref entries in properties are intact
  • Added test_mcp_workbench_list_tools_without_defs: verifies unchanged behavior
    for schemas that don't use $defs

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON Schema Types Using $ref in MCP workbench

1 participant