-
Notifications
You must be signed in to change notification settings - Fork 531
fix: model content annotations as nested objects #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: model content annotations as nested objects #242
Conversation
Updates all Content types to represent annotations as nested objects instead of directly on the content itself. The existing ctors have been moved to deprecated shim ctors for backwards-compat. This brings the implementation in line with the content types as modeled by the specification. An integration test has been added to ensure this doesn't drift in the future. https://github.com/modelcontextprotocol/modelcontextprotocol/blob/c87a0da6d8c2436d56a6398023c80b0562224454/schema/2025-03-26/schema.json#L1970-L1973
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @LucaButBoring ! An important alignment of the schema to comply with the spec!
I've left few recommendations to improve the formatting and the test coverage.
mcp/src/test/java/io/modelcontextprotocol/client/StdioMcpSyncClientTests.java
Outdated
Show resolved
Hide resolved
- Moves annotation test from stdio suite to abstract suite - Adds async version of sync annotation test - Fixes wildcard import
… into fix/content-annotations # Conflicts: # mcp-test/src/main/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientTests.java # mcp-test/src/main/java/io/modelcontextprotocol/client/AbstractMcpSyncClientTests.java # mcp/src/test/java/io/modelcontextprotocol/client/AbstractMcpAsyncClientTests.java # mcp/src/test/java/io/modelcontextprotocol/client/AbstractMcpSyncClientTests.java
Is it possible to rerun workflows? The failing test here appears to be unrelated to the modified code (and appears to be flaky, based on local runs):
|
Thanks for the update @LucaButBoring . Looks good. We discovered a correlation between the #CPUs and time to run the tests. GH Actions are likely running with fewer CPUs and the initialization timeout for the testListToolsWithoutInitialization exceeds 6 sec. |
Updates all Content types to represent annotations as nested objects instead of directly on the content itself. - Refactor TextContent, ImageContent, and EmbeddedResource to use Annotations object instead of separate audience/priority fields - Add backward-compatible deprecated methods for audience() and priority() accessors - Add parameterized tests for message annotations across different message types (success, error, debug) - Test both text and image content annotations with proper priority and audience validation This brings the implementation in line with the content types as modeled by the specification: https://github.com/modelcontextprotocol/modelcontextprotocol/blob/c87a0da6d8c2436d56a6398023c80b0562224454/schema/2025-03-26/schema.json#L1970-L1973
Rebased, squashed and merged at fb40047 |
Updates all Content types to represent annotations as nested objects instead of directly on the content itself. The existing ctors have been moved to deprecated shim ctors for backwards-compat.
This brings the implementation in line with the content types as modeled by the specification. An integration test has been added to ensure this doesn't drift in the future.
Motivation and Context
Content annotations have been incorrect for at least six months. The integration test added in this PR fails without the related schema changes.
How Has This Been Tested?
Newly-implemented integration test, leveraging the appropriate tool from everything.
Breaking Changes
None; the old constructor has been maintained for backwards-compatibility purposes. The old auto-generated record properties (
.audience()
and.priority()
) have also been maintained.Types of changes
Checklist
Additional context