Skip to content

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

Open
shaktimaan00 wants to merge 4 commits into
apache:devfrom
shaktimaan00:fix/1677-mcp-streamable-http
Open

shaktimaan00 wants to merge 4 commits into
apache:devfrom
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

fenbox and others added 2 commits November 19, 2026 15:26
## Proposed Changes

- Add `AGENTS.md` with repository structure, development commands,
coding conventions, testing guidance, and commit/PR expectations.
- Add an English `DESIGN.md` following the design.md alpha
specification, documenting React Bootstrap as the design foundation and
the default primary color `#0033FF`.
- Document existing theme overrides, dark mode, layout conventions, and
component usage, with YAML design tokens and source references.

## Validation

- Checked commands and conventions against repository configuration and
source files.
- Confirmed `DESIGN.md` contains no Chinese text.
- `git diff --cached --check` passed before committing.
- Documentation-only changes; no application tests run.
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.
@LinkinStars

Copy link
Copy Markdown
Member

The new test still expects Answer Enterprise MCP Server, but dev now initializes the server with constant.MCPServerName (Apache Answer MCP Server). After merging into dev, TestRegisterMCPRouterServesStreamableHTTP will fail on this assertion.

Please update the test to use the shared constant.MCPServerName.

…Name

dev initializes the MCP server with constant.MCPServerName, so the literal
"Answer Enterprise MCP Server" in this assertion would fail as soon as the
branch is merged into dev. The test now reads the same constant the router uses.
@shaktimaan00

Copy link
Copy Markdown
Author

Fixed in 81460ab: the assertion now compares initResponse.Result.ServerInfo.Name with
constant.MCPServerName, and the failure message prints the same constant, so the test follows
whatever name the router initializes the server with instead of the old literal.

I also merged dev into the branch (646d838) — it was well behind, and that is what surfaces the
assertion you flagged. The transport code is unchanged: newMCPSSEServer builds the SSE endpoints
from the shared constants as on dev, and the streamable handler is mounted next to them with
r.Any("/mcp", ...).

Gates on the merged tree, in a container:

  • go build ./... — ok
  • go test ./internal/router/ ./internal/controller/ — ok, including
    TestRegisterMCPRouterServesStreamableHTTP and TestRegisterMCPRouterKeepsLegacySSETransport
  • golangci-lint run ./internal/router/... ./internal/controller/... (v2.6.2, the version pinned in
    the Makefile) — 0 issues

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

3 participants