Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,9 @@ public void resourceTemplateRemoved(String uriTemplate) {
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,31 +130,22 @@ void translatesInvalidToolSchemaIntoServerRefusal() {
}

@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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ void testResourceAndPromptChangeNotificationsAreDelivered() throws Exception {
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)
Expand All @@ -843,6 +843,10 @@ void testResourceAndPromptChangeNotificationsAreDelivered() throws Exception {

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();
}
Expand Down
Loading