Skip to content

feat(mcp): support Streamable HTTP transport alongside the legacy SSE endpoint - #1684

Open
shaktimaan00 wants to merge 1 commit into
apache:mainfrom
shaktimaan00:fix/1677-mcp-streamable-http
Open

shaktimaan00 wants to merge 1 commit into
apache:mainfrom
shaktimaan00:fix/1677-mcp-streamable-http

Conversation

@shaktimaan00

Copy link
Copy Markdown

Fixes #1677

Proposed Changes

  • Serve the MCP server over Streamable HTTP as well as the legacy HTTP+SSE transport.
    RegisterMCPRouter now builds server.NewStreamableHTTPServer(s) from the same *server.MCPServer
    the SSE server already serves and mounts it at POST /answer/api/v1/mcp on the existing
    authenticated group, so both transports expose one identical tool list.
  • Leave GET /mcp/sse and POST /mcp/message exactly as they are, for clients that only speak the
    deprecated transport.
  • Add internal/router/mcp_streamable_test.go: an MCP initialize + notifications/initialized +
    tools/list round-trip against the new endpoint (asserting the Mcp-Session-Id header and the six
    built-in tools), plus a check that the legacy message endpoint and SSE route are still wired.

No options are passed to NewStreamableHTTPServer, so the optional GET server-initiated stream
stays enabled (mcp-go's default) — the group's AuthAPIKey middleware already maps GET to a
read-scope key and POST to a write-scope key, and Answer sends no server-initiated notifications.
Say the word if you would rather have server.WithDisableStreaming(true); it is a one-line change.

Checklist

  • Streamable HTTP endpoint at POST /answer/api/v1/mcp built with the pinned mcp-go v0.43.2
  • MCP initialize returns a result and an Mcp-Session-Id; tools/list on that session returns
    get_questions, get_answers_by_question_id, get_comments, get_tags, get_tag_detail,
    get_user
  • Legacy GET /mcp/sse and POST /mcp/message untouched and still registered
  • New route sits on the AuthMcpEnable() + AuthAPIKey() group (internal/base/server/http.go)
  • No new dependency; go.mod/go.sum unchanged

Validation

Run in a golang:1.25-bookworm container against this branch:

command result
go build ./... ok
go vet ./internal/router/ ok
go test ./internal/router/ ./internal/base/middleware/ ./internal/controller/ -count=1 all ok
go test ./... -count=1 all packages ok, no failures
gofmt -l internal/router/ no output
golangci-lint run (v2.6.2, the version Makefile pins) 0 issues

make lint itself is not runnable here because script/check-asf-header.sh needs Docker/Podman for
the hawkeye formatter; the new file carries the ASF header byte-for-byte from mcp_router.go, and
gofmt (the same target's last step) is clean.

The new test fails without the production change (initialize status = 404), so it actually covers
the endpoint rather than the mock.

Notes for the reviewer

Register mcp-go's StreamableHTTPServer at /mcp on the same authenticated group as the
SSE endpoints, so current MCP clients can connect while older ones keep the SSE transport.

This branch has not been deployed

No deployments
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.

feat(mcp): support Streamable HTTP transport in addition to legacy SSE

1 participant