Skip to content

Commit 470edfd

Browse files
committed
add test
1 parent 4df0706 commit 470edfd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

mcp/mcp_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,25 @@ func TestEndToEnd(t *testing.T) {
257257
t.Errorf("tools/call 'fail' mismatch (-want +got):\n%s", diff)
258258
}
259259

260+
// Check output schema validation.
261+
tool, handler := ToolFor(&Tool{Name: "badout"},
262+
func(_ context.Context, _ *CallToolRequest, arg map[string]any) (*CallToolResult, map[string]any, error) {
263+
return nil, map[string]any{"x": 1}, nil
264+
})
265+
tool.OutputSchema.Properties = map[string]*jsonschema.Schema{
266+
"x": {Type: "string"},
267+
}
268+
s.AddTool(tool, handler)
269+
gotFail, err = cs.CallTool(ctx, &CallToolParams{Name: "badout"})
270+
if err != nil {
271+
t.Fatal(err)
272+
}
273+
wantFail = &CallToolResult{IsError: true}
274+
if diff := cmp.Diff(wantFail, gotFail); diff != "" {
275+
t.Errorf("tools/call 'badout' mismatch (-want +got):\n%s", diff)
276+
}
277+
278+
// Check tools-changed notifications.
260279
s.AddTool(&Tool{Name: "T", InputSchema: &jsonschema.Schema{Type: "object"}}, nopHandler)
261280
waitForNotification(t, "tools")
262281
s.RemoveTools("T")

0 commit comments

Comments
 (0)