-
Notifications
You must be signed in to change notification settings - Fork 679
new feat: tool annotation #158
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
WalkthroughThe changes introduce a new Changes
Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🔭 Outside diff range comments (2)
mcp/tools.go (2)
105-106
:⚠️ Potential issueMissing annotations field in MarshalJSON.
The
MarshalJSON
method currently doesn't include the newAnnotations
field when serializing a Tool to JSON. This could lead to the annotations being lost during serialization.Add the annotations field to the marshaled output:
func (t Tool) MarshalJSON() ([]byte, error) { // Create a map to build the JSON structure m := make(map[string]interface{}, 3) // Add the name and description m["name"] = t.Name if t.Description != "" { m["description"] = t.Description } // Determine which schema to use if t.RawInputSchema != nil { if t.InputSchema.Type != "" { return nil, fmt.Errorf("tool %s has both InputSchema and RawInputSchema set: %w", t.Name, errToolSchemaConflict) } m["inputSchema"] = t.RawInputSchema } else { // Use the structured InputSchema m["inputSchema"] = t.InputSchema } + // Add annotations if they have any non-default values + if t.Annotations.Title != "" || t.Annotations.ReadOnlyHint || !t.Annotations.DestructiveHint || + t.Annotations.IdempotentHint || !t.Annotations.OpenWorldHint { + m["annotations"] = t.Annotations + } return json.Marshal(m) }
174-180
:⚠️ Potential issueMissing annotations initialization in NewToolWithRawSchema.
The
NewToolWithRawSchema
function doesn't initialize theAnnotations
field with default values likeNewTool
does, which could lead to inconsistent behavior.Add the default annotations:
func NewToolWithRawSchema(name, description string, schema json.RawMessage) Tool { tool := Tool{ Name: name, Description: description, RawInputSchema: schema, + Annotations: ToolAnnotation{ + Title: "", + ReadOnlyHint: false, + DestructiveHint: true, + IdempotentHint: false, + OpenWorldHint: true, + }, } return tool }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
mcp/tools.go
(4 hunks)server/server_test.go
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
server/server_test.go (1)
mcp/tools.go (2)
ToolAnnotation
(114-125)Title
(217-221)
🔇 Additional comments (4)
mcp/tools.go (3)
76-77
: New field for tool behavior metadata.The addition of the
Annotations
field to theTool
struct provides a structured way to describe tool behavior characteristics, enhancing API clients' understanding of tool usage and side effects.
114-125
: Well-structured tool annotation type.The
ToolAnnotation
struct provides a robust set of behavioral hints that follow industry best practices for describing tool properties:
ReadOnlyHint
- Safety indicator for tools that don't modify stateDestructiveHint
- Warning flag for potentially dangerous operationsIdempotentHint
- Important for retry behaviorOpenWorldHint
- Indicates external system interactionThe use of
omitempty
for JSON tags is appropriate for these optional metadata fields.
150-156
: Conservative default annotation values.The default values for tool annotations take a security-first approach by assuming tools are potentially destructive (
DestructiveHint: true
) and interact with external systems (OpenWorldHint: true
) by default.server/server_test.go (1)
803-809
: Test correctly uses the new tool annotations feature.The test case has been properly updated to set the
Annotations
field on the test tool. The values configure it as a read-only tool that doesn't perform destructive operations or interact with external systems.
82e3b7e
to
12df8ba
Compare
12df8ba
to
67a5a26
Compare
Hi @dugenkui03 @ezynda3 quick feedback. For me annotations aren't properly marshaled. I don't see them on the go client. |
@StarpTech this will be fixed in #165 |
demo
Summary by CodeRabbit