modelcontextprotocol / modelcontextprotocol/java-sdk

API: Generalize notifications for SDK server classes

未关闭
#831 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

waiting for triage
主要语言
Java
星标
3.7k
派生
1.1k
平均合并
1 天 15 小时
30 天内合并 PR
9

描述

I'm building an extension that uses the Java sdk that uses notifications to send 'tool add/delete/update' data to clients (e.g. when new tools are added to an MCP server at runtime).

For this extension to work, it's necessary to provide a new topic string and non-null data to the following transport-level call:

Line 510 in current McpAsyncServer

	public Mono<Void> notifyToolsListChanged() {
		return this.mcpTransportProvider.notifyClients(McpSchema.METHOD_NOTIFICATION_TOOLS_LIST_CHANGED, null);
	}

There is currently no way for the extension to add a custom param to this notification, nor to define a new value for the topic...both of which are required for the extension...e.g.:

public/protected Mono<Void> notifyToolsListChanged(String topic, Object param) {
	return this.mcpTransportProvider.notifyClients(topic, param);
}

Where my extension wishes to call via something like:

server.notifyToolsListChanged("myorg/update", myData);

In a issue #793 I suggested allowing inheritance of the McpAsyncServer class, so that the notifyToolsListChanged() could be overridden by subclasses (via public or protected constructors, constructor args, and member variables) and call the transport directly with desired arguments.

Although I still believe inheritance of core classes is sometimes reasonable for an SDK, it seems that composition is currently favored for this case. There is no way that can see for this to be done through composition currently.

This extension also needs to have some way to prevent the existing notification notifyToolsListChanged() from being sent by addTool and remove/Tool (asynchronously)...meaning that addTool/removeTool need to be customized as well.

Note that I'm interested in generalizing this update extension to other primitives...e.g. resources and prompts...plus others...so the same extension access for server-side dynamic updates. Ultimately it's not just for tools but I'm starting with tools.

On the McpAsyncClient, conversely, there are notification handlers that can be passed into the client on construction, allowing it to receive custom topics with params.

Clearly there are multiple ways to fix this in the SDK. One suggestion: Consider defining a public AbstractAsyncServer superclass, and moving protected members, constructors, and generalized methods into that super class. This is the one way with inheritance that I'm aware of that allows generalization and will not break binary compatibility for the current McpAsyncServer API consumers (e.g. by renaming public methods).

With that said, I'm open to composition rather than inheritance as a solution (as long as it supports what this update extension needs), but afaict will likely require larger refactoring and perhaps API changes at this point.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 McpAsyncServer 开始,重点查看第 510 行附近的 notifyToolsListChanged(),并追踪 addTool 和 removeTool 如何触发通知。将其与 McpAsyncClient 的通知处理器进行比较,并查看 issue #793。完成后应为服务器扩展提供一种受支持的方式,用于发送带数据的自定义主题并控制现有的自动工具通知,同时为资源和提示保留扩展空间。

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
backend-api-design
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
28/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。