modelcontextprotocol / modelcontextprotocol/java-sdk

Add Bulk Operations for tools

未關閉
#941 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

enhancement P3 ready for work
主要語言
Java
星號
3.7k
分支
1.1k
平均合併
1 天 15 小時
30 天內合併 PR
9

描述

So I am trying to submit a trivial change, but before I do that, I would like to know if this change will be acceptable. The idea is that today the MCP server does not support bulk operations for add tools or remove tools, and it is backed by a copy-on-write array list. So if I add a lot of tools, then every single time there is a copy that happens before a single tool gets committed, and that's not that great for performance when I would like to make changes to a lot of tools, for example.

Expected Behavior
Expected behavior is rather simple: I would like an API that lets me add several tools in bulk and that lets me remove several tools in bulk as well.


	/**
	 * Add a new tool specification at runtime.
	 * @param toolSpecification The tool specification to add
	 */
	public void addTool(McpStatelessServerFeatures.SyncToolSpecification toolSpecification) {
		this.asyncServer
			.addTool(McpStatelessServerFeatures.AsyncToolSpecification.fromSync(toolSpecification,
					this.immediateExecution))
			.block();
	}

	/**
	 * Add multiple tool specifications at runtime.
	 * @param toolSpecifications The tool specifications to add
	 */
	public void addTools(List<McpStatelessServerFeatures.SyncToolSpecification> toolSpecifications) {
		if (toolSpecifications == null) {
			this.asyncServer.addTools(null).block();
			return;
		}
		this.asyncServer
			.addTools(toolSpecifications.stream()
				.map(toolSpecification -> McpStatelessServerFeatures.AsyncToolSpecification.fromSync(toolSpecification,
						this.immediateExecution))
				.toList())
			.block();
	}

Current Behavior
The current behavior is that it just has a single method for add and remove

	/**
	 * Add a new tool specification at runtime.
	 * @param toolSpecification The tool specification to add
	 */
	public void addTool(McpStatelessServerFeatures.SyncToolSpecification toolSpecification) {
		this.asyncServer
			.addTool(McpStatelessServerFeatures.AsyncToolSpecification.fromSync(toolSpecification,
					this.immediateExecution))
			.block();
	}

Context

The reason we need this is because we are trying to create what sort of looks like an MCP gateway. For a lot of our internal tooling, these tool definitions come from a database. These tools can get enabled and disabled at runtime. There is also a use case where we interact with a lot of upstream MCP clients and publish out their tools as tools that we own ourselves. If one of those MCP clients goes bad or unhealthy for whatever reason or tries to remove the tools that we have access to, then that same thing should reflect for our clients as well, and it will be great to have that capability because if an MCP client or several MCP clients try to remove their tool all at once, we're looking at hundreds or tens of removals in a single shot. In some cases, maybe even hundreds or hundreds if we are dealing with two or three bigger MCP clients. That's the reason why we need this.

FYI, I have a PR that is already ready that I can immediately push if you guys think this is an acceptable change to introduce or allow addition and removal of tools in bulk.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先定位與 addTool、removeTool、asyncServer 相關的 server API,以及 issue 中展示的 SyncToolSpecification/AsyncToolSpecification 轉換。檢查目前的 copy-on-write 更新如何提交,接著實作具備等效單項行為的批次新增與刪除入口,並驗證一次批次操作能避免重複複製。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
java
領域
api, backend
Issue 類型
功能
難度
3/5
預估耗時
1-2 天
活躍度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。