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 976b39851cf CAMEL-27241: camel-mcp-server-starter - the MCP Java SDK
notifies the removal of a resource template
976b39851cf is described below
commit 976b39851cfd867e85afd1f1d344e8b469e329be
Author: croway <[email protected]>
AuthorDate: Thu Nov 19 14:36:30 2026 +0100
CAMEL-27241: camel-mcp-server-starter - the MCP Java SDK notifies the
removal of a resource template
Spring AI 2.1.0 brings MCP Java SDK 2.2.0, which sends
notifications/resources/list_changed when it removes a resource
template, so the engine no longer sends a second one.
---
.../mcp/server/SpringAiMcpServerEngine.java | 8 +------
.../mcp/server/SpringAiMcpServerEngineTest.java | 25 +++++++---------------
.../mcp/server/SpringBootMcpServerTest.java | 6 +++++-
3 files changed, 14 insertions(+), 25 deletions(-)
diff --git
a/components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/SpringAiMcpServerEngine.java
b/components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/SpringAiMcpServerEngine.java
index d22358a7049..c2ab5e1176d 100644
---
a/components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/SpringAiMcpServerEngine.java
+++
b/components-starter/camel-mcp-server-starter/src/main/java/org/apache/camel/springboot/mcp/server/SpringAiMcpServerEngine.java
@@ -305,15 +305,9 @@ public class SpringAiMcpServerEngine extends
ServiceSupport implements McpServer
return;
}
+ // The MCP Java SDK sends notifications/resources/list_changed
itself when the server advertises it
server.removeResourceTemplate(uriTemplate);
- McpSchema.ServerCapabilities capabilities = server.capabilities();
- if (capabilities != null && capabilities.resources() != null
- &&
Boolean.TRUE.equals(capabilities.resources().listChanged())) {
- // MCP Java SDK 2.1.0 does not notify on template removal;
notify only when advertised.
- server.notifyResourcesListChanged();
- }
-
LOG.debug("MCP resource template removed: {}", uriTemplate);
} catch (Exception e) {
LOG.debug(
diff --git
a/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/SpringAiMcpServerEngineTest.java
b/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/SpringAiMcpServerEngineTest.java
index cf52df4c2c9..20adef652a3 100644
---
a/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/SpringAiMcpServerEngineTest.java
+++
b/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/SpringAiMcpServerEngineTest.java
@@ -130,31 +130,22 @@ class SpringAiMcpServerEngineTest {
}
@Test
- void notifiesTemplateRemovalOnlyWhenAdvertisedAndActuallyRemoved() {
+ void removesOnlyARegisteredTemplateAndLeavesTheNotificationToTheSdk() {
String uriTemplate = "camel:///customers/{id}";
McpSchema.ResourceTemplate template = McpSchema.ResourceTemplate
.builder(uriTemplate, "customers")
.build();
- McpSyncServer notifyingServer = mock(McpSyncServer.class);
-
when(notifyingServer.listResourceTemplates()).thenReturn(List.of(template));
- when(notifyingServer.getServerCapabilities()).thenReturn(
+ // The MCP Java SDK sends resources/list_changed itself when it
removes a template
+ McpSyncServer registeredServer = mock(McpSyncServer.class);
+
when(registeredServer.listResourceTemplates()).thenReturn(List.of(template));
+ when(registeredServer.getServerCapabilities()).thenReturn(
new McpSchema.ServerCapabilities(
null, null, null, null,
new
McpSchema.ServerCapabilities.ResourceCapabilities(false, true), null));
- new
SpringAiMcpServerEngine(notifyingServer).resourceTemplateRemoved(uriTemplate);
- verify(notifyingServer).removeResourceTemplate(uriTemplate);
- verify(notifyingServer).notifyResourcesListChanged();
-
- McpSyncServer nonNotifyingServer = mock(McpSyncServer.class);
-
when(nonNotifyingServer.listResourceTemplates()).thenReturn(List.of(template));
- when(nonNotifyingServer.getServerCapabilities()).thenReturn(
- new McpSchema.ServerCapabilities(
- null, null, null, null,
- new
McpSchema.ServerCapabilities.ResourceCapabilities(false, false), null));
- new
SpringAiMcpServerEngine(nonNotifyingServer).resourceTemplateRemoved(uriTemplate);
- verify(nonNotifyingServer).removeResourceTemplate(uriTemplate);
- verify(nonNotifyingServer, never()).notifyResourcesListChanged();
+ new
SpringAiMcpServerEngine(registeredServer).resourceTemplateRemoved(uriTemplate);
+ verify(registeredServer).removeResourceTemplate(uriTemplate);
+ verify(registeredServer, never()).notifyResourcesListChanged();
McpSyncServer absentServer = mock(McpSyncServer.class);
when(absentServer.listResourceTemplates()).thenReturn(List.of());
diff --git
a/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/SpringBootMcpServerTest.java
b/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/SpringBootMcpServerTest.java
index 769810022c0..b2b3e31f428 100644
---
a/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/SpringBootMcpServerTest.java
+++
b/components-starter/camel-mcp-server-starter/src/test/java/org/apache/camel/springboot/mcp/server/SpringBootMcpServerTest.java
@@ -833,7 +833,7 @@ public class SpringBootMcpServerTest {
await().atMost(10, TimeUnit.SECONDS)
.until(() ->
resourceNotificationCount.get() >= 1);
- // Template removal has an explicit
resources/list_changed notification.
+ // Template removal sends one
resources/list_changed notification.
camelContext.getRouteController().stopRoute("customer-template-route");
await().atMost(10, TimeUnit.SECONDS)
@@ -843,6 +843,10 @@ public class SpringBootMcpServerTest {
await().atMost(10, TimeUnit.SECONDS)
.until(() ->
promptNotificationCount.get() >= 1);
+
+ // The notifications of a session
arrive in order, so a second notification
+ // for the template removal would be
here before the prompt one.
+
assertThat(resourceNotificationCount).hasValue(2);
} finally {
notificationClient.closeGracefully();
}