Skip to content

How can I plug it into an existing net/http server? #44

@zoedsoupe

Description

@zoedsoupe

Description:

I’m integrating mcp-go’s SSEServer into my project and need to combine it with other HTTP endpoints (e.g., Kubernetes health checks) in a single server. For clarity, I want to mount the SSEServer under a custom prefix (e.g., /mcp) while leaving my health endpoints at the root (like /live and /ready).

The SSEServer’s ServeHTTP method is designed to handle requests exactly at /sse and /message. When I attempt to register it using http.HandleFunc with a prefix I still encounter 404 errors when accessing /mcp/sse or /mcp/message.

Steps to Reproduce:

  1. Initialize an instance of the SSEServer via the mcp-go API.
  2. Register the handler using a code snippet similar to:
http.HandleFunc("/ready", readinessHandler)

// assuming s is an already existing MCPServer
sse := server.NewSSEServer(s, "")
http.HandleFunc("/mcp/", sse.ServerHTTP)

log.Fatal(http.listAndServe(":80", nil))
  1. Access /mcp/sse, /mcp/message or /sse, /message and observe a 404 response.

Expected Behavior:

  • A request at least to /sse should be correctly handled.

Environment:

  • Go version: 1.23.5 (using an Alpine-based Docker image)
  • mcp-go version: v0.11.2

Additional Context:

  • I have verified that endpoints like /live and /ready work as expected.
  • The issue appears to be specific to the prefix handling for SSEServer’s endpoints.
  • I’m open to suggestions on the correct approach for mounting the SSEServer under a custom path or if this might be a limitation/bug.

Any guidance or recommended changes would be greatly appreciated. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions