modelcontextprotocol / modelcontextprotocol/java-sdk

API: Generalize notifications for SDK server classes

Đang mở
#831 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

waiting for triage
Ngôn ngữ chính
Java
Star
3.7k
Fork
1.1k
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
9

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu tại McpAsyncServer, đặc biệt là notifyToolsListChanged() quanh dòng 510, và theo dõi cách addTool và removeTool kích hoạt các thông báo. So sánh điều này với các trình xử lý thông báo của McpAsyncClient và xem xét issue #793. Kết quả cần cung cấp một cách được hỗ trợ để các phần mở rộng của server gửi các topic tùy chỉnh kèm dữ liệu và kiểm soát các thông báo tool tự động hiện có, đồng thời vẫn dành chỗ cho resources và prompts.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java
Lĩnh vực
backend-api-design
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
28/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.