Skip to content
Open
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 @@ -128,10 +128,20 @@ public class McpStatelessAsyncServer {

this.protocolVersions = new ArrayList<>(mcpTransport.protocolVersions());

McpStatelessServerHandler handler = new DefaultMcpStatelessServerHandler(requestHandlers, Map.of());
Map<String, McpStatelessNotificationHandler> notificationHandlers = prepareNotificationHandlers();
McpStatelessServerHandler handler = new DefaultMcpStatelessServerHandler(requestHandlers, notificationHandlers);
mcpTransport.setMcpHandler(handler);
}

private Map<String, McpStatelessNotificationHandler> prepareNotificationHandlers() {
Map<String, McpStatelessNotificationHandler> notificationHandlers = new HashMap<>();

notificationHandlers.put(McpSchema.METHOD_NOTIFICATION_INITIALIZED, (exchange, params) -> Mono.empty());
notificationHandlers.put(McpSchema.METHOD_NOTIFICATION_ROOTS_LIST_CHANGED, (exchange, params) -> Mono.empty());

return notificationHandlers;
}

// ---------------------------------------
// Lifecycle Management
// ---------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,64 @@ void testThrownMcpErrorAndJsonRpcError() throws Exception {
mcpServer.close();
}

@Test
void testInitializedNotificationCallReturnsAccepted() throws Exception {
var mcpServer = McpServer.sync(mcpStatelessServerTransport)
.serverInfo("test-server", "1.0.0")
.capabilities(ServerCapabilities.builder().build())
.build();

McpSchema.JSONRPCNotification notification = new McpSchema.JSONRPCNotification(McpSchema.JSONRPC_VERSION,
McpSchema.METHOD_NOTIFICATION_INITIALIZED, null);

MockHttpServletRequest request = new MockHttpServletRequest("POST", CUSTOM_MESSAGE_ENDPOINT);
MockHttpServletResponse response = new MockHttpServletResponse();

byte[] content = JSON_MAPPER.writeValueAsBytes(notification);
request.setContent(content);
request.addHeader("Content-Type", "application/json");
request.addHeader("Content-Length", Integer.toString(content.length));
request.addHeader("Accept", APPLICATION_JSON + ", " + TEXT_EVENT_STREAM);
request.addHeader("Cache-Control", "no-cache");
request.addHeader(HttpHeaders.PROTOCOL_VERSION, ProtocolVersions.MCP_2025_03_26);

mcpStatelessServerTransport.service(request, response);

assertThat(response.getStatus()).isEqualTo(202);
assertThat(response.getContentAsByteArray()).isEmpty();

mcpServer.close();
}

@Test
void testRootsListChangedNotificationCallReturnsAccepted() throws Exception {
var mcpServer = McpServer.sync(mcpStatelessServerTransport)
.serverInfo("test-server", "1.0.0")
.capabilities(ServerCapabilities.builder().build())
.build();

McpSchema.JSONRPCNotification notification = new McpSchema.JSONRPCNotification(McpSchema.JSONRPC_VERSION,
McpSchema.METHOD_NOTIFICATION_ROOTS_LIST_CHANGED, null);

MockHttpServletRequest request = new MockHttpServletRequest("POST", CUSTOM_MESSAGE_ENDPOINT);
MockHttpServletResponse response = new MockHttpServletResponse();

byte[] content = JSON_MAPPER.writeValueAsBytes(notification);
request.setContent(content);
request.addHeader("Content-Type", "application/json");
request.addHeader("Content-Length", Integer.toString(content.length));
request.addHeader("Accept", APPLICATION_JSON + ", " + TEXT_EVENT_STREAM);
request.addHeader("Cache-Control", "no-cache");
request.addHeader(HttpHeaders.PROTOCOL_VERSION, ProtocolVersions.MCP_2025_03_26);

mcpStatelessServerTransport.service(request, response);

assertThat(response.getStatus()).isEqualTo(202);
assertThat(response.getContentAsByteArray()).isEmpty();

mcpServer.close();
}

private double evaluateExpression(String expression) {
// Simple expression evaluator for testing
return switch (expression) {
Expand Down