Skip to content

feat(mcp): serve the MCP 2026-07-28 revision with MCP_PROTOCOL=modern - #287

Merged
epugh merged 3 commits into
apache:mainfrom
adityamparikh:feat/mcp-modern-protocol
Nov 24, 2026
Merged

epugh merged 3 commits into
apache:mainfrom
adityamparikh:feat/mcp-modern-protocol

Conversation

@adityamparikh

@adityamparikh adityamparikh commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #286 (Spring Boot 4.2.0 / Spring AI 2.1.0), whose commit is the first one here; review only the second commit.

Summary

Spring AI 2.1 ships a server for the MCP 2026-07-28 revision: no initialize handshake or session, server/discover, _meta on every request, and Mcp-Method/Mcp-Name headers on a single POST /mcp. This makes it selectable with MCP_PROTOCOL=modern. The default stays on the 2025 revisions that today's clients speak, because the two are not wire-compatible.

 application-http.properties
-spring.ai.mcp.server.protocol=stateless
+spring.ai.mcp.server.protocol=${MCP_PROTOCOL:stateless}
 application-stdio.properties
+spring.ai.mcp.server.protocol=${MCP_PROTOCOL:streamable}

Spring AI chooses the server with @ConditionalOnProperty(protocol = MODERN), so the property is the switch. Every tool, resource, prompt and completion, and the @PreAuthorize scopes on tools, are served unchanged in either mode.

HTTP: the CORS allow-list gains Mcp-Method and Mcp-Name, which a browser client sends on every modern request and which would otherwise fail preflight.

STDIO: ModernStdioTransportConfiguration replaces Spring AI's @ConditionalOnMissingBean stdio transport, in modern STDIO mode only:

Spring AI 2.1.0                           this PR
StdioMcpTransportLifecycle.start()        ReadyStdioMcpTransport
  transport.start().subscribe()             start()   → returns the session Mono, reads nothing yet
    reader on daemon threads                on ApplicationReadyEvent
  main returns → JVM exits                    super.start() on a non-daemon keep-alive thread
                                              ends when stdin closes or the context stops

The SDK's StdioMcpTransport.start() javadoc says its threads do not keep the JVM alive and callers should block on the returned Mono; Spring AI's lifecycle only subscribes. Deferring reads to ApplicationReadyEvent also stops a request written at launch from being read before startup completes. The class is meant to be deleted once Spring AI handles both.

docs/modern-protocol.md documents the mode (client-visible changes, CORS, request-state-secret for multiple instances, native images). MCP_PROTOCOL is also listed in the README's environment table, AGENTS.md (transport modes, configuration, native-image notes) and the THREAT_MODEL.md configuration table. dev-docs/ARCHITECTURE.md and dev-docs/graalvm-native-image.md note the revision choice and that native images fix it at build time, docs/security/http.md lists the two new CORS headers, and the CHANGELOG has an entry.

Evidence

The SDK has no 2026-07-28 client yet, so the new tests speak raw JSON-RPC (ModernMcpRequests):

  • McpModernProtocolHttpIntegrationTest: server/discover advertises the revision and every capability; tools/list keeps every tool and its hints; tools/call creates a collection, indexes and searches; resources and templates are readable.

  • McpModernProtocolMethodSecurityTest: an anonymous call to a secured tool is rejected and an authenticated one succeeds.

  • McpModernProtocolStdioIntegrationTest: launches the jar with MCP_PROTOCOL=modern and sends the first request immediately, then server/discover and tools/list.

  • McpInspectorCorsTest: preflight with the modern headers is allowed; an unknown origin is still rejected.

  • Before: Spring AI 2.1.0's own modern STDIO transport exits right after startup, so the first request gets no answer.
    After: ./gradlew build → 468 tests, 0 failures, 0 skipped (the 457 from chore(deps): upgrade to Spring Boot 4.2.0 and Spring AI 2.1.0 #286 plus the 11 above), BUILD SUCCESSFUL.

Merge Danger

Door: two-way

Nothing changes unless MCP_PROTOCOL=modern is set; reverting removes an opt-in mode and one configuration class.

Blast Radius: opt-in

Default HTTP and STDIO behaviour is unchanged. In the native images the condition is fixed when the binary is built, so MCP_PROTOCOL at docker run time has no effect there; the doc says so.

🤖 Generated with Claude Code

@adityamparikh
adityamparikh marked this pull request as draft November 16, 2026 21:04
@adityamparikh
adityamparikh force-pushed the feat/mcp-modern-protocol branch from dfd87d7 to 56c1243 Compare November 20, 2026 23:03
@adityamparikh
adityamparikh marked this pull request as ready for review November 20, 2026 23:03
- Spring Boot 4.1.1 -> 4.2.0, Spring AI 2.0.1 -> 2.1.0.
- Drop the mcp-bom 2.0.1 pin. Spring AI 2.1.0 depends on MCP SDK 2.2.0
  itself, and the pin, declared ahead of spring-ai-bom, would have held
  the SDK back at 2.0.1 under "first declaration wins".
- opentelemetry-logback-appender 2.28.1-alpha -> 2.34.0-alpha, the
  release built against Boot 4.2's OpenTelemetry 1.68.0. The old
  appender left opentelemetry-api-incubator at 1.62.0-alpha, which fails
  OpenTelemetrySdk creation with NoClassDefFoundError:
  io/opentelemetry/api/internal/ConfigUtil.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
@adityamparikh
adityamparikh force-pushed the feat/mcp-modern-protocol branch from 56c1243 to 47df56a Compare November 20, 2026 23:24
Spring AI 2.1.0 ships the modern MCP server for the 2026-07-28 spec
revision: no initialize handshake or session, server/discover, _meta on
every request, and Mcp-Method/Mcp-Name headers on a single POST /mcp.

MCP_PROTOCOL=modern turns it on for the HTTP and STDIO profiles. The
defaults stay on the 2025 revisions (stateless HTTP, streamable STDIO)
because the new revision is not wire-compatible with today's clients.

- Allow the Mcp-Method and Mcp-Name headers in the HTTP CORS config.
- Work around two Spring AI 2.1.0 modern STDIO bugs: the JVM exited right after
  startup because the stdin reader runs on daemon threads, and a request
  sent at launch could be read before the context was ready.
- Add HTTP, method-security and STDIO integration tests that speak raw
  2026-07-28 JSON-RPC, since the SDK has no modern client yet.
- Document the mode in docs/modern-protocol.md, with the setting in the
  README, AGENTS.md, THREAT_MODEL.md, the architecture and native-image
  dev-docs, the HTTP security CORS list and the CHANGELOG.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
@adityamparikh
adityamparikh force-pushed the feat/mcp-modern-protocol branch from 47df56a to 25e96ce Compare November 21, 2026 14:45
@sonarqubecloud

Copy link
Copy Markdown

@epugh
epugh merged commit e132afd into apache:main Nov 24, 2026
2 checks passed
adityamparikh added a commit to adityamparikh/solr-mcp that referenced this pull request Nov 24, 2026
McpModernProtocolMethodSecurityTest arrived with apache#287 and authenticates its caller with only
ROLE_USER, which was enough while list-collections required isAuthenticated(). Under scoped
authorization the tool requires SCOPE_solr:read, so the authenticated call was denied and the
test failed. The stand-in user now carries that scope, and the anonymous case still proves the
modern transport runs the tool on the request thread with its SecurityContext.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>
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.

2 participants