Skip to content

Notify resources list_changed when removing a resource template - #1266

Merged
Kehrlann merged 1 commit into
modelcontextprotocol:mainfrom
subhashpolisetti:fix/remove-resource-template-notification
Oct 23, 2026
Merged

Kehrlann merged 1 commit into
modelcontextprotocol:mainfrom
subhashpolisetti:fix/remove-resource-template-notification

Conversation

@subhashpolisetti

@subhashpolisetti subhashpolisetti commented Oct 23, 2026 •

Copy link
Copy Markdown

Fixes #1265

Motivation and Context

McpAsyncServer.removeResourceTemplate 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 every other runtime add/remove method in McpAsyncServer (addResourceTemplate, addResource, removeResource, the tool and prompt methods) sends its notification. The method has been like this since it was added in #576. McpSyncServer.removeResourceTemplate delegates to it, so both are affected.

McpAsyncServer server = McpServer.async(transportProvider)
    .capabilities(ServerCapabilities.builder().resources(false, true).build())
    .resourceTemplates(templateSpec)
    .build();
server.removeResourceTemplate(uriTemplate).block(); // no notifications/resources/list_changed

The spec says servers that declare listChanged SHOULD send the notification when the list changes (Resources, List Changed Notification).

The fix uses the same block as removeResource in the same file: notify only when a template was actually removed, and only when Boolean.TRUE.equals(resources().listChanged()).

How Has This Been Tested?

Added two tests to ResourceTemplateManagementTests (mcp-test):

  • testRemoveResourceTemplateNotifiesListChanged fails on main (no message is sent) and passes with this change.
  • testRemoveNonexistentResourceTemplateDoesNotNotify checks that removing an unknown template sends nothing, as removeResource does.

DerivedCapabilitiesRuntimeChangesTests now also removes the template it adds, which covers the new listChanged() read when capabilities are derived and listChanged is null (#1178).

./mvnw -pl mcp-test -am test -Dtest=ResourceTemplateManagementTests,DerivedCapabilitiesRuntimeChangesTests,StdioMcpAsyncServerTests,StdioMcpSyncServerTests,ServletSseMcpAsyncServerTests,ServletSseMcpSyncServerTests -Dsurefire.failIfNoSpecifiedTests=false

./mvnw clean verify and ./mvnw -pl mcp-test -am -Pjackson2 test pass locally.

Breaking Changes

None. Servers that do not declare resources.listChanged behave as before. Servers that do now get the notification the Javadoc already described.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

I did not send the notification unconditionally: when nothing was removed the list did not change, and removeResource already skips the notification in that case.

Left out on purpose: removeResourceTemplate and addResourceTemplate have no null argument check, unlike removeResource, removeTool and removePrompt. That is a separate change. McpStatelessAsyncServer is unchanged because stateless servers do not send notifications.

McpAsyncServer#removeResourceTemplate removed the template but never sent
notifications/resources/list_changed, unlike addResourceTemplate and
removeResource. Send it when a template was removed and the server declares
resources.listChanged.
@Kehrlann
Kehrlann self-requested a review October 23, 2026 08:21
@Kehrlann
Kehrlann merged commit 54e8b61 into modelcontextprotocol:main Oct 23, 2026
22 checks passed
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.

McpAsyncServer.removeResourceTemplate does not send notifications/resources/list_changed

2 participants