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
15 changes: 15 additions & 0 deletions mcp/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package mcp

import (
"bytes"
"context"
"encoding/json"
"errors"
"flag"
Expand Down Expand Up @@ -96,6 +97,18 @@ func TestServerConformance(t *testing.T) {
}
}

type input struct {
In string `jsonschema:"the input"`
}

type output struct {
Out string `jsonschema:"the output"`
}

func structuredTool(ctx context.Context, req *CallToolRequest, args *input) (*CallToolResult, *output, error) {
return nil, &output{"Ack " + args.In}, nil
}

// runServerTest runs the server conformance test.
// It must be executed in a synctest bubble.
func runServerTest(t *testing.T, test *conformanceTest) {
Expand All @@ -109,6 +122,8 @@ func runServerTest(t *testing.T, test *conformanceTest) {
Name: "greet",
Description: "say hi",
}, sayHi)
case "structured":
AddTool(s, &Tool{Name: "structured"}, structuredTool)
default:
t.Fatalf("unknown tool %q", tn)
}
Expand Down
5 changes: 1 addition & 4 deletions mcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func toolForErr[In, Out any](t *Tool, h ToolHandlerFor[In, Out]) (*Tool, ToolHan
)
if reflect.TypeFor[Out]() != reflect.TypeFor[any]() {
var err error
elemZero, err = setSchema[Out](&t.OutputSchema, &outputResolved)
elemZero, err = setSchema[Out](&tt.OutputSchema, &outputResolved)
if err != nil {
return nil, nil, fmt.Errorf("output schema: %v", err)
}
Expand Down Expand Up @@ -258,9 +258,6 @@ func toolForErr[In, Out any](t *Tool, h ToolHandlerFor[In, Out]) (*Tool, ToolHan
res.StructuredContent = elemZero
}
}
if tt.OutputSchema != nil && elemZero != nil {
res.StructuredContent = elemZero
}
return res, nil
}

Expand Down
30 changes: 30 additions & 0 deletions mcp/testdata/conformance/server/tools.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Fixed bugs:

-- tools --
greet
structured

-- client --
{
Expand Down Expand Up @@ -63,6 +64,35 @@ greet
"additionalProperties": false
},
"name": "greet"
},
{
"inputSchema": {
"type": "object",
"required": [
"In"
],
"properties": {
"In": {
"type": "string",
"description": "the input"
}
},
"additionalProperties": false
},
"name": "structured",
"outputSchema": {
"type": "object",
"required": [
"Out"
],
"properties": {
"Out": {
"type": "string",
"description": "the output"
}
},
"additionalProperties": false
}
}
]
}
Expand Down