Repository navigation
McpAsyncServer.removeResourceTemplate does not send notifications/resources/list_changed #1265
Description
Bug description
McpAsyncServer.removeResourceTemplate(String) removes the template but never sends notifications/resources/list_changed, even when the server declares resources.listChanged. Its Javadoc says the returned Mono "completes when clients have been notified of the change", and the other runtime methods (addResourceTemplate, addResource, removeResource, addTool, removeTool, addPrompt, removePrompt) all send their list_changed notification when listChanged is true. Clients that rely on the notification keep showing the removed template until they re-list.
McpSyncServer.removeResourceTemplate delegates to the async server, so it has the same problem.
The method has looked like this since it was added in #576 (v0.14.0). It is the same on main, 2.1.x and 1.1.x.
Spec: Resources, List Changed Notification: "When the list of available resources changes, servers that declared the listChanged capability SHOULD send a notification."
Environment
main @ f19d122 (2.2.0-SNAPSHOT), also 2.1.0. Java 21.0.5, macOS 26.6.2.
Steps to reproduce
- Build an
McpAsyncServerwith.capabilities(ServerCapabilities.builder().resources(false, true).build())and register a resource template. - Call
removeResourceTemplate(<uriTemplate>). - No
notifications/resources/list_changedis sent.
Expected behavior
When a template is removed and resources.listChanged is true, the server sends notifications/resources/list_changed, in the same way removeResource does. Removing a template that is not registered sends nothing, which also matches removeResource.
Minimal Complete Reproducible example
Failing test in the mcp-test module (ResourceTemplateManagementTests):
@Test
void testRemoveResourceTemplateNotifiesListChanged() {
ResourceTemplate template = ResourceTemplate.builder(TEST_TEMPLATE_URI, TEST_TEMPLATE_NAME).build();
McpServerFeatures.AsyncResourceTemplateSpecification specification = new McpServerFeatures.AsyncResourceTemplateSpecification(
template, (exchange, req) -> Mono.just(ReadResourceResult.builder(List.of()).build()));
mcpAsyncServer = McpServer.async(mockTransportProvider)
.serverInfo("test-server", "1.0.0")
.capabilities(ServerCapabilities.builder().resources(false, true).build())
.resourceTemplates(specification)
.build();
StepVerifier.create(mcpAsyncServer.removeResourceTemplate(TEST_TEMPLATE_URI)).verifyComplete();
// Fails on main: no message was sent
assertThat(mockTransportProvider.getTransport().getAllSentMessages()).singleElement()
.isInstanceOfSatisfying(JSONRPCNotification.class, notification -> assertThat(notification.method())
.isEqualTo(McpSchema.METHOD_NOTIFICATION_RESOURCES_LIST_CHANGED));
}
Activity