Skip to content

Commit dcbdb8d

Browse files
committed
add test
1 parent 79dca41 commit dcbdb8d

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

mcp/mcp_test.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -258,21 +258,22 @@ func TestEndToEnd(t *testing.T) {
258258
}
259259

260260
// 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"},
261+
badout := &Tool{
262+
Name: "badout",
263+
OutputSchema: &jsonschema.Schema{
264+
Type: "object",
265+
Properties: map[string]*jsonschema.Schema{
266+
"x": {Type: "string"},
267+
},
268+
},
267269
}
268-
s.AddTool(tool, handler)
270+
AddTool(s, badout, func(_ context.Context, _ *CallToolRequest, arg map[string]any) (*CallToolResult, map[string]any, error) {
271+
return nil, map[string]any{"x": 1}, nil
272+
})
269273
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)
274+
wantMsg := `has type "integer", want "string"`
275+
if err == nil || !strings.Contains(err.Error(), wantMsg) {
276+
t.Errorf("\ngot %q\nwant error message containing %q", err, wantMsg)
276277
}
277278

278279
// Check tools-changed notifications.

mcp/tool.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func unmarshalSchema(data json.RawMessage, resolved *jsonschema.Resolved, v any)
4646
return validateSchema(resolved, v)
4747
}
4848

49-
// TODO: test with nil args.
5049
func validateSchema(resolved *jsonschema.Resolved, value any) error {
5150
if resolved != nil {
5251
if err := resolved.ApplyDefaults(value); err != nil {

0 commit comments

Comments
 (0)