Repository navigation
Python: Keep $defs at the root of wrapped MCP workflow tool schemas - #10367
Open
ni (nniiovoo) wants to merge 1 commit into
Open
ni (nniiovoo) wants to merge 1 commit into
ni (nniiovoo) wants to merge 1 commit into
Conversation
Signed-off-by: NNIIOVO <haimingni44@gmail.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the fix for JSON Schema references in wrapped workflow inputs.
No open issues 🎉
What changed in this PR
Fixes #10366 by keeping JSON Schema references resolvable when WorkflowMCPTool wraps non-object workflow inputs.
Changes:
- Moves
$defsto the wrapper root so#/$defs/...references resolve. - Preserves nested definitions when the input schema has its own resource-defining
$id. - Adds regression tests for schema validation, tool execution, and preservation of schemas with their own
$id.
| File | Description |
|---|---|
python/packages/hosting-mcp/tests/hosting_mcp/test_workflow_tool.py |
Adds wrapped-input regression tests with and without a schema $id. |
python/packages/hosting-mcp/agent_framework_hosting_mcp/_workflow_tool.py |
Relocates $defs when wrapping inputs while preserving separate schema resources. |
Review effort: Balanced
2 tasks done
Nick (surlymochan)
left a comment
There was a problem hiding this comment.
Non-binding review (read the diff; not an approval).
What I verified:
- The logic is sound: when a non-object input schema is wrapped, its
$defsare hoisted to the new root, where the schema's#/$defs/...references point. When the schema carries its own$id(a separate resource), the$defsstay nested with it, so its references still resolve inside it. - The two new tests pin both branches: the wrapped
list[WorkflowInput]case validates withjsonschemaand executes end-to-end, and the$idcase asserts$defsstays underproperties.values.
Two questions:
- The code treats
$idvalues of""and"#"as "same document, hoist", but the tests only cover an absolute-URL$id. Is the"#"branch covered anywhere? A test for it would pin the allowlist. input_schema.pop("$defs", None)mutates the dict returned byinput_adapter.json_schema(). Is that dict freshly built on every call, so the pop cannot leak into a cached/shared schema on a secondlist_tools()call?
This branch was successfully deployed
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.
Motivation & Context
When
WorkflowMCPToolwraps a non-object start input (likelist[Item]) underproperties.<argument_name>, the schema's$defsstayed inside the property while its#/$defs/...references point at the root. So the advertisedinputSchemahad references that don't resolve. Repro is in #10366.Description & Review Guide
_tool_for_workflowmoves$defsfrom the wrapped schema to the root of the wrapper. If the wrapped schema has its own$id, it is a separate schema resource whose references already resolve inside it, so it is left as is.inputSchemafor wrapped inputs that use models (list[Model],Model | None, unions, recursive models), the#/$defs/...references now resolve. Object inputs and wrapped inputs without$defsare unchanged, and argument validation still goes through pydantic as before.$idcheck. Pydantic only puts a$idthere when the model sets one (e.g. throughjson_schema_extra), but moving$defsout of such a schema would break references that resolve today.Tests: I added a test with a
list[dataclass]input that validates arguments against the advertised schema withjsonschema(it fails on main), and one for a wrapped schema with its own$id.Related Issue
Fixes #10366
AI Assistance
AI assistance details: issue analysis, implementation, tests, and this description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.