Skip to content

Commit 1e1ad70

Browse files
authored
Merge pull request #268 from githubnext/main-b2dfb8db2d936040
[log] Add debug logging to internal/server/transport.go
2 parents 5cff224 + fb83b9d commit 1e1ad70

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

internal/server/transport.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ import (
1515
sdk "github.com/modelcontextprotocol/go-sdk/mcp"
1616
)
1717

18+
var logTransport = logger.New("server:transport")
19+
1820
// HTTPTransport wraps the SDK's HTTP transport
1921
type HTTPTransport struct {
2022
Addr string
2123
}
2224

2325
// Start implements sdk.Transport interface
2426
func (t *HTTPTransport) Start(ctx context.Context) error {
27+
logTransport.Printf("Starting HTTP transport: addr=%s", t.Addr)
2528
// The SDK will handle the actual HTTP server setup
2629
// We just need to provide the address
2730
log.Printf("HTTP transport ready on %s", t.Addr)
@@ -76,6 +79,7 @@ func withResponseLogging(handler http.Handler) http.Handler {
7679
// CreateHTTPServerForMCP creates an HTTP server that handles MCP over streamable HTTP transport
7780
// If apiKey is provided, all requests except /health require authentication (spec 7.1)
7881
func CreateHTTPServerForMCP(addr string, unifiedServer *UnifiedServer, apiKey string) *http.Server {
82+
logTransport.Printf("Creating HTTP server for MCP: addr=%s, auth_enabled=%v", addr, apiKey != "")
7983
mux := http.NewServeMux()
8084

8185
// OAuth discovery endpoint - return 404 since we don't use OAuth
@@ -85,6 +89,7 @@ func CreateHTTPServerForMCP(addr string, unifiedServer *UnifiedServer, apiKey st
8589
})
8690
mux.Handle("/mcp/.well-known/oauth-authorization-server", withResponseLogging(oauthHandler))
8791

92+
logTransport.Print("Registering streamable HTTP handler for MCP protocol")
8893
// Create StreamableHTTP handler for MCP protocol (supports POST requests)
8994
// This is what Codex uses with transport = "streamablehttp"
9095
streamableHandler := sdk.NewStreamableHTTPHandler(func(r *http.Request) *sdk.Server {
@@ -110,6 +115,7 @@ func CreateHTTPServerForMCP(addr string, unifiedServer *UnifiedServer, apiKey st
110115

111116
// Reject requests without Authorization header
112117
if sessionID == "" {
118+
logTransport.Printf("Rejecting connection: no Authorization header, remote=%s, path=%s", r.RemoteAddr, r.URL.Path)
113119
logger.LogErrorMd("client", "MCP connection rejected: no Authorization header, remote=%s, path=%s", r.RemoteAddr, r.URL.Path)
114120
log.Printf("[%s] %s %s - REJECTED: No Authorization header", r.RemoteAddr, r.Method, r.URL.Path)
115121
// Return nil to reject the connection
@@ -163,6 +169,7 @@ func CreateHTTPServerForMCP(addr string, unifiedServer *UnifiedServer, apiKey st
163169

164170
// Close endpoint for graceful shutdown (spec 5.1.3)
165171
closeHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
172+
logTransport.Printf("Close endpoint called: method=%s, remote=%s", r.Method, r.RemoteAddr)
166173
log.Printf("[%s] %s %s", r.RemoteAddr, r.Method, r.URL.Path)
167174
logger.LogInfo("shutdown", "Close endpoint called, remote=%s", r.RemoteAddr)
168175

@@ -185,6 +192,7 @@ func CreateHTTPServerForMCP(addr string, unifiedServer *UnifiedServer, apiKey st
185192

186193
// Initiate shutdown and get server count
187194
serversTerminated := unifiedServer.InitiateShutdown()
195+
logTransport.Printf("Shutdown initiated: servers_terminated=%d", serversTerminated)
188196

189197
// Return success response (spec 5.1.3)
190198
w.Header().Set("Content-Type", "application/json")

0 commit comments

Comments
 (0)