Skip to content

refactor: consolidate MCP initialize payload builder and protocol-version constant #106

Description

@salimovartem

Part of #111.

Goal

Eliminate the copy-paste drift between the two initialize response literals (stdio vs HTTP) by extracting a single payload builder and a named protocol-version constant.

Context

The initialize response — protocolVersion, capabilities, serverInfo — is declared twice with the same content: once in plugins/corezoid/mcp-server/mcp_server.go:303-318 for the stdio transport, and once in plugins/corezoid/mcp-server/mcp_http.go:288-303 for the Streamable HTTP transport. The string "2025-03-26" is hardcoded in 9 places across the repo (2 production, 7 tests) with no shared constant. Any change to the response shape has to be applied twice, and there is no build-level guarantee that the two paths stay in sync.

This refactor is a prerequisite for the two follow-up tasks in the same milestone (server/discover handler and UnsupportedProtocolVersionError), both of which need to return the same capabilities as initialize. Consolidating first keeps the follow-ups small and prevents introducing a third divergent copy of the payload.

The repo currently reports itself as legacy-only (spec 2025-03-26) and stays that way in this PR. Do not raise the version.

Scope

In scope:

  • Introduce const mcpProtocolVersion = "2025-03-26" in plugins/corezoid/mcp-server/mcp_server.go, adjacent to the existing mcpServerVersion constant (line 52).
  • Add a helper (suggested name buildInitializeResult()) in mcp_server.go that returns the shared map[string]interface{} result body used by initializeprotocolVersion, capabilities (with tools, resources, prompts), serverInfo.
  • Replace the inline literals in both dispatchers (stdio at mcp_server.go:303-318, HTTP at mcp_http.go:288-303) with a call to the new helper.
  • Switch all seven test-side occurrences of "2025-03-26" to reference the new constant (or, where tests must remain string-literal for readability, add a compile-time assertion / helper). Files: mcp_protocol_test.go (4 occurrences at lines 91, 122, 166, 211), mcp_http_test.go:129, mcp_http_session_test.go:191, mcp_http_session_test.go:382.

Out of scope:

  • Adding server/discover (separate issue).
  • Returning UnsupportedProtocolVersionError on unknown versions (separate issue).
  • Advertising any MCP extensions (Tasks, Apps, ui) — none of them are supported yet.
  • Raising the protocol version above 2025-03-26.
  • Touching Mcp-Session-Id, elicitation, or any other transport-level behaviour.

Files / areas to touch

  • plugins/corezoid/mcp-server/mcp_server.go — add mcpProtocolVersion constant and buildInitializeResult() helper; replace inline literal in the initialize case (line ~297 switch, ~303-318 payload).
  • plugins/corezoid/mcp-server/mcp_http.go — replace inline literal in the initialize case (line ~272 switch, ~288-303 payload) with the shared helper.
  • plugins/corezoid/mcp-server/mcp_protocol_test.go — update lines 91, 122, 166, 211 to use the constant.
  • plugins/corezoid/mcp-server/mcp_http_test.go — update line 129.
  • plugins/corezoid/mcp-server/mcp_http_session_test.go — update lines 191, 382.

Acceptance criteria

  • Exactly one occurrence of the string "2025-03-26" remains in production code — the value of the mcpProtocolVersion constant.
  • The initialize response body is produced by a single function called from both stdio and HTTP dispatchers.
  • TestMCPProtocol_Initialize and TestHTTPDispatch_Initialize pass with no assertion changes (behaviour is byte-identical).
  • Test files no longer hardcode "2025-03-26" in more than one place per file (constant reference is fine).
  • go build ./... and go vet ./... are clean.
  • go test -race ./... passes.

Verification

cd plugins/corezoid/mcp-server
go build ./...
go vet ./...
go test -race -coverprofile=coverage.out ./...
grep -rn '"2025-03-26"' .       # should show 1 hit (the constant definition)

Dependencies

Notes

  • mcpServerVersion (line 52 of mcp_server.go) is the server version (the plugin's 2.3.5), not the protocol version. Do not merge the two — they change on different cadences.
  • The MCP 2026-07-28 spec explicitly lists 2025-03-26 as a valid legacy version and expects legacy servers to keep returning it verbatim in initialize. Do not bump.
  • Keep the helper's return type as map[string]interface{} to avoid churning JSON marshalling for callers; a typed struct is not required at this stage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions