Commit 18117eb
authored
Integrate project logger with MCP SDK ClientOptions and ServerOptions (#1067)
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:
```go
sdk.NewClient(&sdk.Implementation{...}, &sdk.ClientOptions{})
sdk.NewServer(&sdk.Implementation{...}, nil)
```
After:
```go
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]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses (expand for details)</summary>
>
> #### 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:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to the custom allowlist in this
repository's [Copilot coding agent
settings](https://github.com/github/gh-aw-mcpg/settings/copilot/coding_agent)
(admins only)
>
> </details>
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
----
*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:**
```go
sdk.NewServer(&sdk.Implementation{
Name: "awmg-unified",
Version: "1.0.0",
}, nil) // 4 files changed
Lines changed: 32 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
158 | 159 | | |
159 | 160 | | |
160 | 161 | | |
161 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
162 | 168 | | |
163 | 169 | | |
164 | 170 | | |
165 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
166 | 174 | | |
167 | 175 | | |
168 | 176 | | |
| |||
300 | 308 | | |
301 | 309 | | |
302 | 310 | | |
303 | | - | |
304 | | - | |
| 311 | + | |
| 312 | + | |
305 | 313 | | |
306 | 314 | | |
307 | 315 | | |
| |||
506 | 514 | | |
507 | 515 | | |
508 | 516 | | |
509 | | - | |
510 | | - | |
| 517 | + | |
| 518 | + | |
511 | 519 | | |
512 | 520 | | |
513 | 521 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
568 | 569 | | |
569 | 570 | | |
570 | 571 | | |
571 | | - | |
| 572 | + | |
572 | 573 | | |
573 | 574 | | |
574 | 575 | | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
575 | 583 | | |
576 | 584 | | |
577 | 585 | | |
| |||
687 | 695 | | |
688 | 696 | | |
689 | 697 | | |
690 | | - | |
| 698 | + | |
691 | 699 | | |
692 | 700 | | |
693 | 701 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
186 | | - | |
| 186 | + | |
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
190 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
191 | 193 | | |
192 | 194 | | |
193 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
| 135 | + | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
140 | 142 | | |
141 | 143 | | |
142 | 144 | | |
| |||
0 commit comments