Skip to content

Commit b8c81c6

Browse files
committed
address comments
1 parent 3dd0074 commit b8c81c6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

mcp/server.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,12 @@ func toolForErr[In, Out any](t *Tool, h ToolHandlerFor[In, Out]) (*Tool, ToolHan
201201
// element type, use the zero value of its element type in place of a typed
202202
// nil.
203203
var (
204-
zero any
204+
elemZero any // only non-nil if Out is a pointer type
205205
outputResolved *jsonschema.Resolved
206206
)
207207
if reflect.TypeFor[Out]() != reflect.TypeFor[any]() {
208208
var err error
209-
zero, err = setSchema[Out](&t.OutputSchema, &outputResolved)
209+
elemZero, err = setSchema[Out](&t.OutputSchema, &outputResolved)
210210
if err != nil {
211211
return nil, nil, fmt.Errorf("output schema: %v", err)
212212
}
@@ -250,16 +250,16 @@ func toolForErr[In, Out any](t *Tool, h ToolHandlerFor[In, Out]) (*Tool, ToolHan
250250
res = &CallToolResult{}
251251
}
252252
res.StructuredContent = out
253-
if zero != nil {
253+
if elemZero != nil {
254254
// Avoid typed nil, which will serialize as JSON null.
255255
// Instead, use the zero value of the non-zero
256256
var z Out
257-
if any(out) == any(z) { // bypass comparable check: pointers are comparable
258-
res.StructuredContent = zero
257+
if any(out) == any(z) { // zero is only non-nil if Out is a pointer type
258+
res.StructuredContent = elemZero
259259
}
260260
}
261-
if tt.OutputSchema != nil && zero != nil {
262-
res.StructuredContent = zero
261+
if tt.OutputSchema != nil && elemZero != nil {
262+
res.StructuredContent = elemZero
263263
}
264264
return res, nil
265265
}

0 commit comments

Comments
 (0)