Skip to content

refactor: change notification params type from Map<String,Object> to Object #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2025

Conversation

tzolov
Copy link
Contributor

@tzolov tzolov commented Apr 10, 2025

This change generalizes the parameter type for notification methods across the MCP framework, allowing for more flexible parameter passing. Instead of requiring parameters to be structured as a Map<String,Object>, the API now accepts any Object as parameters.

The primary motivation is to simplify client usage by allowing direct passing of strongly-typed
objects without requiring conversion to a Map first, as demonstrated in the McpAsyncServer
logging notification implementation.

Affected components:

  • McpSession interface and implementations
  • McpServerTransportProvider interface and implementations
  • McpSchema JSONRPCNotification record

…Object

This change generalizes the parameter type for notification methods across the MCP framework,
allowing for more flexible parameter passing. Instead of requiring parameters to be structured
as a Map<String,Object>, the API now accepts any Object as parameters.

The primary motivation is to simplify client usage by allowing direct passing of strongly-typed
 objects without requiring conversion to a Map first, as demonstrated in the McpAsyncServer
logging notification implementation.

Affected components:

- McpSession interface and implementations
- McpServerTransportProvider interface and implementations
- McpSchema JSONRPCNotification record

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Comment on lines 672 to 676
// Map<String, Object> params =
// this.objectMapper.convertValue(loggingMessageNotification,
// new TypeReference<Map<String, Object>>() {
// });

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Map<String, Object> params =
// this.objectMapper.convertValue(loggingMessageNotification,
// new TypeReference<Map<String, Object>>() {
// });

Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>
Copy link
Member

@chemicL chemicL left a comment

Choose a reason for hiding this comment

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

Breaking change alert, but I think it's absolutely worth it.

* @return a Mono that completes when the notification has been broadcast
* @see McpSession#sendNotification(String, Map)
*/
Mono<Void> notifyClients(String method, Map<String, Object> params);
Mono<Void> notifyClients(String method, Object params);
Copy link
Member

Choose a reason for hiding this comment

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

Let's keep in mind to take note of the breaking change in the release docs. I think it's worth the effort though.

* @return a Mono that completes when the notification has been sent
*/
Mono<Void> sendNotification(String method, Map<String, Object> params);
Mono<Void> sendNotification(String method, Object params);
Copy link
Member

Choose a reason for hiding this comment

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

Let's keep in mind to take note of the breaking change in the release docs. I think it's worth the effort though.

@tzolov tzolov merged commit 391ec19 into main Apr 10, 2025
1 check passed
@tzolov tzolov deleted the fix-notification-payload branch April 10, 2025 10:26
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.

2 participants