examples/server/middleware: log tool result (#400)

Log the result of a tool call in the middleware.

This example now fully demonstrates that receiving middleware can
effectively wrap a ToolHandler. That means that one reason for ToolFor
is moot: you don't need to get your hands on the returned ToolHandler in
order to wrap it.
This commit is contained in:
Jonathan Amsterdam 2025-09-03 11:34:02 -04:00 • committed by GitHub
commit 0bb1a42b53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -64,6 +64,12 @@ func main() {
"duration_ms", duration.Milliseconds(),
"has_result", result != nil,
)
// Log more for tool results.
if ctr, ok := result.(*mcp.CallToolResult); ok {
logger.Info("tool result",
"isError", ctr.IsError,
"structuredContent", ctr.StructuredContent)
}
}
return result, err
}
@ -103,7 +109,7 @@ func main() {
Content: []mcp.Content{
&mcp.TextContent{Text: message},
},
}, nil, nil
}, message, nil
},
)