From 7498fb35073518fe329190d164e756f87ad84dd1 Mon Sep 17 00:00:00 2001
From: Christian Tzolov
Date: Thu, 10 Apr 2025 12:11:19 +0200
Subject: [PATCH 1/2] refactor: change notification params type from
Map to 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, 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
---
.../transport/WebFluxSseServerTransportProvider.java | 2 +-
.../transport/WebMvcSseServerTransportProvider.java | 2 +-
.../io/modelcontextprotocol/server/McpAsyncServer.java | 10 ++++++----
.../HttpServletSseServerTransportProvider.java | 2 +-
.../server/transport/StdioServerTransportProvider.java | 2 +-
.../io/modelcontextprotocol/spec/McpClientSession.java | 2 +-
.../java/io/modelcontextprotocol/spec/McpSchema.java | 2 +-
.../io/modelcontextprotocol/spec/McpServerSession.java | 2 +-
.../spec/McpServerTransportProvider.java | 4 ++--
.../java/io/modelcontextprotocol/spec/McpSession.java | 4 ++--
.../MockMcpServerTransportProvider.java | 2 +-
11 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxSseServerTransportProvider.java b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxSseServerTransportProvider.java
index df8dd0211..be30bd72f 100644
--- a/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxSseServerTransportProvider.java
+++ b/mcp-spring/mcp-spring-webflux/src/main/java/io/modelcontextprotocol/server/transport/WebFluxSseServerTransportProvider.java
@@ -188,7 +188,7 @@ public void setSessionFactory(McpServerSession.Factory sessionFactory) {
* errors if any session fails to receive the message
*/
@Override
- public Mono notifyClients(String method, Map params) {
+ public Mono notifyClients(String method, Object params) {
if (sessions.isEmpty()) {
logger.debug("No active sessions to broadcast message to");
return Mono.empty();
diff --git a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java
index fa2e357f9..7bd1aa6c9 100644
--- a/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java
+++ b/mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java
@@ -179,7 +179,7 @@ public void setSessionFactory(McpServerSession.Factory sessionFactory) {
* @return A Mono that completes when the broadcast attempt is finished
*/
@Override
- public Mono notifyClients(String method, Map params) {
+ public Mono notifyClients(String method, Object params) {
if (sessions.isEmpty()) {
logger.debug("No active sessions to broadcast message to");
return Mono.empty();
diff --git a/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java b/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java
index df9386685..55fd32d12 100644
--- a/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java
+++ b/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java
@@ -669,15 +669,17 @@ public Mono loggingNotification(LoggingMessageNotification loggingMessageN
return Mono.error(new McpError("Logging message must not be null"));
}
- Map params = this.objectMapper.convertValue(loggingMessageNotification,
- new TypeReference
* @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 sendNotification(String method, Map params);
+ Mono sendNotification(String method, Object params);
/**
* Closes the session and releases any associated resources asynchronously.
diff --git a/mcp/src/test/java/io/modelcontextprotocol/MockMcpServerTransportProvider.java b/mcp/src/test/java/io/modelcontextprotocol/MockMcpServerTransportProvider.java
index 3fb19180b..20a8c0cf5 100644
--- a/mcp/src/test/java/io/modelcontextprotocol/MockMcpServerTransportProvider.java
+++ b/mcp/src/test/java/io/modelcontextprotocol/MockMcpServerTransportProvider.java
@@ -47,7 +47,7 @@ public void setSessionFactory(Factory sessionFactory) {
}
@Override
- public Mono notifyClients(String method, Map params) {
+ public Mono notifyClients(String method, Object params) {
return session.sendNotification(method, params);
}
From 0526b54e2f0269c506b68897d400d849653625b6 Mon Sep 17 00:00:00 2001
From: Christian Tzolov
Date: Thu, 10 Apr 2025 12:21:12 +0200
Subject: [PATCH 2/2] Remove code comments
Signed-off-by: Christian Tzolov
---
.../java/io/modelcontextprotocol/server/McpAsyncServer.java | 5 -----
1 file changed, 5 deletions(-)
diff --git a/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java b/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java
index 55fd32d12..ec2a04c9e 100644
--- a/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java
+++ b/mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java
@@ -669,11 +669,6 @@ public Mono loggingNotification(LoggingMessageNotification loggingMessageN
return Mono.error(new McpError("Logging message must not be null"));
}
- // Map params =
- // this.objectMapper.convertValue(loggingMessageNotification,
- // new TypeReference>() {
- // });
-
if (loggingMessageNotification.level().level() < minLoggingLevel.level()) {
return Mono.empty();
}