Skip to content
Merged
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
11 changes: 7 additions & 4 deletions mcp/example_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ func Example_loggingMiddleware() {
"session_id", req.GetSession().ID(),
"has_params", req.GetParams() != nil,
)
// Log more for tool calls.
if ctr, ok := req.(*mcp.CallToolRequest); ok {
logger.Info("Calling tool",
"name", ctr.Params.Name,
"args", ctr.Params.Arguments)
}

start := time.Now()

result, err := next(ctx, method, req)

duration := time.Since(start)

if err != nil {
logger.Error("MCP method failed",
"method", method,
Expand All @@ -62,7 +65,6 @@ func Example_loggingMiddleware() {
"has_result", result != nil,
)
}

return result, err
}
}
Expand Down Expand Up @@ -134,6 +136,7 @@ func Example_loggingMiddleware() {
// time=2025-01-01T00:00:00Z level=INFO msg="MCP method started" method=notifications/initialized session_id="" has_params=true
// time=2025-01-01T00:00:00Z level=INFO msg="MCP method completed" method=notifications/initialized session_id="" duration_ms=0 has_result=false
// time=2025-01-01T00:00:00Z level=INFO msg="MCP method started" method=tools/call session_id="" has_params=true
// time=2025-01-01T00:00:00Z level=INFO msg="Calling tool" name=greet args="{\"name\":\"World\"}"
// time=2025-01-01T00:00:00Z level=INFO msg="MCP method completed" method=tools/call session_id="" duration_ms=0 has_result=true
// Tool result: Hello, World!
}