Skip to content

Commit 71b910b

Browse files
authored
fix: tool annotation (#165)
1 parent 37ac814 commit 71b910b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

client/sse_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ func TestSSEMCPClient(t *testing.T) {
2525
"test-tool",
2626
mcp.WithDescription("Test tool"),
2727
mcp.WithString("parameter-1", mcp.Description("A string tool parameter")),
28+
mcp.WithToolAnnotation(mcp.ToolAnnotation{
29+
Title: "Test Tool Annotation Title",
30+
ReadOnlyHint: true,
31+
DestructiveHint: false,
32+
IdempotentHint: true,
33+
OpenWorldHint: false,
34+
}),
2835
), func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
2936
return &mcp.CallToolResult{
3037
Content: []mcp.Content{
@@ -95,10 +102,21 @@ func TestSSEMCPClient(t *testing.T) {
95102

96103
// Test ListTools
97104
toolsRequest := mcp.ListToolsRequest{}
98-
_, err = client.ListTools(ctx, toolsRequest)
105+
toolListResult, err := client.ListTools(ctx, toolsRequest)
99106
if err != nil {
100107
t.Errorf("ListTools failed: %v", err)
101108
}
109+
if toolListResult == nil || len((*toolListResult).Tools) == 0 {
110+
t.Errorf("Expected one tool")
111+
}
112+
testToolAnnotations := (*toolListResult).Tools[0].Annotations
113+
if testToolAnnotations.Title != "Test Tool Annotation Title" ||
114+
testToolAnnotations.ReadOnlyHint != true ||
115+
testToolAnnotations.DestructiveHint != false ||
116+
testToolAnnotations.IdempotentHint != true ||
117+
testToolAnnotations.OpenWorldHint != false {
118+
t.Errorf("The annotations of the tools are invalid")
119+
}
102120
})
103121

104122
// t.Run("Can handle notifications", func(t *testing.T) {

mcp/tools.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ func (t Tool) MarshalJSON() ([]byte, error) {
102102
m["inputSchema"] = t.InputSchema
103103
}
104104

105+
m["annotations"] = t.Annotations
106+
105107
return json.Marshal(m)
106108
}
107109

0 commit comments

Comments
 (0)