Skip to content
Closed
Show file tree
Hide file tree
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
7 changes: 1 addition & 6 deletions contrib/mark3labs/mcp-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@ func main() {
}
defer tracer.Stop()

// Add tracing to your server hooks
hooks := &server.Hooks{}
mcpgotrace.AddServerHooks(hooks)

srv := server.NewMCPServer("my-server", "1.0.0",
server.WithHooks(hooks),
server.WithToolHandlerMiddleware(mcpgotrace.NewToolHandlerMiddleware()))
mcpgotrace.WithTracing())
}
```

Expand Down
9 changes: 2 additions & 7 deletions contrib/mark3labs/mcp-go/example_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016 Datadog, Inc.
// Copyright 2025 Datadog, Inc.

package mcpgo_test

Expand All @@ -15,12 +15,7 @@ func Example() {
tracer.Start()
defer tracer.Stop()

// Create server hooks and add Datadog tracing
hooks := &server.Hooks{}
mcpgotrace.AddServerHooks(hooks)

srv := server.NewMCPServer("my-server", "1.0.0",
server.WithHooks(hooks),
server.WithToolHandlerMiddleware(mcpgotrace.NewToolHandlerMiddleware()))
mcpgotrace.WithTracing())
_ = srv
}
2 changes: 1 addition & 1 deletion contrib/mark3labs/mcp-go/mcpgo.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016 Datadog, Inc.
// Copyright 2025 Datadog, Inc.

package mcpgo // import "github.com/DataDog/dd-trace-go/contrib/mark3labs/mcp-go/v2"

Expand Down
14 changes: 4 additions & 10 deletions contrib/mark3labs/mcp-go/mcpgo_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016 Datadog, Inc.
// Copyright 2025 Datadog, Inc.

package mcpgo

Expand Down Expand Up @@ -47,11 +47,7 @@ func TestIntegrationSessionInitialize(t *testing.T) {
tt := testTracer(t)
defer tt.Stop()

hooks := &server.Hooks{}
AddServerHooks(hooks)

srv := server.NewMCPServer("test-server", "1.0.0",
server.WithHooks(hooks))
srv := server.NewMCPServer("test-server", "1.0.0", WithTracing())

ctx := context.Background()
initRequest := `{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test-client","version":"1.0.0"}}}`
Expand Down Expand Up @@ -102,8 +98,7 @@ func TestIntegrationToolCallSuccess(t *testing.T) {
tt := testTracer(t)
defer tt.Stop()

srv := server.NewMCPServer("test-server", "1.0.0",
server.WithToolHandlerMiddleware(NewToolHandlerMiddleware()))
srv := server.NewMCPServer("test-server", "1.0.0", WithTracing())

calcTool := mcp.NewTool("calculator",
mcp.WithDescription("A simple calculator"))
Expand Down Expand Up @@ -180,8 +175,7 @@ func TestIntegrationToolCallError(t *testing.T) {
tt := testTracer(t)
defer tt.Stop()

srv := server.NewMCPServer("test-server", "1.0.0",
server.WithToolHandlerMiddleware(NewToolHandlerMiddleware()))
srv := server.NewMCPServer("test-server", "1.0.0", WithTracing())

errorTool := mcp.NewTool("error_tool",
mcp.WithDescription("A tool that always errors"))
Expand Down
36 changes: 36 additions & 0 deletions contrib/mark3labs/mcp-go/option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2025 Datadog, Inc.

package mcpgo

import (
"reflect"

"github.com/mark3labs/mcp-go/server"
)

// The file contains methods for easily adding tracing to a MCP server.

// Pass to server.NewMCPServer to add tracing to the server.
func WithTracing() server.ServerOption {
return func(s *server.MCPServer) {

// Append hooks (hooks is a private field)
v := reflect.ValueOf(s).Elem()
hooksField := v.FieldByName("hooks")
if !hooksField.IsValid() {
return
}
hooksField = reflect.NewAt(hooksField.Type(), hooksField.Addr().UnsafePointer()).Elem()
if hooksField.IsNil() {
hooksField.Set(reflect.ValueOf(&server.Hooks{}))
}
hooks := hooksField.Interface().(*server.Hooks)
AddServerHooks(hooks)

// Add tool handler middleware (toolHandlerMiddlewares is a private field, but this appensd to it)
server.WithToolHandlerMiddleware(NewToolHandlerMiddleware())(s)
}
}
Loading