Skip to content

Performance: Add/Remove Bulk Ops for Tools#942

Open
amaan75 wants to merge 6 commits intomodelcontextprotocol:mainfrom
amaan75:feature/bulk_ops_support
Open

Performance: Add/Remove Bulk Ops for Tools#942
amaan75 wants to merge 6 commits intomodelcontextprotocol:mainfrom
amaan75:feature/bulk_ops_support

Conversation

@amaan75
Copy link
Copy Markdown

@amaan75 amaan75 commented Apr 29, 2026

So this PR just allows for people to use add tools in bulk and remove tools in bulk.
Added addTools and removeTools methods to McpAsyncServer, McpStatelessAsyncServer, McpSyncServer, and McpStatelessSyncServer to support adding and removing multiple tool handlers at runtime, including input validation and deduplication logic.

Closes BulkOps

Motivation and Context

This change is needed so if this change is needed to make sure that if you are dealing with a lot of MCPs and there's a lot of to and fro tools that are very dynamic, for example, coming from a database or somewhere, those don't have to be those changes. Those changes don't have to go in a for loop, and the copy on ArrayList doesn't keep on copying for hunderds of iterations.

How Has This Been Tested?

There are unit tests that ensure that this works as intended.
This pull request adds bulk registration and removal support for tool handlers in both asynchronous and synchronous MCP server implementations. It introduces new methods for adding and removing multiple tools at once, ensures proper validation and deduplication, and updates tests to cover these scenarios.

Testing enhancements:

  • Added comprehensive integration and unit tests to verify bulk tool registration, replacement, deduplication, and removal, including edge cases such as empty lists and missing capabilities. [1] [2]

Breaking Changes

No

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

Copilot AI review requested due to automatic review settings April 29, 2026 13:44
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds bulk tool registration/removal APIs across MCP sync/async and stateless/stateful server variants to reduce CopyOnWriteArrayList churn and support dynamic tool sets at runtime (Issue #941).

Changes:

  • Add addTools(List<...>) / removeTools(List<String>) to McpAsyncServer, McpStatelessAsyncServer, McpSyncServer, and McpStatelessSyncServer.
  • Implement bulk deduplication (“last occurrence wins”) and replacement semantics for added tools.
  • Add/extend unit + integration tests covering bulk add/replace/dedup/remove and notification behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java Adds bulk add/remove implementations (including dedup) + notifications.
mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessAsyncServer.java Adds bulk add/remove implementations for stateless server variant.
mcp-core/src/main/java/io/modelcontextprotocol/server/McpSyncServer.java Adds blocking bulk add/remove wrappers over async server.
mcp-core/src/main/java/io/modelcontextprotocol/server/McpStatelessSyncServer.java Adds blocking bulk add/remove wrappers over stateless async server.
mcp-test/src/main/java/io/modelcontextprotocol/server/AbstractMcpAsyncServerTests.java Adds tests for bulk add/remove and “notify once per operation” behavior.
mcp-test/src/main/java/io/modelcontextprotocol/server/AbstractMcpSyncServerTests.java Adds sync-server tests for bulk add/replace/dedup/remove + capability checks.
mcp-test/src/main/java/io/modelcontextprotocol/AbstractMcpClientServerIntegrationTests.java Adds client/server integration test validating bulk tool list-change propagation.
mcp-test/src/test/java/io/modelcontextprotocol/server/HttpServletStatelessIntegrationTests.java Adds stateless HTTP integration test for bulk tool mutations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@amaan75 amaan75 changed the title Performance: Add/Remove Bulk Ops for Tools Draft: Performance: Add/Remove Bulk Ops for Tools Apr 29, 2026
@amaan75 amaan75 changed the title Draft: Performance: Add/Remove Bulk Ops for Tools Performance: Add/Remove Bulk Ops for Tools Apr 29, 2026
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.

Add Bulk Operations for tools

2 participants