Skip to content

Integrate project logger with MCP SDK ClientOptions and ServerOptions#1067

Merged
lpcox merged 2 commits intomainfrom
copilot/review-go-sdk-module
Feb 19, 2026
Merged

Integrate project logger with MCP SDK ClientOptions and ServerOptions#1067
lpcox merged 2 commits intomainfrom
copilot/review-go-sdk-module

Conversation

Copy link
Contributor

Copilot AI commented Feb 19, 2026

The MCP SDK v1.3.0 supports logger injection through ClientOptions and ServerOptions, but the gateway was passing empty options (&sdk.ClientOptions{}) or nil, leaving SDK operations invisible in logs.

Changes

Client creation (internal/mcp/connection.go)

  • newMCPClient() now accepts *logger.Logger parameter
  • Converts to *slog.Logger via logger.NewSlogLoggerWithHandler()
  • Passes to sdk.ClientOptions.Logger

Server creation (internal/server/unified.go, internal/server/routed.go)

  • Pass logger via sdk.ServerOptions in unified mode
  • Pass logger via sdk.ServerOptions in routed/filtered servers

Tests

  • Tests pass nil to disable SDK logging in test environments
  • Added TestNewMCPClientWithLogger for validation

Example

Before:

sdk.NewClient(&sdk.Implementation{...}, &sdk.ClientOptions{})
sdk.NewServer(&sdk.Implementation{...}, nil)

After:

sdk.NewClient(&sdk.Implementation{...}, &sdk.ClientOptions{
    Logger: logger.NewSlogLoggerWithHandler(log),
})
sdk.NewServer(&sdk.Implementation{...}, &sdk.ServerOptions{
    Logger: logger.NewSlogLoggerWithHandler(logUnified),
})

SDK internal operations now flow through the project's debug logging system (DEBUG=* shows SDK activity).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /tmp/go-build1436996487/b275/launcher.test /tmp/go-build1436996487/b275/launcher.test -test.testlogfile=/tmp/go-build1436996487/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true o s.go 64/pkg/tool/linu_x004.c credential.helpe/opt/hostedtoolcache/go/1.25.7/x64/pkg/tool/linux_amd64/vet (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build1436996487/b260/config.test /tmp/go-build1436996487/b260/config.test -test.testlogfile=/tmp/go-build1436996487/b260/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go ac/hmac.go x_amd64/asm --depth 2 REDACTED x_amd64/asm conf�� g_.a HEHYCbGHr 64/pkg/tool/linux_amd64/compile user.name (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build1436996487/b275/launcher.test /tmp/go-build1436996487/b275/launcher.test -test.testlogfile=/tmp/go-build1436996487/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true o s.go 64/pkg/tool/linu_x004.c credential.helpe/opt/hostedtoolcache/go/1.25.7/x64/pkg/tool/linux_amd64/vet (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build1436996487/b275/launcher.test /tmp/go-build1436996487/b275/launcher.test -test.testlogfile=/tmp/go-build1436996487/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true o s.go 64/pkg/tool/linu_x004.c credential.helpe/opt/hostedtoolcache/go/1.25.7/x64/pkg/tool/linux_amd64/vet (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build1436996487/b284/mcp.test /tmp/go-build1436996487/b284/mcp.test -test.testlogfile=/tmp/go-build1436996487/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -c=4 -nolocalimports -importcfg /tmp/go-build180286792/b223/importcfg -pack /home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/internal/middleware/jqschema.go 64/pkg/include 64/s�� 64/src/runtime/cgo --global ache/go/1.25.7/x64/pkg/tool/linu--64 pull.rebase (dns block)
    • Triggering command: /tmp/go-build2197604316/b284/mcp.test /tmp/go-build2197604316/b284/mcp.test -test.testlogfile=/tmp/go-build2197604316/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ache/go/1.25.7/x64/src/runtime/c-p v5H2/gdzdyx1nTJ_thj3Av5H2 8085717/b189/ (dns block)
    • Triggering command: /tmp/go-build1032557839/b284/mcp.test /tmp/go-build1032557839/b284/mcp.test -test.testlogfile=/tmp/go-build1032557839/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true s mn4I/VW84qF8_Uqs9FMGXmn4I x_amd64/compile (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[go-fan] Go Module Review: modelcontextprotocol/go-sdk</issue_title>
<issue_description># 🐹 Go Fan Report: modelcontextprotocol/go-sdk

Module Overview

The modelcontextprotocol/go-sdk is the official Go SDK for Model Context Protocol servers and clients, maintained in collaboration with Google. This SDK provides comprehensive support for building MCP servers and clients in Go, including HTTP/SSE transport, stdio transport, tool/resource/prompt registration, and session management.

Repository: https://github.com/modelcontextprotocol/go-sdk
Version Used: v1.3.0 ✅ (Latest)
Last Updated: 2026-02-18 (Today!)
Stars: 3,875 ⭐

Current Usage in gh-aw-mcpg

Files & Import Statistics

  • Files: 20 files (5 production + 15 test files)
  • Import Count: 20 direct imports
  • Key APIs Used:
    • Server APIs: NewServer(), AddTool(), NewStreamableHTTPHandler(), StreamableHTTPOptions
    • Client APIs: NewClient(), Connect(), ListTools(), CallTool()
    • Transport APIs: NewInMemoryTransports(), StreamableHTTP with session support

Production Files

  1. internal/server/transport.go - StreamableHTTP handler creation
  2. internal/server/unified.go - Unified mode server implementation
  3. internal/server/routed.go - Routed mode server implementation
  4. internal/mcp/connection.go - Client connections to backend MCP servers
  5. internal/testutil/mcptest/ - Test infrastructure (3 files)

Current Patterns

Server Creation:

sdk.NewServer(&sdk.Implementation{
    Name:    "awmg-unified",
    Version: "1.0.0",
}, nil)  // ⚠️ No server options used

Client Creation:

sdk.NewClient(&sdk.Implementation{
    Name:    "awmg",
    Version: version.Get(),
}, &sdk.ClientOptions{})  // ⚠️ Empty options

StreamableHTTP (Good!):

&sdk.StreamableHTTPOptions{
    Stateless:      false,
    Logger:         logger.NewSlogLoggerWithHandler(logTransport),
    SessionTimeout: 30 * time.Minute,
}

Research Findings

Recent Updates (v1.3.0 - Released 2026-02-09)

The project is using the latest version of the SDK! v1.3.0 includes significant improvements:

  1. ✨ Schema Caching - Dramatically improves performance in stateless server scenarios
  2. 🔧 Logger in ClientOptions - Logging moved from deprecated location to ClientOptions
  3. 🛡️ GetError/SetError Export - Better structured error handling
  4. 🐛 Case-Insensitive HTTP Headers - Fixed SSE Content-Type checking bug
  5. ⚡ Race Condition Fix - Fixed logging race condition
  6. 📋 HTTP 405 Compliance - Added Allow header per RFC 9110

Best Practices from SDK Maintainers

  1. Logger Integration: Pass logger through ClientOptions and ServerOptions for complete visibility
  2. Error Handling: Use SDK's GetError/SetError methods for structured error context
  3. Session Management: Leverage StreamableHTTP with timeouts (✅ already doing this!)
  4. Schema Caching: Automatic in v1.3.0, provides significant performance gains

SDK Features We're NOT Using

  1. Resources API - Only test usage, no production resources exposed
  2. Prompts API - Zero usage (could provide helpful templates)
  3. Completion API - Zero usage
  4. Sampling API - Zero usage (LLM integration)
  5. Extensions (SEP-2133) - New capability for custom protocol extensions
  6. Advanced Logging - Logger only in transport, not in client/server options
  7. Structured Error Types - Custom HTTP errors instead of SDK types

Improvement Opportunities

🏃 Quick Wins

1. Add Logger to ClientOptions ⭐ HIGH PRIORITY

  • Current: &sdk.ClientOptions{} (empty)
  • Fix: Pass project logger to SDK
  • Benefit: Unified logging across gateway and SDK operations
  • Effort: 1-2 hours
  • Location: internal/mcp/connection.go:165
  • Code:
    &sdk.ClientOptions{
        Logger: logger.NewSlogLoggerWithHandler(logClient),
    }

2. Add Logger to ServerOptions ⭐ HIGH PRIORITY

  • Current: sdk.NewServer(..., nil) (no options)
  • Fix: Pass logger via server options
  • Benefit: Better visibility into SDK server operations
  • Effort: 1-2 hours
  • Locations: internal/server/unified.go:136, internal/server/routed.go:187

3. Validate Schema Caching Performance

  • Current: Automatic in v1.3.0 (good!)
  • Improvement: Add metrics to quantify performance gains
  • Benefit: Document actual performance improvements
  • Effort: 2-3 hours

✨ Feature Opportunities

1. Implement Resources API (Medium Complexity)

Opportunity: Expose gateway state as MCP resources

Potential Resources:

  • /config - Current gateway configuration
  • /health - Gateway health status
  • /metrics - Performance metrics
  • /backends - Backend server status
  • /sessions - Active session information

Benefit: Clients can query gateway state using ...


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Review Go Module modelcontextprotocol/go-sdk Integrate project logger with MCP SDK ClientOptions and ServerOptions Feb 19, 2026
@lpcox lpcox marked this pull request as ready for review February 19, 2026 00:24
Copilot AI review requested due to automatic review settings February 19, 2026 00:24
@lpcox lpcox merged commit 18117eb into main Feb 19, 2026
8 checks passed
@lpcox lpcox deleted the copilot/review-go-sdk-module branch February 19, 2026 00:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR integrates the project's logger with the MCP SDK v1.3.0's ClientOptions and ServerOptions, enabling visibility into SDK internal operations through the gateway's debug logging system. Previously, empty options were passed, leaving SDK operations invisible in logs.

Changes:

  • Added logger parameter to newMCPClient() function with nil-safety check for test environments
  • Integrated logger with SDK ClientOptions for all client connections
  • Integrated logger with SDK ServerOptions for unified and routed mode servers

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
internal/mcp/connection.go Modified newMCPClient() to accept logger parameter and pass it to SDK ClientOptions; updated all call sites to pass logConn
internal/mcp/connection_test.go Updated test calls to pass nil logger and added new test TestNewMCPClientWithLogger to verify logger acceptance
internal/server/unified.go Updated unified server creation to pass logger via ServerOptions
internal/server/routed.go Updated filtered server creation to pass logger via ServerOptions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[go-fan] Go Module Review: modelcontextprotocol/go-sdk

3 participants