Skip to content

Commit e381bb1

Browse files
committed
fix: use helper functions
1 parent c6354a3 commit e381bb1

File tree

3 files changed

+52
-25
lines changed

3 files changed

+52
-25
lines changed

client/inprocess_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ func TestInProcessMCPClient(t *testing.T) {
2222
"test-tool",
2323
mcp.WithDescription("Test tool"),
2424
mcp.WithString("parameter-1", mcp.Description("A string tool parameter")),
25-
mcp.WithToolAnnotation(
26-
"Test Tool Annotation Title",
27-
true,
28-
false,
29-
true,
30-
false,
31-
),
25+
mcp.WithTitleAnnotation("Test Tool Annotation Title"),
26+
mcp.WithReadOnlyHintAnnotation(true),
27+
mcp.WithDestructiveHintAnnotation(false),
28+
mcp.WithIdempotentHintAnnotation(true),
29+
mcp.WithOpenWorldHintAnnotation(false),
3230
), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
3331
return &mcp.CallToolResult{
3432
Content: []mcp.Content{

client/sse_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ func TestSSEMCPClient(t *testing.T) {
2626
"test-tool",
2727
mcp.WithDescription("Test tool"),
2828
mcp.WithString("parameter-1", mcp.Description("A string tool parameter")),
29-
mcp.WithToolAnnotation(
30-
"Test Tool Annotation Title",
31-
true,
32-
false,
33-
true,
34-
false,
35-
),
29+
mcp.WithTitleAnnotation("Test Tool Annotation Title"),
30+
mcp.WithReadOnlyHintAnnotation(true),
31+
mcp.WithDestructiveHintAnnotation(false),
32+
mcp.WithIdempotentHintAnnotation(true),
33+
mcp.WithOpenWorldHintAnnotation(false),
3634
), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
3735
return &mcp.CallToolResult{
3836
Content: []mcp.Content{

mcp/tools.go

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,49 @@ func WithDescription(description string) ToolOption {
208208
}
209209

210210
// WithToolAnnotation adds optional hints about the Tool.
211-
func WithToolAnnotation(
212-
title string,
213-
readOnlyHint, destructiveHint, idempotentHint, openWorldHint bool,
214-
) ToolOption {
211+
func WithToolAnnotation(annotation ToolAnnotation) ToolOption {
215212
return func(t *Tool) {
216-
t.Annotations = ToolAnnotation{
217-
Title: title,
218-
ReadOnlyHint: &readOnlyHint,
219-
DestructiveHint: &destructiveHint,
220-
IdempotentHint: &idempotentHint,
221-
OpenWorldHint: &openWorldHint,
222-
}
213+
t.Annotations = annotation
214+
}
215+
}
216+
217+
// WithTitleAnnotation sets the Title field of the Tool's Annotations.
218+
// It provides a human-readable title for the tool.
219+
func WithTitleAnnotation(title string) ToolOption {
220+
return func(t *Tool) {
221+
t.Annotations.Title = title
222+
}
223+
}
224+
225+
// WithReadOnlyHintAnnotation sets the ReadOnlyHint field of the Tool's Annotations.
226+
// If true, it indicates the tool does not modify its environment.
227+
func WithReadOnlyHintAnnotation(value bool) ToolOption {
228+
return func(t *Tool) {
229+
t.Annotations.ReadOnlyHint = &value
230+
}
231+
}
232+
233+
// WithDestructiveHintAnnotation sets the DestructiveHint field of the Tool's Annotations.
234+
// If true, it indicates the tool may perform destructive updates.
235+
func WithDestructiveHintAnnotation(value bool) ToolOption {
236+
return func(t *Tool) {
237+
t.Annotations.DestructiveHint = &value
238+
}
239+
}
240+
241+
// WithIdempotentHintAnnotation sets the IdempotentHint field of the Tool's Annotations.
242+
// If true, it indicates repeated calls with the same arguments have no additional effect.
243+
func WithIdempotentHintAnnotation(value bool) ToolOption {
244+
return func(t *Tool) {
245+
t.Annotations.IdempotentHint = &value
246+
}
247+
}
248+
249+
// WithOpenWorldHintAnnotation sets the OpenWorldHint field of the Tool's Annotations.
250+
// If true, it indicates the tool interacts with external entities.
251+
func WithOpenWorldHintAnnotation(value bool) ToolOption {
252+
return func(t *Tool) {
253+
t.Annotations.OpenWorldHint = &value
223254
}
224255
}
225256

0 commit comments

Comments
 (0)