SSE endpoints not working in network mode - only HTTP endpoint functional #13

Closed
opened 2025-07-13 20:11:27 -05:00 by b3nw · 1 comment
Owner

SSE Endpoints Not Working in Network Mode

Issue Description

In network mode, the HTTP endpoint (/mcp) works perfectly but the SSE endpoints (/sse and /message) return 404 errors. This prevents achieving the goal of having both HTTP and SSE transports on a single port.

Current Status

Working: HTTP endpoint at /mcp with proper session management
Not Working: SSE endpoints at /sse and /message

Environment

  • Version: network-mode-v0.3.0 branch
  • mcp-go version: v0.30.0
  • Transport mode: network
  • Test server: git.local.ben.io:8080

Working HTTP Endpoint Test

# HTTP endpoint works perfectly
curl -X POST http://git.local.ben.io:8080/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}}}'

# Returns:
# HTTP/1.1 200 OK
# Mcp-Session-Id: mcp-session-32a4e4af-483b-4b0e-a135-cdc5a1a2c420
# {"jsonrpc":"2.0","id":1,"result":{...}}

Failing SSE Endpoint Tests

# SSE connection endpoint fails
curl -X GET http://git.local.ben.io:8080/sse
# Returns: 404 page not found

# SSE message endpoint fails  
curl -X POST http://git.local.ben.io:8080/message?sessionId=test \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"tools/list","params":{},"id":1}'
# Returns: 404 page not found

Current Implementation

case "network":
    streamableServer := server.NewStreamableHTTPServer(mcpServer)
    sseServer := server.NewSSEServer(mcpServer)
    
    mux := http.NewServeMux()
    mux.Handle("/mcp", streamableServer)
    mux.Handle("/sse", sseServer.SSEHandler())
    mux.Handle("/message", sseServer.MessageHandler())
    
    return http.ListenAndServe(fmt.Sprintf(":%d", flag.Port), mux)

Attempted Solutions

1. Direct SSE Server Mounting

mux.Handle("/sse/", sseServer)  // Tried with trailing slash

Result: Still 404 on /sse/sse and /sse/message

2. Custom SSE Endpoint Configuration

sseServer := server.NewSSEServer(mcpServer,
    server.WithSSEEndpoint("/sse"),
    server.WithMessageEndpoint("/message"),
)
mux.Handle("/sse", sseServer.SSEHandler())
mux.Handle("/message", sseServer.MessageHandler())

Result: Still 404 on both endpoints

3. Default SSE Server with Handler Mounting

sseServer := server.NewSSEServer(mcpServer)
mux.Handle("/sse", sseServer.SSEHandler())
mux.Handle("/message", sseServer.MessageHandler())

Result: Still 404 on both endpoints

Server Binding Confirmation

  • Server process runs successfully
  • Port 8080 is bound correctly
  • HTTP requests to /mcp work perfectly
  • All requests to /sse and /message return 404

Analysis

The issue appears to be related to how the SSE handlers are being mounted or configured. The mcp-go SSE server expects specific routing that may not be compatible with custom mux mounting.

Investigation Areas

  1. SSE Handler Internal Routing: The SSE handlers may expect to handle their own internal routing
  2. Path Conflicts: There may be path normalization issues with the Go ServeMux
  3. Handler Initialization: The SSE handlers may require specific initialization that's not happening
  4. mcp-go Framework Limitations: The framework may not support custom mounting of SSE handlers

Workaround

Currently, users can use the HTTP endpoint (/mcp) which is fully functional with session management. However, this doesn't achieve the goal of having both transports available.

Next Steps

  1. Examine mcp-go SSE server source code more thoroughly
  2. Test SSE server in isolation to understand expected behavior
  3. Consider alternative mounting strategies
  4. Investigate if custom routing wrapper is needed

Files Modified

  • operation/operation.go (network mode implementation)
  • TESTING.md (documentation of endpoints)

Priority

Medium - HTTP endpoint works, but full network mode functionality requires both transports

# SSE Endpoints Not Working in Network Mode ## Issue Description In network mode, the HTTP endpoint (`/mcp`) works perfectly but the SSE endpoints (`/sse` and `/message`) return 404 errors. This prevents achieving the goal of having both HTTP and SSE transports on a single port. ## Current Status ✅ **Working**: HTTP endpoint at `/mcp` with proper session management ❌ **Not Working**: SSE endpoints at `/sse` and `/message` ## Environment - **Version**: network-mode-v0.3.0 branch - **mcp-go version**: v0.30.0 - **Transport mode**: `network` - **Test server**: git.local.ben.io:8080 ## Working HTTP Endpoint Test ```bash # HTTP endpoint works perfectly curl -X POST http://git.local.ben.io:8080/mcp \ -H "Content-Type: application/json" \ -d '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}}}' # Returns: # HTTP/1.1 200 OK # Mcp-Session-Id: mcp-session-32a4e4af-483b-4b0e-a135-cdc5a1a2c420 # {"jsonrpc":"2.0","id":1,"result":{...}} ``` ## Failing SSE Endpoint Tests ```bash # SSE connection endpoint fails curl -X GET http://git.local.ben.io:8080/sse # Returns: 404 page not found # SSE message endpoint fails curl -X POST http://git.local.ben.io:8080/message?sessionId=test \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","method":"tools/list","params":{},"id":1}' # Returns: 404 page not found ``` ## Current Implementation ```go case "network": streamableServer := server.NewStreamableHTTPServer(mcpServer) sseServer := server.NewSSEServer(mcpServer) mux := http.NewServeMux() mux.Handle("/mcp", streamableServer) mux.Handle("/sse", sseServer.SSEHandler()) mux.Handle("/message", sseServer.MessageHandler()) return http.ListenAndServe(fmt.Sprintf(":%d", flag.Port), mux) ``` ## Attempted Solutions ### 1. Direct SSE Server Mounting ```go mux.Handle("/sse/", sseServer) // Tried with trailing slash ``` **Result**: Still 404 on `/sse/sse` and `/sse/message` ### 2. Custom SSE Endpoint Configuration ```go sseServer := server.NewSSEServer(mcpServer, server.WithSSEEndpoint("/sse"), server.WithMessageEndpoint("/message"), ) mux.Handle("/sse", sseServer.SSEHandler()) mux.Handle("/message", sseServer.MessageHandler()) ``` **Result**: Still 404 on both endpoints ### 3. Default SSE Server with Handler Mounting ```go sseServer := server.NewSSEServer(mcpServer) mux.Handle("/sse", sseServer.SSEHandler()) mux.Handle("/message", sseServer.MessageHandler()) ``` **Result**: Still 404 on both endpoints ## Server Binding Confirmation - ✅ Server process runs successfully - ✅ Port 8080 is bound correctly - ✅ HTTP requests to `/mcp` work perfectly - ❌ All requests to `/sse` and `/message` return 404 ## Analysis The issue appears to be related to how the SSE handlers are being mounted or configured. The mcp-go SSE server expects specific routing that may not be compatible with custom mux mounting. ## Investigation Areas 1. **SSE Handler Internal Routing**: The SSE handlers may expect to handle their own internal routing 2. **Path Conflicts**: There may be path normalization issues with the Go ServeMux 3. **Handler Initialization**: The SSE handlers may require specific initialization that's not happening 4. **mcp-go Framework Limitations**: The framework may not support custom mounting of SSE handlers ## Workaround Currently, users can use the HTTP endpoint (`/mcp`) which is fully functional with session management. However, this doesn't achieve the goal of having both transports available. ## Next Steps 1. Examine mcp-go SSE server source code more thoroughly 2. Test SSE server in isolation to understand expected behavior 3. Consider alternative mounting strategies 4. Investigate if custom routing wrapper is needed ## Files Modified - `operation/operation.go` (network mode implementation) - `TESTING.md` (documentation of endpoints) ## Priority **Medium** - HTTP endpoint works, but full network mode functionality requires both transports
b3nw closed this issue 2025-07-13 21:06:04 -05:00
Author
Owner

This issue is now resolved. The network mode has been updated to correctly handle both HTTP and SSE transports on a single port. The operation/operation.go file was modified to properly initialize and route the SSE server endpoints (/sse and /message), which were previously returning 404 errors. Both transport methods are now fully functional in network mode.

This issue is now resolved. The `network` mode has been updated to correctly handle both HTTP and SSE transports on a single port. The `operation/operation.go` file was modified to properly initialize and route the SSE server endpoints (`/sse` and `/message`), which were previously returning 404 errors. Both transport methods are now fully functional in `network` mode.
This repo is archived. You cannot comment on issues.
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: b3nw/gitea-mcp#13