Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions mcp/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ type Tool struct {
InputSchema ToolInputSchema `json:"inputSchema"`
// Alternative to InputSchema - allows arbitrary JSON Schema to be provided
RawInputSchema json.RawMessage `json:"-"` // Hide this from JSON marshaling
// Optional properties describing tool behavior
Annotations ToolAnnotation `json:"annotations"`
}

// MarshalJSON implements the json.Marshaler interface for Tool.
Expand Down Expand Up @@ -109,6 +111,19 @@ type ToolInputSchema struct {
Required []string `json:"required,omitempty"`
}

type ToolAnnotation struct {
// Human-readable title for the tool
Title string `json:"title,omitempty"`
// If true, the tool does not modify its environment
ReadOnlyHint bool `json:"readOnlyHint,omitempty"`
// If true, the tool may perform destructive updates
DestructiveHint bool `json:"destructiveHint,omitempty"`
// If true, repeated calls with same args have no additional effect
IdempotentHint bool `json:"idempotentHint,omitempty"`
// If true, tool interacts with external entities
OpenWorldHint bool `json:"openWorldHint,omitempty"`
}

// ToolOption is a function that configures a Tool.
// It provides a flexible way to set various properties of a Tool using the functional options pattern.
type ToolOption func(*Tool)
Expand All @@ -132,6 +147,13 @@ func NewTool(name string, opts ...ToolOption) Tool {
Properties: make(map[string]interface{}),
Required: nil, // Will be omitted from JSON if empty
},
Annotations: ToolAnnotation{
Title: "",
ReadOnlyHint: false,
DestructiveHint: true,
IdempotentHint: false,
OpenWorldHint: true,
},
}

for _, opt := range opts {
Expand Down Expand Up @@ -166,6 +188,12 @@ func WithDescription(description string) ToolOption {
}
}

func WithToolAnnotation(annotation ToolAnnotation) ToolOption {
return func(t *Tool) {
t.Annotations = annotation
}
}

//
// Common Property Options
//
Expand Down
7 changes: 7 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,13 @@ func TestMCPServer_HandleUndefinedHandlers(t *testing.T) {
Type: "object",
Properties: map[string]interface{}{},
},
Annotations: mcp.ToolAnnotation{
Title: "test-tool",
ReadOnlyHint: true,
DestructiveHint: false,
IdempotentHint: false,
OpenWorldHint: false,
},
}, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
return &mcp.CallToolResult{}, nil
})
Expand Down