This is an automated email from the ASF dual-hosted git repository.
Croway pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
The following commit(s) were added to refs/heads/main by this push:
new 7f9bb323c3f CAMEL-27174: camel-mcp-server-starter - serve the Camel
routes on the Spring AI server for MCP protocol version 2026-07-28
7f9bb323c3f is described below
commit 7f9bb323c3f00518500dee7336c5e3d74547f458
Author: croway <[email protected]>
AuthorDate: Thu Nov 19 14:34:04 2026 +0100
CAMEL-27174: camel-mcp-server-starter - serve the Camel routes on the
Spring AI server for MCP protocol version 2026-07-28
With spring.ai.mcp.server.protocol=MODERN (Spring AI 2.1), Spring AI
auto-configures the MCP Java SDK server for
protocol version 2026-07-28 instead of an McpSyncServer, so the starter
registered nothing.
- SpringAiModernMcpServerEngine adds the ai-tool, ai-resource and ai-prompt
routes to the in-memory tool, resource and
prompt repositories Spring AI auto-configures, next to the application's
own entries; those repositories tell the
clients listening with subscriptions/listen when a list changes. A route
with the name or URI of an entry already
served is refused, and resource templates are checked for overlaps, as
with the other protocols.
- CamelMcpServerAutoConfiguration also activates on that server (SYNC type
only), and warns when the application
defines its own repository, which Camel cannot add to.
- CamelMcpServerModernTransportAutoConfiguration provides Camel's Origin
validation and caller-identity extraction to
Spring AI's WebMvcModernServerTransport as beans; those of the
application take precedence.
- Docs: "MCP protocol version 2026-07-28" in the starter usage page.
---
.../src/main/doc/usage.adoc | 54 ++-
.../server/CamelMcpServerAutoConfiguration.java | 69 +++-
...lMcpServerModernTransportAutoConfiguration.java | 72 ++++
.../mcp/server/SpringAiModernMcpServerEngine.java | 432 +++++++++++++++++++++
...rk.boot.autoconfigure.AutoConfiguration.imports | 1 +
.../CamelMcpServerAutoConfigurationTest.java | 84 ++++
...ServerModernTransportAutoConfigurationTest.java | 73 ++++
.../mcp/server/SpringBootMcpServerModernTest.java | 293 ++++++++++++++
.../modules/ROOT/pages/starters/mcp-server.adoc | 54 ++-
9 files changed, 1107 insertions(+), 25 deletions(-)
diff --git
a/components-starter/camel-mcp-server-starter/src/main/doc/usage.adoc
b/components-starter/camel-mcp-server-starter/src/main/doc/usage.adoc
index 85660415941..41d08923c61 100644
--- a/components-starter/camel-mcp-server-starter/src/main/doc/usage.adoc
+++ b/components-starter/camel-mcp-server-starter/src/main/doc/usage.adoc
@@ -133,9 +133,10 @@ spring.ai.mcp.server.prompt-change-notification = true
=== Origin validation
Camel's principal-aware HTTP transport is selected only when
-`spring.ai.mcp.server.protocol` is `STREAMABLE` or `STATELESS` (see
-<<_serving_without_sessions>>) and the Camel transport activation condition is
-satisfied:
+`spring.ai.mcp.server.protocol` is `STREAMABLE`, `STATELESS` (see
+<<_serving_without_sessions>>) or `MODERN` (see
+<<_mcp_protocol_version_2026_07_28>>) and the Camel transport activation
+condition is satisfied:
* By default, the Camel provider is selected when `camel.mcp-server.tags` is
configured. This enables the Origin validator and authenticated caller
@@ -181,8 +182,8 @@ If Camel tags or Origin settings are configured while the
Spring AI protocol
is unset or uses SSE, the Camel HTTP transport is not installed.
The starter logs a warning because Origin validation and caller-context
extraction are not active in that configuration. Select
-`spring.ai.mcp.server.protocol=STREAMABLE` (or `STATELESS`) when those
-protections are required.
+`spring.ai.mcp.server.protocol=STREAMABLE` (or `STATELESS` or `MODERN`) when
+those protections are required.
With the Spring AI 2.0.2 WebMVC transport, an Origin rejection currently
returns HTTP 403 with a plain-text `Invalid Origin header` response body.
@@ -278,8 +279,47 @@ request:
The stateless mode serves the MCP protocol versions that open with an
`initialize` handshake (2025-11-25 and earlier). Protocol version 2026-07-28,
-which has no session by design, is not served by this starter yet: it needs
-Spring AI 2.1.0.
+which has no session by design, is served with `MODERN`.
+
+=== MCP protocol version 2026-07-28
+
+With `spring.ai.mcp.server.protocol=MODERN`, Spring AI serves MCP protocol
+version 2026-07-28, and the starter adds the Camel routes to that server. A
+client of 2026-07-28 has no handshake and no session: every request carries its
+protocol version and is served on its own, so a restart or another instance is
+invisible to the client. Unlike with `STATELESS`, the client is still told
about
+changes: when a Camel route adds or removes a tool, resource or prompt, a
client
+listening with a `subscriptions/listen` request receives the list change.
+
+[source,properties]
+----
+spring.ai.mcp.server.protocol = MODERN
+camel.mcp-server.tags = crm
+----
+
+The Camel routes are added to the tool, resource and prompt repositories that
+Spring AI auto-configures, next to the application's own tools, resources and
+prompts. A Camel route with the name or URI of one of them is refused, as with
+the other protocols. Camel's Origin validation and caller-context extraction
+apply to every request: the starter provides them to Spring AI's
+`WebMvcModernServerTransport` as `ServerHttpHeaderValidator` and
+`McpTransportContextExtractor` beans, and beans of those types defined by the
+application take precedence.
+
+Be aware that:
+
+* Spring AI serves one protocol per application: with `MODERN`, a client that
+ opens with an `initialize` handshake (protocol version 2025-11-25 and
+ earlier) is answered with HTTP 400 and cannot connect. Clients that try
+ 2026-07-28 first and fall back to `initialize` connect with 2026-07-28. Camel
+ Main and Camel JBang serve both kinds of client on the same endpoint (see
+ xref:components:others:mcp-server.adoc[MCP Server]);
+* only `spring.ai.mcp.server.type=SYNC`, the default, is supported: with
+ `ASYNC`, the starter does not register the Camel routes;
+* if the application defines its own tool, resource or prompt repository, the
+ Camel routes of that kind are not served, and the starter logs a warning;
+* protocol version 2026-07-28 is built on the `io.modelcontextprotocol.modern`
+ API of the MCP Java SDK, which may still change in minor releases.
=== Connecting MCP clients
diff --git
a/components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/CamelMcpServerAutoConfiguration.java
b/components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/CamelMcpServerAutoConfiguration.java
index 3b22b53dcc2..48695b9c09e 100644
---
a/components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/CamelMcpServerAutoConfiguration.java
+++
b/components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/CamelMcpServerAutoConfiguration.java
@@ -16,6 +16,10 @@
*/
package org.apache.camel.springboot.mcp.server;
+import io.modelcontextprotocol.modern.server.McpServer;
+import io.modelcontextprotocol.modern.server.feature.McpSyncPromptRepository;
+import io.modelcontextprotocol.modern.server.feature.McpSyncResourceRepository;
+import io.modelcontextprotocol.modern.server.feature.McpSyncToolRepository;
import io.modelcontextprotocol.server.McpStatelessSyncServer;
import io.modelcontextprotocol.server.McpSyncServer;
import org.apache.camel.CamelContext;
@@ -25,6 +29,9 @@ import org.apache.camel.component.mcp.server.McpServerEngine;
import org.apache.camel.spring.boot.CamelAutoConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.ai.mcp.modern.InMemorySyncPromptRepository;
+import org.springframework.ai.mcp.modern.InMemorySyncResourceRepository;
+import org.springframework.ai.mcp.modern.InMemorySyncToolRepository;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
@@ -40,12 +47,14 @@ import org.springframework.util.StringUtils;
/**
* Auto-configures the Camel MCP server bridge over the Spring AI MCP server:
every ai-tool route whose tags match
* {@code camel.mcp-server.tags} is exposed as an MCP tool of the
auto-configured {@link McpSyncServer}, or of the
- * {@link McpStatelessSyncServer} when {@code
spring.ai.mcp.server.protocol=STATELESS}.
+ * {@link McpStatelessSyncServer} when {@code
spring.ai.mcp.server.protocol=STATELESS}, or of the server for MCP
+ * protocol version 2026-07-28 when {@code
spring.ai.mcp.server.protocol=MODERN}.
*/
@AutoConfiguration(after = CamelAutoConfiguration.class,
afterName = {
"org.springframework.ai.mcp.server.common.autoconfigure.McpServerAutoConfiguration",
-
"org.springframework.ai.mcp.server.common.autoconfigure.McpServerStatelessAutoConfiguration"
})
+
"org.springframework.ai.mcp.server.common.autoconfigure.McpServerStatelessAutoConfiguration",
+
"org.springframework.ai.mcp.server.common.autoconfigure.McpServerModernAutoConfiguration"
})
@Conditional(CamelMcpServerAutoConfiguration.OnSpringAiMcpServerCondition.class)
@ConditionalOnProperty(value = "camel.mcp-server.enabled", matchIfMissing =
true)
@EnableConfigurationProperties(McpServerConfigurationProperties.class)
@@ -57,11 +66,40 @@ public class CamelMcpServerAutoConfiguration {
// Camel handles the lifecycle of this bean
@ConditionalOnMissingBean(McpServerEngine.class)
McpServerEngine camelMcpServerEngine(
- ObjectProvider<McpSyncServer> mcpSyncServer,
ObjectProvider<McpStatelessSyncServer> mcpStatelessSyncServer) {
+ ObjectProvider<McpSyncServer> mcpSyncServer,
ObjectProvider<McpStatelessSyncServer> mcpStatelessSyncServer,
+ ObjectProvider<McpSyncToolRepository> toolRepository,
+ ObjectProvider<McpSyncResourceRepository> resourceRepository,
+ ObjectProvider<McpSyncPromptRepository> promptRepository) {
McpSyncServer server = mcpSyncServer.getIfAvailable();
- return server != null
- ? new SpringAiMcpServerEngine(server)
- : new
SpringAiMcpServerEngine(mcpStatelessSyncServer.getObject());
+ if (server != null) {
+ return new SpringAiMcpServerEngine(server);
+ }
+ McpStatelessSyncServer statelessServer =
mcpStatelessSyncServer.getIfAvailable();
+ if (statelessServer != null) {
+ return new SpringAiMcpServerEngine(statelessServer);
+ }
+ return new SpringAiModernMcpServerEngine(
+ inMemoryRepository(toolRepository,
InMemorySyncToolRepository.class, "tools", "ai-tool"),
+ inMemoryRepository(resourceRepository,
InMemorySyncResourceRepository.class, "resources",
+ "ai-resource"),
+ inMemoryRepository(promptRepository,
InMemorySyncPromptRepository.class, "prompts", "ai-prompt"));
+ }
+
+ /**
+ * The in-memory repository Spring AI auto-configured for the server of
MCP protocol version 2026-07-28, which the
+ * Camel routes are added to; null when the server serves none of these,
or serves them from a repository of the
+ * application, which Camel cannot add to.
+ */
+ private static <R, T extends R> T inMemoryRepository(
+ ObjectProvider<R> repository, Class<T> inMemoryType, String kind,
String routes) {
+ R available = repository.getIfAvailable();
+ if (available == null || inMemoryType.isInstance(available)) {
+ return inMemoryType.cast(available);
+ }
+ LOG.warn("The Spring AI MCP server serves its {} from {}, a repository
of the application: Camel {} routes"
+ + " cannot be added to it and are not served.",
+ kind, available.getClass().getName(), routes);
+ return null;
}
@Bean(initMethod = "", destroyMethod = "")
@@ -99,11 +137,12 @@ public class CamelMcpServerAutoConfiguration {
}
String protocol =
environment.getProperty("spring.ai.mcp.server.protocol");
- if (!"STREAMABLE".equalsIgnoreCase(protocol) &&
!"STATELESS".equalsIgnoreCase(protocol)) {
+ if (!"STREAMABLE".equalsIgnoreCase(protocol) &&
!"STATELESS".equalsIgnoreCase(protocol)
+ && !"MODERN".equalsIgnoreCase(protocol)) {
LOG.warn("Camel MCP routes or Origin settings are configured, but "
- + "spring.ai.mcp.server.protocol is neither STREAMABLE
nor STATELESS. Camel's Origin validation "
- + "and authenticated caller-context extraction are not
active; configure "
- + "spring.ai.mcp.server.protocol=STREAMABLE or STATELESS
to enable them.");
+ + "spring.ai.mcp.server.protocol is not STREAMABLE,
STATELESS or MODERN. Camel's Origin "
+ + "validation and authenticated caller-context extraction
are not active; configure "
+ + "spring.ai.mcp.server.protocol=STREAMABLE, STATELESS or
MODERN to enable them.");
return;
}
@@ -120,7 +159,7 @@ public class CamelMcpServerAutoConfiguration {
/**
* Matches when Spring AI auto-configured a synchronous MCP server: with
sessions ({@code SSE},
- * {@code STREAMABLE}) or stateless ({@code STATELESS}).
+ * {@code STREAMABLE}), stateless ({@code STATELESS}), or for MCP protocol
version 2026-07-28 ({@code MODERN}).
*/
static final class OnSpringAiMcpServerCondition extends AnyNestedCondition
{
@@ -135,6 +174,14 @@ public class CamelMcpServerAutoConfiguration {
@ConditionalOnBean(McpStatelessSyncServer.class)
static final class OnStatelessServer {
}
+
+ // the server of 2026-07-28 is the same bean for both API types: the
Camel routes need the synchronous
+ // repositories
+ @ConditionalOnBean(McpServer.class)
+ @ConditionalOnProperty(prefix = "spring.ai.mcp.server", name = "type",
havingValue = "SYNC",
+ matchIfMissing = true)
+ static final class OnModernServer {
+ }
}
}
diff --git
a/components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/CamelMcpServerModernTransportAutoConfiguration.java
b/components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/CamelMcpServerModernTransportAutoConfiguration.java
new file mode 100644
index 00000000000..47756755d36
--- /dev/null
+++
b/components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/CamelMcpServerModernTransportAutoConfiguration.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.springboot.mcp.server;
+
+import io.modelcontextprotocol.server.McpTransportContextExtractor;
+import io.modelcontextprotocol.server.transport.ServerHttpHeaderValidator;
+import
org.springframework.ai.mcp.server.common.autoconfigure.McpServerStdioDisabledCondition;
+import
org.springframework.ai.mcp.server.webmvc.transport.WebMvcModernServerTransport;
+import org.springframework.boot.autoconfigure.AutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import
org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.web.servlet.function.ServerRequest;
+
+/**
+ * Adds Camel's Origin validation and the authenticated caller identity to the
Spring AI WebMVC transport of MCP
+ * protocol version 2026-07-28 ({@code spring.ai.mcp.server.protocol=MODERN}),
the counterpart of
+ * {@link CamelMcpServerTransportAutoConfiguration} for the Streamable HTTP
transport.
+ * <p>
+ * Spring AI builds that transport with the {@link ServerHttpHeaderValidator}
and the
+ * {@link McpTransportContextExtractor} beans of the application context, so
this configuration provides them and
+ * keeps Spring AI's endpoint and settings. A validator or an extractor of the
application takes precedence, and so
+ * does a {@link WebMvcModernServerTransport} of the application.
+ */
+@AutoConfiguration(
+ beforeName =
"org.springframework.ai.mcp.server.webmvc.autoconfigure.McpServerModernWebMvcAutoConfiguration")
+@ConditionalOnClass(WebMvcModernServerTransport.class)
+@Conditional({
+ McpServerStdioDisabledCondition.class,
+ CamelMcpServerTransportCondition.class
+})
+@ConditionalOnProperty(
+ prefix = "camel.mcp-server",
+ name = "enabled",
+ matchIfMissing = true)
+@ConditionalOnProperty(
+ prefix = "spring.ai.mcp.server",
+ name = "protocol",
+ havingValue = "MODERN",
+ matchIfMissing = false)
+@EnableConfigurationProperties(McpServerConfigurationProperties.class)
+public class CamelMcpServerModernTransportAutoConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean
+ ServerHttpHeaderValidator
camelMcpServerHttpHeaderValidator(McpServerConfigurationProperties
camelProperties) {
+ return
CamelMcpServerTransportAutoConfiguration.createOriginHeaderValidator(camelProperties.getAllowedOrigins());
+ }
+
+ @Bean
+ @ConditionalOnMissingBean
+ McpTransportContextExtractor<ServerRequest>
camelMcpServerContextExtractor() {
+ return SpringAiMcpTransportContext::extract;
+ }
+}
diff --git
a/components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/SpringAiModernMcpServerEngine.java
b/components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/SpringAiModernMcpServerEngine.java
new file mode 100644
index 00000000000..9c5e8928e91
--- /dev/null
+++
b/components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/SpringAiModernMcpServerEngine.java
@@ -0,0 +1,432 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.springboot.mcp.server;
+
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import io.modelcontextprotocol.json.McpJsonDefaults;
+import io.modelcontextprotocol.json.McpJsonMapper;
+import io.modelcontextprotocol.modern.McpException;
+import io.modelcontextprotocol.modern.McpSchema;
+import io.modelcontextprotocol.modern.McpSchema.ErrorCodes;
+import io.modelcontextprotocol.modern.server.McpSyncResponse;
+import io.modelcontextprotocol.modern.server.feature.McpSyncPrompt;
+import io.modelcontextprotocol.modern.server.feature.McpSyncTool;
+import io.modelcontextprotocol.modern.server.feature.ResourceTemplatesPage;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.ai.resource.AiResourceUriTemplate;
+import org.apache.camel.component.ai.tool.AiToolAnnotations;
+import org.apache.camel.component.mcp.server.McpPromptMessage;
+import org.apache.camel.component.mcp.server.McpPromptResult;
+import org.apache.camel.component.mcp.server.McpResourceReadResult;
+import org.apache.camel.component.mcp.server.McpServerEngine;
+import org.apache.camel.component.mcp.server.McpServerInfo;
+import org.apache.camel.component.mcp.server.McpServerPrompt;
+import org.apache.camel.component.mcp.server.McpServerRefusedException;
+import org.apache.camel.component.mcp.server.McpServerResource;
+import org.apache.camel.component.mcp.server.McpServerResourceTemplate;
+import org.apache.camel.component.mcp.server.McpServerTool;
+import org.apache.camel.component.mcp.server.McpToolCallResult;
+import org.apache.camel.support.service.ServiceSupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.ai.mcp.modern.InMemorySyncPromptRepository;
+import org.springframework.ai.mcp.modern.InMemorySyncResourceRepository;
+import org.springframework.ai.mcp.modern.InMemorySyncToolRepository;
+import org.springframework.ai.mcp.modern.SyncResourceRegistration;
+import org.springframework.ai.mcp.modern.SyncResourceTemplateRegistration;
+
+/**
+ * Publishes the Camel {@code ai-tool}, {@code ai-resource} and {@code
ai-prompt} routes into the Spring AI MCP server
+ * for protocol version 2026-07-28 ({@code
spring.ai.mcp.server.protocol=MODERN}).
+ * <p>
+ * That server has no session: it takes its tools, resources and prompts from
repositories. The routes go into the
+ * in-memory repositories Spring AI auto-configures, next to the application's
own tools, resources and prompts, and
+ * those repositories tell the clients listening with {@code
subscriptions/listen} when a list changes. A route with the
+ * name or URI of an entry already served is refused. A repository the
application defines itself cannot be added to,
+ * so the routes of that kind are refused too.
+ * <p>
+ * The conversions mirror {@link SpringAiMcpServerEngine}, with the types of
the 2026-07-28 schema of the MCP Java SDK.
+ */
+public class SpringAiModernMcpServerEngine extends ServiceSupport implements
McpServerEngine {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(SpringAiModernMcpServerEngine.class);
+
+ private static final String EMPTY_OBJECT_SCHEMA = """
+ {
+ "type": "object",
+ "properties": {},
+ "additionalProperties": false
+ }
+ """;
+
+ private final InMemorySyncToolRepository tools;
+ private final InMemorySyncResourceRepository resources;
+ private final InMemorySyncPromptRepository prompts;
+ private final McpJsonMapper jsonMapper = McpJsonDefaults.getMapper();
+ private CamelContext camelContext;
+
+ /**
+ * @param tools the repository the tools are added to, or null when
the server serves no Camel tools
+ * @param resources the repository the resources and resource templates
are added to, or null when the server
+ * serves no Camel resources
+ * @param prompts the repository the prompts are added to, or null when
the server serves no Camel prompts
+ */
+ public SpringAiModernMcpServerEngine(
+ InMemorySyncToolRepository tools, InMemorySyncResourceRepository
resources,
+ InMemorySyncPromptRepository prompts) {
+ this.tools = tools;
+ this.resources = resources;
+ this.prompts = prompts;
+ }
+
+ @Override
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ @Override
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ @Override
+ public void initialize(McpServerInfo info) {
+ // serving identity is owned by spring.ai.mcp.server.*; the hint is
deliberately ignored
+ LOG.debug("Spring AI MCP server engine for protocol version 2026-07-28
initialized; serving configuration is"
+ + " owned by spring.ai.mcp.server.*");
+ }
+
+ // ---- tools
+
+ @Override
+ public void toolAdded(McpServerTool tool) {
+ if (tools == null) {
+ throw new McpServerRefusedException(
+ "MCP tool '" + tool.name() + "' is not served: the Spring
AI MCP server serves no tools, or"
+ + " serves them from a
repository of the application");
+ }
+ McpSchema.Tool definition;
+ try {
+ definition = buildTool(tool);
+ } catch (IllegalArgumentException e) {
+ throw new McpServerRefusedException(
+ "MCP tool '" + tool.name() + "' has an invalid input or
output schema: " + e.getMessage(), e);
+ }
+ try {
+ tools.add(McpSyncTool.of(definition, (ctx, request) -> {
+ Map<String, Object> arguments = request.arguments() != null ?
request.arguments() : Map.of();
+ McpToolCallResult result = tool.handler().call(
+ arguments,
SpringAiMcpTransportContext.from(ctx.transportContext()));
+ McpSchema.CallToolResult.Builder builder =
McpSchema.CallToolResult.builder()
+
.addContent(McpSchema.TextContent.builder(result.text()).build())
+ .isError(result.isError());
+ if (result.structuredContent() != null) {
+ builder.structuredContent(result.structuredContent());
+ }
+ return McpSyncResponse.result(builder.build());
+ }));
+ } catch (IllegalArgumentException e) {
+ throw new McpServerRefusedException("An MCP tool named '" +
tool.name() + "' is already registered", e);
+ }
+ LOG.debug("MCP tool added: {}", tool.name());
+ }
+
+ @Override
+ public void toolRemoved(String toolName) {
+ if (tools != null && tools.remove(toolName)) {
+ LOG.debug("MCP tool removed: {}", toolName);
+ }
+ }
+
+ private McpSchema.Tool buildTool(McpServerTool tool) {
+ String schema = tool.inputSchemaJson() != null ?
tool.inputSchemaJson() : EMPTY_OBJECT_SCHEMA;
+ McpSchema.Tool.Builder builder = McpSchema.Tool.builder(tool.name(),
jsonMapper, schema)
+ .description(tool.description());
+ if (tool.outputSchemaJson() != null &&
!tool.outputSchemaJson().isBlank()) {
+ builder.outputSchema(jsonMapper, tool.outputSchemaJson());
+ }
+ AiToolAnnotations annotations = tool.annotations();
+ if (annotations != null) {
+ if (annotations.title() != null) {
+ builder.title(annotations.title());
+ }
+ // returnDirect is not part of the 2026-07-28 tool annotations;
unset hints are not published, so MCP
+ // clients apply their own spec defaults
+ if (annotations.readOnlyHint() != null ||
annotations.destructiveHint() != null
+ || annotations.idempotentHint() != null ||
annotations.openWorldHint() != null) {
+ builder.annotations(McpSchema.ToolAnnotations.builder()
+ .readOnlyHint(annotations.readOnlyHint())
+ .destructiveHint(annotations.destructiveHint())
+ .idempotentHint(annotations.idempotentHint())
+ .openWorldHint(annotations.openWorldHint())
+ .build());
+ }
+ }
+ return builder.build();
+ }
+
+ // ---- resources and resource templates
+
+ @Override
+ public void resourceAdded(McpServerResource resource) {
+ if (resources == null) {
+ throw new McpServerRefusedException(
+ "MCP resource '" + resource.uri() + "' is not served: the
Spring AI MCP server serves no"
+ + " resources, or serves them
from a repository of the application");
+ }
+ McpSchema.Resource.Builder builder =
McpSchema.Resource.builder(resource.uri(), resource.name())
+ .description(resource.description())
+ .mimeType(resource.mimeType());
+ if (resource.title() != null && !resource.title().isBlank()) {
+ builder.title(resource.title());
+ }
+ try {
+ resources.add(SyncResourceRegistration.of(builder.build(), (ctx,
request) -> McpSyncResponse.result(
+ readResult(resource.uri(), resource.mimeType(),
resource.handler().read()))));
+ } catch (IllegalArgumentException e) {
+ throw new McpServerRefusedException(
+ "An MCP resource with URI '" + resource.uri() + "' is
already registered", e);
+ }
+ LOG.debug("MCP resource added: {}", resource.uri());
+ }
+
+ @Override
+ public void resourceRemoved(String resourceUri) {
+ if (resources != null && resources.remove(resourceUri)) {
+ LOG.debug("MCP resource removed: {}", resourceUri);
+ }
+ }
+
+ @Override
+ public boolean supportsResources() {
+ return resources != null;
+ }
+
+ @Override
+ public void resourceTemplateAdded(McpServerResourceTemplate
resourceTemplate) {
+ String uriTemplate = resourceTemplate.uriTemplate();
+ if (resources == null) {
+ throw new McpServerRefusedException(
+ "MCP resource template '" + uriTemplate + "' is not
served: the Spring AI MCP server serves no"
+ + " resources, or serves them
from a repository of the application");
+ }
+ List<McpSchema.ResourceTemplate> existingTemplates =
listResourceTemplates();
+ if (existingTemplates.stream().anyMatch(existing ->
existing.uriTemplate().equals(uriTemplate))) {
+ throw new McpServerRefusedException(
+ "An MCP resource template '" + uriTemplate + "' is already
registered");
+ }
+ checkNoOverlap(uriTemplate, existingTemplates);
+
+ McpSchema.ResourceTemplate.Builder builder =
McpSchema.ResourceTemplate.builder(uriTemplate,
+ resourceTemplate.name())
+ .description(resourceTemplate.description())
+ .mimeType(resourceTemplate.mimeType());
+ if (resourceTemplate.title() != null &&
!resourceTemplate.title().isBlank()) {
+ builder.title(resourceTemplate.title());
+ }
+ try {
+ resources.add(SyncResourceTemplateRegistration.of(builder.build(),
+ (ctx, request) ->
McpSyncResponse.result(readResult(request.uri(), resourceTemplate.mimeType(),
+ resourceTemplate.handler().read(request.uri())))));
+ } catch (IllegalArgumentException e) {
+ throw new McpServerRefusedException(
+ "MCP resource template '" + uriTemplate + "' cannot be
registered: " + e.getMessage(), e);
+ }
+ LOG.debug("MCP resource template added: {}", uriTemplate);
+ }
+
+ @Override
+ public void resourceTemplateRemoved(String uriTemplate) {
+ if (resources != null && resources.remove(uriTemplate)) {
+ LOG.debug("MCP resource template removed: {}", uriTemplate);
+ }
+ }
+
+ @Override
+ public boolean supportsResourceTemplates() {
+ return resources != null;
+ }
+
+ /**
+ * All the resource templates served, the application's included, across
the pages of the repository.
+ */
+ private List<McpSchema.ResourceTemplate> listResourceTemplates() {
+ List<McpSchema.ResourceTemplate> all = new ArrayList<>();
+ String cursor = null;
+ do {
+ // the in-memory repository does not read the request context
+ ResourceTemplatesPage page = resources.listTemplates(null, cursor);
+ all.addAll(page.resourceTemplates());
+ cursor = page.nextCursor();
+ } while (cursor != null);
+ return all;
+ }
+
+ /**
+ * Refuses a template that matches a URI another template matches, as
{@link SpringAiMcpServerEngine} does: which
+ * template a read goes to would otherwise depend on the order the
templates were registered in.
+ */
+ private static void checkNoOverlap(String uriTemplate,
List<McpSchema.ResourceTemplate> existingTemplates) {
+ AiResourceUriTemplate candidate;
+ try {
+ candidate = new AiResourceUriTemplate(uriTemplate);
+ } catch (IllegalArgumentException e) {
+ throw new McpServerRefusedException(
+ "Invalid MCP resource template '" + uriTemplate + "': " +
e.getMessage(), e);
+ }
+ for (McpSchema.ResourceTemplate existing : existingTemplates) {
+ AiResourceUriTemplate existingMatcher;
+ try {
+ existingMatcher = new
AiResourceUriTemplate(existing.uriTemplate());
+ } catch (IllegalArgumentException e) {
+ String candidateScheme = uriScheme(uriTemplate);
+ String existingScheme = uriScheme(existing.uriTemplate());
+ // a template of the application in a syntax Camel does not
support cannot overlap a Camel template
+ // of another scheme; for the same or an unknown scheme, refuse
+ if (candidateScheme != null && existingScheme != null
+ && !candidateScheme.equalsIgnoreCase(existingScheme)) {
+ LOG.warn("Skipping overlap check between MCP resource
template '{}' and unsupported Spring"
+ + " template '{}' because their URI schemes
differ",
+ uriTemplate, existing.uriTemplate());
+ continue;
+ }
+ throw new McpServerRefusedException(
+ "Cannot safely check whether MCP resource template '"
+ uriTemplate
+ + "' overlaps existing
Spring template '" + existing.uriTemplate()
+ + "'",
+ e);
+ }
+ if (candidate.overlaps(existingMatcher)) {
+ throw new McpServerRefusedException(
+ "MCP resource template '" + uriTemplate + "' overlaps
existing template '"
+ + existing.uriTemplate() +
"'");
+ }
+ }
+ }
+
+ private static String uriScheme(String uriTemplate) {
+ int colon = uriTemplate.indexOf(':');
+ if (colon <= 0) {
+ return null;
+ }
+ String scheme = uriTemplate.substring(0, colon);
+ return scheme.matches("[A-Za-z][A-Za-z0-9+.-]*") ? scheme : null;
+ }
+
+ private static McpSchema.ReadResourceResult readResult(String uri, String
mimeType, McpResourceReadResult result) {
+ if (result.isError()) {
+ throw new McpException(ErrorCodes.INTERNAL_ERROR,
result.errorMessage());
+ }
+ McpSchema.ResourceContents contents;
+ if (result.blob() != null) {
+ contents = McpSchema.BlobResourceContents.builder(uri,
Base64.getEncoder().encodeToString(result.blob()))
+ .mimeType(mimeType)
+ .build();
+ } else {
+ contents = McpSchema.TextResourceContents.builder(uri,
result.text()).mimeType(mimeType).build();
+ }
+ return McpSchema.ReadResourceResult.builder(List.of(contents)).build();
+ }
+
+ // ---- prompts
+
+ @Override
+ public void promptAdded(McpServerPrompt prompt) {
+ if (prompts == null) {
+ throw new McpServerRefusedException(
+ "MCP prompt '" + prompt.name() + "' is not served: the
Spring AI MCP server serves no prompts,"
+ + " or serves them from a
repository of the application");
+ }
+ McpSchema.Prompt.Builder builder =
McpSchema.Prompt.builder(prompt.name())
+ .description(prompt.description())
+ .arguments(prompt.arguments().stream()
+ .map(argument ->
McpSchema.PromptArgument.builder(argument.name())
+ .description(argument.description())
+ .required(argument.required())
+ .build())
+ .toList());
+ if (prompt.title() != null && !prompt.title().isBlank()) {
+ builder.title(prompt.title());
+ }
+ try {
+ prompts.add(McpSyncPrompt.of(builder.build(), (ctx, request) ->
getPrompt(prompt, request)));
+ } catch (IllegalArgumentException e) {
+ throw new McpServerRefusedException("An MCP prompt named '" +
prompt.name() + "' is already registered", e);
+ }
+ LOG.debug("MCP prompt added: {}", prompt.name());
+ }
+
+ @Override
+ public void promptRemoved(String promptName) {
+ if (prompts != null && prompts.remove(promptName)) {
+ LOG.debug("MCP prompt removed: {}", promptName);
+ }
+ }
+
+ @Override
+ public boolean supportsPrompts() {
+ return prompts != null;
+ }
+
+ private McpSyncResponse<McpSchema.GetPromptOutcome> getPrompt(
+ McpServerPrompt prompt, McpSchema.GetPromptRequest request) {
+ Map<String, String> arguments = request.arguments() != null ?
request.arguments() : Map.of();
+ McpPromptResult result = prompt.handler().get(arguments);
+ if (result == null) {
+ throw new McpException(ErrorCodes.INTERNAL_ERROR, "Prompt
execution failed");
+ }
+ if (result.isError()) {
+ throw new McpException(
+ result.argumentError() ? ErrorCodes.INVALID_PARAMS :
ErrorCodes.INTERNAL_ERROR,
+ result.errorMessage());
+ }
+ List<McpSchema.PromptMessage> messages =
result.messages().stream().map(this::toPromptMessage).toList();
+ return McpSyncResponse.result(
+
McpSchema.GetPromptResult.builder(messages).description(result.description()).build());
+ }
+
+ private McpSchema.PromptMessage toPromptMessage(McpPromptMessage message) {
+ McpSchema.Role role;
+ try {
+ role =
McpSchema.Role.valueOf(message.role().toUpperCase(Locale.ROOT));
+ } catch (RuntimeException e) {
+ throw new McpException(ErrorCodes.INTERNAL_ERROR, "Prompt returned
an invalid message role");
+ }
+ Object value = message.content();
+ McpSchema.Content content;
+ if (value instanceof String text) {
+ content = McpSchema.TextContent.builder(text).build();
+ } else if (value instanceof McpSchema.Content modern) {
+ content = modern;
+ } else if (value != null) {
+ // a map, or a content block of the MCP SDK's other schema: both
have the same JSON form
+ try {
+ content = jsonMapper.convertValue(value,
McpSchema.Content.class);
+ } catch (RuntimeException e) {
+ throw new McpException(ErrorCodes.INTERNAL_ERROR, "Prompt
returned an invalid MCP content block");
+ }
+ } else {
+ throw new McpException(ErrorCodes.INTERNAL_ERROR, "Prompt returned
an unsupported content value");
+ }
+ return McpSchema.PromptMessage.builder(role, content).build();
+ }
+}
diff --git
a/components-starter/camel-mcp-server-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
b/components-starter/camel-mcp-server-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
index 00dee30b4c7..9bc92faa4a7 100644
---
a/components-starter/camel-mcp-server-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
+++
b/components-starter/camel-mcp-server-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -17,3 +17,4 @@
org.apache.camel.springboot.mcp.server.CamelMcpServerAutoConfiguration
org.apache.camel.springboot.mcp.server.CamelMcpServerTransportAutoConfiguration
org.apache.camel.springboot.mcp.server.CamelMcpServerStatelessTransportAutoConfiguration
+org.apache.camel.springboot.mcp.server.CamelMcpServerModernTransportAutoConfiguration
diff --git
a/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/CamelMcpServerAutoConfigurationTest.java
b/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/CamelMcpServerAutoConfigurationTest.java
index d7f70c20109..1f17cb0a47f 100644
---
a/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/CamelMcpServerAutoConfigurationTest.java
+++
b/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/CamelMcpServerAutoConfigurationTest.java
@@ -16,18 +16,26 @@
*/
package org.apache.camel.springboot.mcp.server;
+import io.modelcontextprotocol.modern.server.McpServer;
+import io.modelcontextprotocol.modern.server.feature.McpSyncToolRepository;
import io.modelcontextprotocol.server.McpSyncServer;
import org.apache.camel.component.mcp.server.McpServerBridge;
import org.apache.camel.component.mcp.server.McpServerEngine;
+import org.apache.camel.component.mcp.server.McpServerRefusedException;
+import org.apache.camel.component.mcp.server.McpServerTool;
import org.apache.camel.spring.boot.CamelAutoConfiguration;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
+import org.springframework.ai.mcp.modern.InMemorySyncPromptRepository;
+import org.springframework.ai.mcp.modern.InMemorySyncResourceRepository;
+import org.springframework.ai.mcp.modern.InMemorySyncToolRepository;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
class CamelMcpServerAutoConfigurationTest {
@@ -43,6 +51,45 @@ class CamelMcpServerAutoConfigurationTest {
}
}
+ /**
+ * What Spring AI auto-configures for {@code
spring.ai.mcp.server.protocol=MODERN}.
+ */
+ @Configuration
+ static class McpModernServerConfiguration {
+ @Bean
+ McpServer mcpModernServer() {
+ return Mockito.mock(McpServer.class);
+ }
+
+ @Bean
+ InMemorySyncToolRepository mcpModernToolRepository() {
+ return InMemorySyncToolRepository.builder().build();
+ }
+
+ @Bean
+ InMemorySyncResourceRepository mcpModernResourceRepository() {
+ return InMemorySyncResourceRepository.builder().build();
+ }
+
+ @Bean
+ InMemorySyncPromptRepository mcpModernPromptRepository() {
+ return InMemorySyncPromptRepository.builder().build();
+ }
+ }
+
+ @Configuration
+ static class McpModernServerWithApplicationToolRepositoryConfiguration {
+ @Bean
+ McpServer mcpModernServer() {
+ return Mockito.mock(McpServer.class);
+ }
+
+ @Bean
+ McpSyncToolRepository applicationToolRepository() {
+ return Mockito.mock(McpSyncToolRepository.class);
+ }
+ }
+
@Test
void testBridgeAndEngineConfiguredByDefault() {
runner.withUserConfiguration(McpSyncServerConfiguration.class)
@@ -64,6 +111,43 @@ class CamelMcpServerAutoConfigurationTest {
});
}
+ @Test
+ void testModernServerUsesItsInMemoryRepositories() {
+ runner.withUserConfiguration(McpModernServerConfiguration.class)
+ .withPropertyValues("camel.mcp-server.tags=crm")
+ .run(context -> {
+
assertThat(context).getBean(McpServerEngine.class).isInstanceOf(SpringAiModernMcpServerEngine.class);
+ McpServerEngine engine =
context.getBean(McpServerEngine.class);
+ assertThat(engine.supportsResources()).isTrue();
+ assertThat(engine.supportsResourceTemplates()).isTrue();
+ assertThat(engine.supportsPrompts()).isTrue();
+ assertThat(context).hasSingleBean(McpServerBridge.class);
+ });
+ }
+
+ @Test
+ void testModernServerOfTheAsyncTypeIsNotServed() {
+ runner.withUserConfiguration(McpModernServerConfiguration.class)
+ .withPropertyValues("camel.mcp-server.tags=crm",
"spring.ai.mcp.server.type=ASYNC")
+ .run(context ->
assertThat(context).doesNotHaveBean(McpServerEngine.class));
+ }
+
+ @Test
+ void testModernServerRefusesToolsWhenTheApplicationDefinesTheRepository() {
+
runner.withUserConfiguration(McpModernServerWithApplicationToolRepositoryConfiguration.class)
+ .withPropertyValues("camel.mcp-server.tags=crm")
+ .run(context -> {
+ McpServerEngine engine =
context.getBean(McpServerEngine.class);
+ McpServerTool tool = Mockito.mock(McpServerTool.class);
+ Mockito.when(tool.name()).thenReturn("crm_lookup");
+ assertThatThrownBy(() -> engine.toolAdded(tool))
+ .isInstanceOf(McpServerRefusedException.class)
+ .hasMessageContaining("crm_lookup");
+ assertThat(engine.supportsResources()).isFalse();
+ assertThat(engine.supportsPrompts()).isFalse();
+ });
+ }
+
@Test
void testBacksOffWithoutMcpSyncServer() {
runner.run(context -> {
diff --git
a/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/CamelMcpServerModernTransportAutoConfigurationTest.java
b/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/CamelMcpServerModernTransportAutoConfigurationTest.java
new file mode 100644
index 00000000000..a02985d6085
--- /dev/null
+++
b/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/CamelMcpServerModernTransportAutoConfigurationTest.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.springboot.mcp.server;
+
+import io.modelcontextprotocol.server.McpTransportContextExtractor;
+import io.modelcontextprotocol.server.transport.ServerHttpHeaderValidator;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.autoconfigure.AutoConfigurations;
+import
org.springframework.boot.test.context.runner.WebApplicationContextRunner;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Camel's Origin validation and caller-identity extraction are provided to
Spring AI's transport of MCP protocol
+ * version 2026-07-28 only with {@code spring.ai.mcp.server.protocol=MODERN},
and those of the application take
+ * precedence.
+ */
+class CamelMcpServerModernTransportAutoConfigurationTest {
+
+ private final WebApplicationContextRunner contextRunner = new
WebApplicationContextRunner()
+
.withConfiguration(AutoConfigurations.of(CamelMcpServerModernTransportAutoConfiguration.class))
+ .withPropertyValues("spring.ai.mcp.server.protocol=MODERN");
+
+ @Test
+ void camelValidatorAndExtractorAreProvidedForCamelRoutes() {
+
contextRunner.withPropertyValues("camel.mcp-server.tags=crm").run(context -> {
+ assertThat(context).hasNotFailed();
+ assertThat(context).hasSingleBean(ServerHttpHeaderValidator.class);
+
assertThat(context).hasSingleBean(McpTransportContextExtractor.class);
+ });
+ }
+
+ @Test
+ void applicationValidatorTakesPrecedence() {
+ ServerHttpHeaderValidator custom = headers -> {
+ };
+ contextRunner.withPropertyValues("camel.mcp-server.tags=crm")
+ .withBean("applicationValidator",
ServerHttpHeaderValidator.class, () -> custom)
+ .run(context -> {
+
assertThat(context).hasSingleBean(ServerHttpHeaderValidator.class);
+
assertThat(context.getBean(ServerHttpHeaderValidator.class)).isSameAs(custom);
+
assertThat(context).hasSingleBean(McpTransportContextExtractor.class);
+ });
+ }
+
+ @Test
+ void nothingIsProvidedWithoutCamelRoutes() {
+ contextRunner.run(context -> {
+
assertThat(context).doesNotHaveBean(ServerHttpHeaderValidator.class);
+
assertThat(context).doesNotHaveBean(McpTransportContextExtractor.class);
+ });
+ }
+
+ @Test
+ void nothingIsProvidedForAnotherProtocol() {
+ contextRunner.withPropertyValues("camel.mcp-server.tags=crm",
"spring.ai.mcp.server.protocol=STREAMABLE")
+ .run(context ->
assertThat(context).doesNotHaveBean(ServerHttpHeaderValidator.class));
+ }
+}
diff --git
a/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/SpringBootMcpServerModernTest.java
b/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/SpringBootMcpServerModernTest.java
new file mode 100644
index 00000000000..5a937bf06bf
--- /dev/null
+++
b/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/SpringBootMcpServerModernTest.java
@@ -0,0 +1,293 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.springboot.mcp.server;
+
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.charset.StandardCharsets;
+import java.time.Duration;
+import java.util.Base64;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
+
+import io.modelcontextprotocol.json.McpJsonDefaults;
+import io.modelcontextprotocol.modern.McpSchema;
+import io.modelcontextprotocol.modern.client.McpClient;
+import io.modelcontextprotocol.modern.client.McpSyncClient;
+import io.modelcontextprotocol.modern.client.SubscriptionEvent;
+import io.modelcontextprotocol.modern.client.transport.HttpClientMcpTransport;
+import
io.modelcontextprotocol.modern.client.transport.McpHttpRequestCustomizer;
+import io.modelcontextprotocol.modern.server.McpSyncResponse;
+import io.modelcontextprotocol.modern.server.feature.McpSyncTool;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mcp.server.McpServerEngine;
+import org.apache.camel.component.mcp.server.McpToolCallContext;
+import org.apache.camel.test.spring.junit6.CamelSpringBootTest;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.Customizer;
+import
org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.core.userdetails.User;
+import org.springframework.security.provisioning.InMemoryUserDetailsManager;
+import org.springframework.security.web.SecurityFilterChain;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+
+/**
+ * The Spring AI MCP server for protocol version 2026-07-28 ({@code
spring.ai.mcp.server.protocol=MODERN}) serves the
+ * Camel routes (CAMEL-27174): no handshake and no session, a client listening
with {@code subscriptions/listen} is told
+ * when a route adds a tool, Camel's Origin validation applies, and the
authenticated caller reaches the route.
+ */
+@EnableAutoConfiguration
+@CamelSpringBootTest
+@SpringBootTest(
+ webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
+ classes = {
SpringBootMcpServerModernTest.TestConfiguration.class },
+ properties = {
+ "spring.main.banner-mode=off",
+ "spring.ai.mcp.server.protocol=MODERN",
+ "spring.ai.mcp.server.name=camel-modern",
+ "camel.mcp-server.tags=modern",
+ "camel.main.run-controller=false" })
+public class SpringBootMcpServerModernTest {
+
+ private static final String AUTHORIZATION = "Basic " + Base64.getEncoder()
+
.encodeToString("mcp-user:mcp-secret".getBytes(StandardCharsets.UTF_8));
+
+ private static final String INITIALIZE = """
+
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25",
+ "capabilities":{},"clientInfo":{"name":"test","version":"1"}}}""";
+
+ private static final String DISCOVER = """
+
{"jsonrpc":"2.0","id":2,"method":"server/discover","params":{"_meta":{
+ "io.modelcontextprotocol/protocolVersion":"2026-07-28",
+ "io.modelcontextprotocol/clientCapabilities":{},
+
"io.modelcontextprotocol/clientInfo":{"name":"test","version":"1"}}}}""";
+
+ private static final HttpClient HTTP = HttpClient.newHttpClient();
+
+ @LocalServerPort
+ private int port;
+
+ @Autowired
+ private McpServerEngine engine;
+
+ @Autowired
+ private CamelContext camelContext;
+
+ @Configuration
+ public static class TestConfiguration {
+
+ @Bean
+ public InMemoryUserDetailsManager mcpTestUsers() {
+ return new InMemoryUserDetailsManager(
+
User.withUsername("mcp-user").password("{noop}mcp-secret").roles("MCP_USER").build());
+ }
+
+ @Bean
+ public SecurityFilterChain mcpTestSecurityFilterChain(HttpSecurity
http) throws Exception {
+ return http
+ .csrf(csrf -> csrf.ignoringRequestMatchers("/mcp"))
+ .authorizeHttpRequests(authorize -> authorize
+ .requestMatchers("/mcp").authenticated()
+ .anyRequest().permitAll())
+ .httpBasic(Customizer.withDefaults())
+ .build();
+ }
+
+ /**
+ * A tool of the application itself, served next to the Camel routes.
+ */
+ @Bean
+ public List<McpSyncTool> springTools() {
+ McpSchema.Tool tool = McpSchema.Tool.builder("add_numbers",
McpJsonDefaults.getMapper(), """
+ {"type":"object","properties":{}}""").description("A tool
of the application").build();
+ return List.of(McpSyncTool.of(tool, (ctx, request) ->
McpSyncResponse.result(McpSchema.CallToolResult
+ .builder().addContent(McpSchema.TextContent.builder("from
spring").build()).build())));
+ }
+
+ @Bean
+ public RouteBuilder routes() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("ai-tool:say_hello?tags=modern&description=Say hello"
+ +
"¶meter.name=string¶meter.name.required=true")
+ .setBody(simple("Hello ${header.name}"));
+
+ from("ai-tool:who_am_i?tags=modern&description=Return the
authenticated caller")
+ .process(exchange ->
exchange.getMessage().setBody("name=" + exchange.getProperty(
+
McpToolCallContext.SECURITY_PRINCIPAL_NAME_PROPERTY)));
+
+ // refused: the application already serves a tool with
this name
+ from("ai-tool:add_numbers?tags=modern&description=Same
name as the application tool")
+ .setBody(constant("from camel"));
+
+
from("ai-resource:readme?resourceUri=camel:///readme.txt&tags=modern"
+ + "&description=Read me&mimeType=text/plain")
+ .setBody(constant("read me"));
+
+
from("ai-resource:order?uriTemplate=camel:///orders/{orderId}&tags=modern"
+ + "&description=An order&mimeType=text/plain")
+ .process(exchange ->
exchange.getMessage().setBody("order " + exchange.getMessage()
+
.getHeader("CamelAiResourceTemplateVariable.orderId", String.class)));
+
+ from("ai-prompt:greet?tags=modern&description=Greet
someone"
+ + "&argument.name.description=Who to
greet&argument.name.required=true")
+ .setBody(simple("Hello ${header.name}"));
+ }
+ };
+ }
+ }
+
+ @Test
+ void engineIsBoundToTheModernServer() {
+ assertThat(engine).isInstanceOf(SpringAiModernMcpServerEngine.class);
+ }
+
+ @Test
+ void callsToolsWithoutHandshake() {
+ McpSyncClient client = client();
+
+
assertThat(client.tools().list().tools()).extracting(McpSchema.Tool::name)
+ .contains("say_hello", "who_am_i", "add_numbers");
+ assertThat(text(client.tool("say_hello").arguments(Map.of("name",
"Camel")).call()))
+ .isEqualTo("Hello Camel");
+
assertThat(text(client.tool("who_am_i").arguments(Map.of()).call())).isEqualTo("name=mcp-user");
+
assertThat(text(client.tool("add_numbers").arguments(Map.of()).call())).isEqualTo("from
spring");
+ }
+
+ @Test
+ void readsResourcesAndTemplates() {
+ McpSyncClient client = client();
+
+
assertThat(client.resources().list().resources()).extracting(McpSchema.Resource::uri)
+ .containsExactly("camel:///readme.txt");
+ assertThat(client.resourceTemplates().list().resourceTemplates())
+
.extracting(McpSchema.ResourceTemplate::uriTemplate).containsExactly("camel:///orders/{orderId}");
+
assertThat(client.resource("camel:///readme.txt").read().contents()).singleElement()
+ .isInstanceOfSatisfying(McpSchema.TextResourceContents.class,
+ text -> assertThat(text.text()).isEqualTo("read me"));
+
assertThat(client.resource("camel:///orders/42").read().contents()).singleElement()
+ .isInstanceOfSatisfying(McpSchema.TextResourceContents.class,
+ text -> assertThat(text.text()).isEqualTo("order 42"));
+ }
+
+ @Test
+ void getsAPrompt() {
+ McpSyncClient client = client();
+
+
assertThat(client.prompts().list().prompts()).extracting(McpSchema.Prompt::name).containsExactly("greet");
+ McpSchema.GetPromptResult result =
client.prompt("greet").arguments(Map.of("name", "Camel")).get();
+ assertThat(result.messages()).singleElement().satisfies(message -> {
+ assertThat(message.role()).isEqualTo(McpSchema.Role.USER);
+
assertThat(message.content()).isInstanceOfSatisfying(McpSchema.TextContent.class,
+ text -> assertThat(text.text()).isEqualTo("Hello Camel"));
+ });
+ }
+
+ @Test
+ void listenerIsToldWhenARouteAddsAndRemovesATool() throws Exception {
+ McpSyncClient client = client();
+ List<SubscriptionEvent> events = new CopyOnWriteArrayList<>();
+ try (McpSyncClient.Listening listening =
client.listen().toolsChanged().open(events::add)) {
+ await().atMost(10, TimeUnit.SECONDS)
+ .until(() ->
events.stream().anyMatch(SubscriptionEvent.Subscribed.class::isInstance));
+
+ camelContext.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("ai-tool:late_tool?tags=modern&description=Added
while the client listens")
+ .routeId("late-tool")
+ .setBody(constant("late"));
+ }
+ });
+
+ await().atMost(10, TimeUnit.SECONDS)
+ .until(() ->
events.stream().anyMatch(SubscriptionEvent.ToolsListChanged.class::isInstance));
+ }
+
assertThat(client.tools().list().tools()).extracting(McpSchema.Tool::name).contains("late_tool");
+
+ camelContext.getRouteController().stopRoute("late-tool");
+ camelContext.removeRoute("late-tool");
+
assertThat(client.tools().list().tools()).extracting(McpSchema.Tool::name).doesNotContain("late_tool");
+ }
+
+ @Test
+ void initializeIsRefusedWithoutSession() throws Exception {
+ HttpResponse<String> initialize = post(INITIALIZE, Map.of());
+
+ // the error code is Spring AI's: its transport checks the 2026-07-28
headers first (-32020), where the MCP
+ // SDK's servlet transport answers an initialize with the supported
versions (-32022)
+ assertThat(initialize.statusCode()).isEqualTo(400);
+ assertThat(initialize.body()).contains("\"error\"");
+
assertThat(initialize.headers().firstValue("Mcp-Session-Id")).isEmpty();
+ }
+
+ @Test
+ void originIsValidated() throws Exception {
+ Map<String, String> discover = Map.of("MCP-Protocol-Version",
"2026-07-28", "Mcp-Method", "server/discover");
+
+ assertThat(post(DISCOVER, discover).statusCode()).isEqualTo(200);
+ assertThat(post(DISCOVER, withOrigin(discover,
"http://localhost:3000")).statusCode()).isEqualTo(200);
+ assertThat(post(DISCOVER, withOrigin(discover,
"https://attacker.example")).statusCode()).isEqualTo(403);
+ }
+
+ private McpSyncClient client() {
+ return
McpClient.sync(HttpClientMcpTransport.builder("http://localhost:" + port +
"/mcp")
+ .requestCustomizer(McpHttpRequestCustomizer.fromSync(
+ (request, headers, context) ->
headers.set("Authorization", AUTHORIZATION)))
+ .build())
+ .clientInfo(McpSchema.Implementation.builder("test",
"1").build())
+ .build();
+ }
+
+ private static String text(McpSchema.CallToolResult result) {
+ assertThat(result.isError()).isNotEqualTo(Boolean.TRUE);
+
assertThat(result.content()).singleElement().isInstanceOf(McpSchema.TextContent.class);
+ return ((McpSchema.TextContent) result.content().get(0)).text();
+ }
+
+ private static Map<String, String> withOrigin(Map<String, String> headers,
String origin) {
+ Map<String, String> copy = new HashMap<>(headers);
+ copy.put("Origin", origin);
+ return copy;
+ }
+
+ private HttpResponse<String> post(String body, Map<String, String>
headers) throws Exception {
+ HttpRequest.Builder builder =
HttpRequest.newBuilder(URI.create("http://localhost:" + port + "/mcp"))
+ .timeout(Duration.ofSeconds(10))
+ .header("Authorization", AUTHORIZATION)
+ .header("Content-Type", "application/json")
+ .header("Accept", "application/json, text/event-stream")
+ .POST(HttpRequest.BodyPublishers.ofString(body));
+ headers.forEach(builder::header);
+ return HTTP.send(builder.build(),
HttpResponse.BodyHandlers.ofString());
+ }
+}
diff --git a/docs/spring-boot/modules/ROOT/pages/starters/mcp-server.adoc
b/docs/spring-boot/modules/ROOT/pages/starters/mcp-server.adoc
index fded0f8619d..90adc9d660f 100644
--- a/docs/spring-boot/modules/ROOT/pages/starters/mcp-server.adoc
+++ b/docs/spring-boot/modules/ROOT/pages/starters/mcp-server.adoc
@@ -328,9 +328,10 @@ spring.ai.mcp.server.prompt-change-notification = true
=== Origin validation
Camel's principal-aware HTTP transport is selected only when
-`spring.ai.mcp.server.protocol` is `STREAMABLE` or `STATELESS` (see
-<<_serving_without_sessions>>) and the Camel transport activation condition is
-satisfied:
+`spring.ai.mcp.server.protocol` is `STREAMABLE`, `STATELESS` (see
+<<_serving_without_sessions>>) or `MODERN` (see
+<<_mcp_protocol_version_2026_07_28>>) and the Camel transport activation
+condition is satisfied:
* By default, the Camel provider is selected when `camel.mcp-server.tags` is
configured. This enables the Origin validator and authenticated caller
@@ -376,8 +377,8 @@ If Camel tags or Origin settings are configured while the
Spring AI protocol
is unset or uses SSE, the Camel HTTP transport is not installed.
The starter logs a warning because Origin validation and caller-context
extraction are not active in that configuration. Select
-`spring.ai.mcp.server.protocol=STREAMABLE` (or `STATELESS`) when those
-protections are required.
+`spring.ai.mcp.server.protocol=STREAMABLE` (or `STATELESS` or `MODERN`) when
+those protections are required.
With the Spring AI 2.0.2 WebMVC transport, an Origin rejection currently
returns HTTP 403 with a plain-text `Invalid Origin header` response body.
@@ -473,8 +474,47 @@ request:
The stateless mode serves the MCP protocol versions that open with an
`initialize` handshake (2025-11-25 and earlier). Protocol version 2026-07-28,
-which has no session by design, is not served by this starter yet: it needs
-Spring AI 2.1.0.
+which has no session by design, is served with `MODERN`.
+
+=== MCP protocol version 2026-07-28
+
+With `spring.ai.mcp.server.protocol=MODERN`, Spring AI serves MCP protocol
+version 2026-07-28, and the starter adds the Camel routes to that server. A
+client of 2026-07-28 has no handshake and no session: every request carries its
+protocol version and is served on its own, so a restart or another instance is
+invisible to the client. Unlike with `STATELESS`, the client is still told
about
+changes: when a Camel route adds or removes a tool, resource or prompt, a
client
+listening with a `subscriptions/listen` request receives the list change.
+
+[source,properties]
+----
+spring.ai.mcp.server.protocol = MODERN
+camel.mcp-server.tags = crm
+----
+
+The Camel routes are added to the tool, resource and prompt repositories that
+Spring AI auto-configures, next to the application's own tools, resources and
+prompts. A Camel route with the name or URI of one of them is refused, as with
+the other protocols. Camel's Origin validation and caller-context extraction
+apply to every request: the starter provides them to Spring AI's
+`WebMvcModernServerTransport` as `ServerHttpHeaderValidator` and
+`McpTransportContextExtractor` beans, and beans of those types defined by the
+application take precedence.
+
+Be aware that:
+
+* Spring AI serves one protocol per application: with `MODERN`, a client that
+ opens with an `initialize` handshake (protocol version 2025-11-25 and
+ earlier) is answered with HTTP 400 and cannot connect. Clients that try
+ 2026-07-28 first and fall back to `initialize` connect with 2026-07-28. Camel
+ Main and Camel JBang serve both kinds of client on the same endpoint (see
+ xref:components:others:mcp-server.adoc[MCP Server]);
+* only `spring.ai.mcp.server.type=SYNC`, the default, is supported: with
+ `ASYNC`, the starter does not register the Camel routes;
+* if the application defines its own tool, resource or prompt repository, the
+ Camel routes of that kind are not served, and the starter logs a warning;
+* protocol version 2026-07-28 is built on the `io.modelcontextprotocol.modern`
+ API of the MCP Java SDK, which may still change in minor releases.
=== Connecting MCP clients