Skip to content

Commit 0bb1a42

Browse files
authored
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.
1 parent 063fb12 commit 0bb1a42

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

examples/server/middleware/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ func main() {
6464
"duration_ms", duration.Milliseconds(),
6565
"has_result", result != nil,
6666
)
67+
// Log more for tool results.
68+
if ctr, ok := result.(*mcp.CallToolResult); ok {
69+
logger.Info("tool result",
70+
"isError", ctr.IsError,
71+
"structuredContent", ctr.StructuredContent)
72+
}
6773
}
6874
return result, err
6975
}
@@ -103,7 +109,7 @@ func main() {
103109
Content: []mcp.Content{
104110
&mcp.TextContent{Text: message},
105111
},
106-
}, nil, nil
112+
}, message, nil
107113
},
108114
)
109115

0 commit comments

Comments
 (0)