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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void setSessionFactory(McpServerSession.Factory sessionFactory) {
* errors if any session fails to receive the message
*/
@Override
public Mono<Void> notifyClients(String method, Map<String, Object> params) {
public Mono<Void> notifyClients(String method, Object params) {
if (sessions.isEmpty()) {
logger.debug("No active sessions to broadcast message to");
return Mono.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void setSessionFactory(McpServerSession.Factory sessionFactory) {
* @return A Mono that completes when the broadcast attempt is finished
*/
@Override
public Mono<Void> notifyClients(String method, Map<String, Object> params) {
public Mono<Void> notifyClients(String method, Object params) {
if (sessions.isEmpty()) {
logger.debug("No active sessions to broadcast message to");
return Mono.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,15 +669,12 @@ public Mono<Void> loggingNotification(LoggingMessageNotification loggingMessageN
return Mono.error(new McpError("Logging message must not be null"));
}

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

if (loggingMessageNotification.level().level() < minLoggingLevel.level()) {
return Mono.empty();
}

return this.mcpTransportProvider.notifyClients(McpSchema.METHOD_NOTIFICATION_MESSAGE, params);
return this.mcpTransportProvider.notifyClients(McpSchema.METHOD_NOTIFICATION_MESSAGE,
loggingMessageNotification);
}

private McpServerSession.RequestHandler<Void> setLoggerRequestHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void setSessionFactory(McpServerSession.Factory sessionFactory) {
* @return A Mono that completes when the broadcast attempt is finished
*/
@Override
public Mono<Void> notifyClients(String method, Map<String, Object> params) {
public Mono<Void> notifyClients(String method, Object params) {
if (sessions.isEmpty()) {
logger.debug("No active sessions to broadcast message to");
return Mono.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void setSessionFactory(McpServerSession.Factory sessionFactory) {
}

@Override
public Mono<Void> notifyClients(String method, Map<String, Object> params) {
public Mono<Void> notifyClients(String method, Object params) {
if (this.session == null) {
return Mono.error(new McpError("No session to close"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public <T> Mono<T> sendRequest(String method, Object requestParams, TypeReferenc
* @return A Mono that completes when the notification is sent
*/
@Override
public Mono<Void> sendNotification(String method, Map<String, Object> params) {
public Mono<Void> sendNotification(String method, Object params) {
McpSchema.JSONRPCNotification jsonrpcNotification = new McpSchema.JSONRPCNotification(McpSchema.JSONRPC_VERSION,
method, params);
return this.transport.sendMessage(jsonrpcNotification);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public record JSONRPCRequest( // @formatter:off
public record JSONRPCNotification( // @formatter:off
@JsonProperty("jsonrpc") String jsonrpc,
@JsonProperty("method") String method,
@JsonProperty("params") Map<String, Object> params) implements JSONRPCMessage {
@JsonProperty("params") Object params) implements JSONRPCMessage {
} // @formatter:on

@JsonInclude(JsonInclude.Include.NON_ABSENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public <T> Mono<T> sendRequest(String method, Object requestParams, TypeReferenc
}

@Override
public Mono<Void> sendNotification(String method, Map<String, Object> params) {
public Mono<Void> sendNotification(String method, Object params) {
McpSchema.JSONRPCNotification jsonrpcNotification = new McpSchema.JSONRPCNotification(McpSchema.JSONRPC_VERSION,
method, params);
return this.transport.sendMessage(jsonrpcNotification);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public interface McpServerTransportProvider {
/**
* Sends a notification to all connected clients.
* @param method the name of the notification method to be called on the clients
* @param params a map of parameters to be sent with the notification
* @param params parameters to be sent with the notification
* @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.


/**
* Immediately closes all the transports with connected clients and releases any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ default Mono<Void> sendNotification(String method) {
* parameters with the notification.
* </p>
* @param method the name of the notification method to be sent to the counterparty
* @param params a map of parameters to be sent with the notification
* @param params parameters to be sent with the notification
* @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.


/**
* Closes the session and releases any associated resources asynchronously.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void setSessionFactory(Factory sessionFactory) {
}

@Override
public Mono<Void> notifyClients(String method, Map<String, Object> params) {
public Mono<Void> notifyClients(String method, Object params) {
return session.sendNotification(method, params);
}

Expand Down