feat: Add tool annotations support via runtime options#35
Open
bryankthompson wants to merge 1 commit into
Open
feat: Add tool annotations support via runtime options#35bryankthompson wants to merge 1 commit into
bryankthompson wants to merge 1 commit into
Conversation
Add support for MCP tool annotations (readOnlyHint, destructiveHint,
idempotentHint, openWorldHint, title) through a runtime options pattern
consistent with the existing WithExtraProperties() approach.
This enables users to specify annotation hints at tool registration time:
```go
tool := runtime.ApplyToolAnnotations(
generatedTool,
runtime.WithToolAnnotations(runtime.ToolAnnotationConfig{
Title: "Get Item",
ReadOnlyHint: boolPtr(true),
}),
)
```
Changes:
- Add WithToolAnnotations() runtime option
- Add ApplyToolAnnotations() helper function
- Add ApplyOptions() for combined annotations and extra properties
- Add comprehensive unit tests (9 test cases)
- Add examples/with-annotations demonstrating usage
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.
Summary
This PR adds support for MCP tool annotations through a runtime options pattern, allowing users to add semantic hints to generated tools. This follows the existing
WithExtraProperties()pattern and enables LLMs and MCP clients to better understand tool behavior.Key changes:
WithToolAnnotations()- New runtime option for specifying annotationsApplyToolAnnotations()- Helper function to apply annotations to a toolApplyOptions()- Combined function for both annotations and extra propertiesUsage Example
Annotation Types Supported
TitleReadOnlyHintDestructiveHintIdempotentHintOpenWorldHintTest Plan
go test ./pkg/runtime/...)go build ./examples/with-annotations/...)go vetpassesRelated
This implements support for the MCP tool annotations specification. The SDK (mcp-go v0.37.0) already supports
mcp.ToolAnnotation- this PR makes it easy for users to apply annotations to generated tools.🤖 Generated with Claude Code