Repository navigation
Fix NPE when adding or removing features on a server with derived capabilities - #1178
Merged
Kehrlann merged 1 commit intoOct 13, 2026
Conversation
itzjb
marked this pull request as ready for review
October 13, 2026 04:56
…abilities Derived server capabilities leave listChanged null since modelcontextprotocol#928. Compare with Boolean.TRUE.equals in McpAsyncServer so runtime add/remove of tools, resources, resource templates and prompts completes instead of throwing a NullPointerException.
Kehrlann
force-pushed
the
fix/derived-capabilities-listchanged-npe
branch
from
October 13, 2026 15:58
d82a00f to
6a8140d
Compare
Kehrlann
self-requested a review
October 13, 2026 16:00
Kehrlann
approved these changes
Oct 13, 2026
Kehrlann
added a commit
that referenced
this pull request
Oct 13, 2026
- Follow-up to #1178 Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1177
Motivation and Context
If you build a server without
.capabilities(...)and register tools, resources or prompts on the builder,McpServerFeaturesderives the capabilities withToolCapabilities.builder().build()(and the resource/prompt equivalents). Since #928 those builders leavelistChangedasnull; before #928 the derived value wasfalse.McpAsyncServerunboxes thatBooleanin seven places:so
addTool,removeTool,addResource,removeResource,addResourceTemplate,addPromptandremovePromptfail with aNullPointerExceptionwhen the returnedMonois subscribed. The tool, resource or prompt has already been added or removed at that point, so the caller sees an error for a change that took effect.McpSyncServerrethrows the NPE from.block().This change compares with
Boolean.TRUE.equals(...), whichMcpAsyncServeralready does forresources().subscribe(). AnulllistChangednow means "no list_changed notification", which matches the capability that was advertised.How Has This Been Tested?
Added
DerivedCapabilitiesRuntimeChangesTests(mcp-test). It builds async and sync servers without explicit capabilities and checks that runtime add/remove of tools, resources, resource templates and prompts complete and send no notification. All four tests fail onmainwith the NPE and pass with this change.Breaking Changes
None. Servers that set
listChangedexplicitly behave as before.Types of changes
Checklist
Additional context
Restoring
listChanged(false)inMcpServerFeatureswould also fix the default path, but it would bring back"listChanged": falseon the wire, which #928 moved away from. It would also leaveServerCapabilities.builder().tools(null)failing the same way.McpAsyncClientunboxesroots().listChanged()the same way, but its derived default isfalse, so I left it out of this PR.