fix(mcp): preserve $defs and definitions fields in JsonSchema conversion #903
Open
JGoP-L wants to merge 1 commit intoagentscope-ai:mainfrom
Open
fix(mcp): preserve $defs and definitions fields in JsonSchema conversion #903JGoP-L wants to merge 1 commit intoagentscope-ai:mainfrom
JGoP-L wants to merge 1 commit intoagentscope-ai:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes MCP tool JSON Schema conversion so that referenced type definitions are not lost when converting McpSchema.JsonSchema into AgentScope tool parameters, preventing $ref resolution failures (Issue #893).
Changes:
- Preserve top-level
$defs(JSON Schema 2020-12) duringMcpSchema.JsonSchema→ parameters conversion. - Preserve legacy
definitions(pre-2020-12) during conversion. - Add unit tests covering
$defs,definitions, and both simultaneously.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
agentscope-core/src/main/java/io/agentscope/core/tool/mcp/McpTool.java |
Copies defs() → $defs and definitions() → definitions into the produced parameters schema map to keep $ref targets available. |
agentscope-core/src/test/java/io/agentscope/core/tool/mcp/McpToolTest.java |
Adds test cases validating $defs and/or definitions are retained in the converted schema. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
261e851 to
4ce9a8c
Compare
When converting MCP JsonSchema to AgentScope parameters, the $defs and definitions fields were not being preserved. This caused $ref references to break since the referenced type definitions were lost during conversion. Fixes agentscope-ai#893 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4ce9a8c to
8f6ca95
Compare
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.
AgentScope-Java Version
1.0.10-SNAPSHOT
Description
Background
When MCP (Model Context Protocol) tools return JSON Schema with $ref references, the referenced type
definitions are stored in $defs (JSON Schema 2020-12) or definitions (legacy JSON Schema) fields.
These definitions are essential for resolving $ref references.
Problem
The McpTool.convertMcpSchemaToParameters() method was only copying type, properties, required, and
additionalProperties fields from the MCP JsonSchema. The $defs and definitions fields were being
dropped during conversion, causing $ref references to become invalid.
Solution
Added logic to preserve $defs and definitions fields when converting MCP schema to AgentScope
parameters:
// Preserve $defs and definitions for $ref resolution
if (inputSchema.defs() != null && !inputSchema.defs().isEmpty()) {
parameters.put("$defs", new HashMap<>(inputSchema.defs()));
}
if (inputSchema.definitions() != null && !inputSchema.definitions().isEmpty()) {
parameters.put("definitions", new HashMap<>(inputSchema.definitions()));
}
Changes
How to Test
mvn test -pl agentscope-core -Dtest=McpToolTest
Fixes #893
Checklist