Skip to content

Commit bfefc76

Browse files
committed
Fix race condition in tools list filter
- McpSyncListFilteringIntegrationTests#multipleFilters would flake sometimes in CI. This is a symptom of a race condition when multiple tool-list filters run in a .all() and one filter cancels the whole operation. Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
1 parent d03b9f1 commit bfefc76

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncListFilter.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public interface McpAsyncListFilter<T> {
5252
static <T> McpAsyncListFilter<T> fromSync(McpSyncListFilter<T> filter, boolean immediateExecution) {
5353
Assert.notNull(filter, "filter must not be null");
5454
return (transportContext, primitive) -> {
55-
var visible = Mono.fromCallable(() -> filter.isVisible(transportContext, primitive));
55+
// Not fromCallable: subscribeOn would fuse it into MonoSubscribeOnCallable,
56+
// which can interrupt the worker thread after a downstream all() cancelled it
57+
// from that thread, e.g. while that thread writes the HTTP response
58+
var visible = Mono.defer(() -> Mono.just(filter.isVisible(transportContext, primitive)));
5659
return immediateExecution ? visible : visible.subscribeOn(Schedulers.boundedElastic());
5760
};
5861
}

0 commit comments

Comments
 (0)