From 0bb1a42b53c08869cdc65281504081706c3627b8 Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Wed, 3 Sep 2025 11:34:02 -0400 Subject: [PATCH] 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. --- examples/server/middleware/main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/server/middleware/main.go b/examples/server/middleware/main.go index 224c8c6..4e37471 100644 --- a/examples/server/middleware/main.go +++ b/examples/server/middleware/main.go @@ -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 }, )