Add Annotation Support on Resources #111
Merged
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.
This PR adds support for resource annotations as defined in the MCP Specs.
Usage
Three annotation types are now available for use with Resource classes.
1. Audience.
Accepted values:
Role::USER,Role::ASSISTANT, or an array of both.2. Priority.
A numerical score between 0.0 and 1.0 indicating resource importance.
Validation. Throws
InvalidArgumentExceptionif value is outside the 0.0 to 1.0 range.3. LastModified
An ISO 8601 timestamp showing when the resource was last updated.
Accepted formats:
2025-01-12T15:00:58Z2025-01-12T15:00:58+00:00Validation. Throws
InvalidArgumentExceptionif the timestamp format is invalid.Combining Multiple Annotations
All three annotations can be combined on a single resource.
How It Works
Annotations are automatically included in resource listings via the
resources/listmethod.{ "uri": "file://resources/user-dashboard", "name": "UserDashboard", "description": "User-facing dashboard data", "mimeType": "text/plain", "annotations": { "audience": ["user"], "priority": 0.9, "lastModified": "2025-01-12T15:00:58Z" } }If no annotations are present, the
annotationsfield is omitted entirely from the response.Important
This implementation throw error if Invalid Annotations are added on the
Tool::classorResource::class