Skip to content

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

Conversation

LucaButBoring
Copy link
Contributor

@LucaButBoring LucaButBoring commented May 16, 2025

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

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
@LucaButBoring LucaButBoring mentioned this pull request May 16, 2025
9 tasks
Copy link
Contributor

@tzolov tzolov left a 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.

@tzolov tzolov self-assigned this Jun 15, 2025
@tzolov tzolov added this to the 0.11.0 milestone Jun 15, 2025
@tzolov tzolov added waiting for user Waiting for user feedback or more details labels Jun 16, 2025
- 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
@LucaButBoring
Copy link
Contributor Author

LucaButBoring commented Jun 16, 2025

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):

StdioMcpAsyncClientTests.testListToolsWithoutInitialization expectation "expectNextCount(1)" failed (expected: count = 1; actual: counted = 0; signal: onError(io.modelcontextprotocol.spec.McpError: Client failed to initialize listing tools))

@tzolov
Copy link
Contributor

tzolov commented Jun 17, 2025

Thanks for the update @LucaButBoring . Looks good.
The StdioMcpAsyncClientTests.testListToolsWithoutInitialization fails because of test InitializationTimeout timeout. I will bump it from 6 to 10 sec.

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.

tzolov pushed a commit that referenced this pull request Jun 17, 2025
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
@tzolov
Copy link
Contributor

tzolov commented Jun 17, 2025

Rebased, squashed and merged at fb40047

@tzolov tzolov closed this Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MCP Schema waiting for user Waiting for user feedback or more details
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants