Skip to content

Commit 7035219

Browse files
more cleanups
1 parent 6a95378 commit 7035219

File tree

7 files changed

+20
-42
lines changed

7 files changed

+20
-42
lines changed

mcp-spring/mcp-spring-webmvc/src/main/java/io/modelcontextprotocol/server/transport/WebMvcSseServerTransportProvider.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import java.io.IOException;
88
import java.time.Duration;
9-
import java.util.Map;
109
import java.util.UUID;
1110
import java.util.concurrent.ConcurrentHashMap;
1211

@@ -300,7 +299,7 @@ private ServerResponse handleMessage(ServerRequest request) {
300299
return ServerResponse.status(HttpStatus.SERVICE_UNAVAILABLE).body("Server is shutting down");
301300
}
302301

303-
if (!request.param("sessionId").isPresent()) {
302+
if (request.param("sessionId").isEmpty()) {
304303
return ServerResponse.badRequest().body(new McpError("Session ID missing in message endpoint"));
305304
}
306305

mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/TomcatTestUtil.java

+2-13
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
*/
44
package io.modelcontextprotocol.server;
55

6-
import java.io.IOException;
7-
import java.net.InetSocketAddress;
8-
import java.net.ServerSocket;
9-
106
import org.apache.catalina.Context;
117
import org.apache.catalina.startup.Tomcat;
128

@@ -53,15 +49,8 @@ public static TomcatServer createTomcatServer(String contextPath, int port, Clas
5349
wrapper.setAsyncSupported(true);
5450
context.addServletMappingDecoded("/*", "dispatcherServlet");
5551

56-
try {
57-
// Configure and start the connector with async support
58-
var connector = tomcat.getConnector();
59-
connector.setAsyncTimeout(3000); // 3 seconds timeout for async requests
60-
}
61-
catch (Exception e) {
62-
throw new RuntimeException("Failed to start Tomcat", e);
63-
}
64-
52+
var connector = tomcat.getConnector();
53+
connector.setAsyncTimeout(3000); // 3 seconds timeout for async requests
6554
return new TomcatServer(tomcat, appContext);
6655
}
6756

mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/WebMvcSseAsyncServerTransportTests.java

-4
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ protected McpServerTransportProvider createMcpTransportProvider() {
9090
return transportProvider;
9191
}
9292

93-
@Override
94-
protected void onStart() {
95-
}
96-
9793
@Override
9894
protected void onClose() {
9995
if (transportProvider != null) {

mcp-spring/mcp-spring-webmvc/src/test/java/io/modelcontextprotocol/server/WebMvcSseSyncServerTransportTests.java

-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ protected WebMvcSseServerTransportProvider createMcpTransportProvider() {
8989
return transportProvider;
9090
}
9191

92-
@Override
93-
protected void onStart() {
94-
}
95-
9692
@Override
9793
protected void onClose() {
9894
if (transportProvider != null) {

mcp-test/src/main/java/io/modelcontextprotocol/server/AbstractMcpSyncServerTests.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ void testConstructorWithInvalidArguments() {
7777
void testGracefulShutdown() {
7878
var mcpSyncServer = McpServer.sync(createMcpTransportProvider()).serverInfo("test-server", "1.0.0").build();
7979

80-
assertThatCode(() -> mcpSyncServer.closeGracefully()).doesNotThrowAnyException();
80+
assertThatCode(mcpSyncServer::closeGracefully).doesNotThrowAnyException();
8181
}
8282

8383
@Test
8484
void testImmediateClose() {
8585
var mcpSyncServer = McpServer.sync(createMcpTransportProvider()).serverInfo("test-server", "1.0.0").build();
8686

87-
assertThatCode(() -> mcpSyncServer.close()).doesNotThrowAnyException();
87+
assertThatCode(mcpSyncServer::close).doesNotThrowAnyException();
8888
}
8989

9090
@Test
@@ -93,7 +93,7 @@ void testGetAsyncServer() {
9393

9494
assertThat(mcpSyncServer.getAsyncServer()).isNotNull();
9595

96-
assertThatCode(() -> mcpSyncServer.closeGracefully()).doesNotThrowAnyException();
96+
assertThatCode(mcpSyncServer::closeGracefully).doesNotThrowAnyException();
9797
}
9898

9999
// ---------------------------------------
@@ -138,7 +138,7 @@ void testAddDuplicateTool() {
138138
.isInstanceOf(McpError.class)
139139
.hasMessage("Tool with name '" + TEST_TOOL_NAME + "' already exists");
140140

141-
assertThatCode(() -> mcpSyncServer.closeGracefully()).doesNotThrowAnyException();
141+
assertThatCode(mcpSyncServer::closeGracefully).doesNotThrowAnyException();
142142
}
143143

144144
@Test
@@ -153,7 +153,7 @@ void testRemoveTool() {
153153

154154
assertThatCode(() -> mcpSyncServer.removeTool(TEST_TOOL_NAME)).doesNotThrowAnyException();
155155

156-
assertThatCode(() -> mcpSyncServer.closeGracefully()).doesNotThrowAnyException();
156+
assertThatCode(mcpSyncServer::closeGracefully).doesNotThrowAnyException();
157157
}
158158

159159
@Test
@@ -173,9 +173,9 @@ void testRemoveNonexistentTool() {
173173
void testNotifyToolsListChanged() {
174174
var mcpSyncServer = McpServer.sync(createMcpTransportProvider()).serverInfo("test-server", "1.0.0").build();
175175

176-
assertThatCode(() -> mcpSyncServer.notifyToolsListChanged()).doesNotThrowAnyException();
176+
assertThatCode(mcpSyncServer::notifyToolsListChanged).doesNotThrowAnyException();
177177

178-
assertThatCode(() -> mcpSyncServer.closeGracefully()).doesNotThrowAnyException();
178+
assertThatCode(mcpSyncServer::closeGracefully).doesNotThrowAnyException();
179179
}
180180

181181
// ---------------------------------------
@@ -186,9 +186,9 @@ void testNotifyToolsListChanged() {
186186
void testNotifyResourcesListChanged() {
187187
var mcpSyncServer = McpServer.sync(createMcpTransportProvider()).serverInfo("test-server", "1.0.0").build();
188188

189-
assertThatCode(() -> mcpSyncServer.notifyResourcesListChanged()).doesNotThrowAnyException();
189+
assertThatCode(mcpSyncServer::notifyResourcesListChanged).doesNotThrowAnyException();
190190

191-
assertThatCode(() -> mcpSyncServer.closeGracefully()).doesNotThrowAnyException();
191+
assertThatCode(mcpSyncServer::closeGracefully).doesNotThrowAnyException();
192192
}
193193

194194
@Test
@@ -219,7 +219,7 @@ void testAddResourceWithNullSpecifiation() {
219219
.isInstanceOf(McpError.class)
220220
.hasMessage("Resource must not be null");
221221

222-
assertThatCode(() -> mcpSyncServer.closeGracefully()).doesNotThrowAnyException();
222+
assertThatCode(mcpSyncServer::closeGracefully).doesNotThrowAnyException();
223223
}
224224

225225
@Test
@@ -312,7 +312,7 @@ void testRemovePrompt() {
312312

313313
assertThatCode(() -> mcpSyncServer.removePrompt(TEST_PROMPT_NAME)).doesNotThrowAnyException();
314314

315-
assertThatCode(() -> mcpSyncServer.closeGracefully()).doesNotThrowAnyException();
315+
assertThatCode(mcpSyncServer::closeGracefully).doesNotThrowAnyException();
316316
}
317317

318318
@Test
@@ -325,7 +325,7 @@ void testRemoveNonexistentPrompt() {
325325
assertThatThrownBy(() -> mcpSyncServer.removePrompt("nonexistent-prompt")).isInstanceOf(McpError.class)
326326
.hasMessage("Prompt with name 'nonexistent-prompt' not found");
327327

328-
assertThatCode(() -> mcpSyncServer.closeGracefully()).doesNotThrowAnyException();
328+
assertThatCode(mcpSyncServer::closeGracefully).doesNotThrowAnyException();
329329
}
330330

331331
// ---------------------------------------
@@ -366,7 +366,7 @@ void testRootsChangeHandlers() {
366366
.build();
367367

368368
assertThat(multipleConsumersServer).isNotNull();
369-
assertThatCode(() -> multipleConsumersServer.closeGracefully()).doesNotThrowAnyException();
369+
assertThatCode(multipleConsumersServer::closeGracefully).doesNotThrowAnyException();
370370
onClose();
371371

372372
// Test error handling
@@ -378,14 +378,14 @@ void testRootsChangeHandlers() {
378378
.build();
379379

380380
assertThat(errorHandlingServer).isNotNull();
381-
assertThatCode(() -> errorHandlingServer.closeGracefully()).doesNotThrowAnyException();
381+
assertThatCode(errorHandlingServer::closeGracefully).doesNotThrowAnyException();
382382
onClose();
383383

384384
// Test without consumers
385385
var noConsumersServer = McpServer.sync(createMcpTransportProvider()).serverInfo("test-server", "1.0.0").build();
386386

387387
assertThat(noConsumersServer).isNotNull();
388-
assertThatCode(() -> noConsumersServer.closeGracefully()).doesNotThrowAnyException();
388+
assertThatCode(noConsumersServer::closeGracefully).doesNotThrowAnyException();
389389
}
390390

391391
}

mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ private Mono<McpSchema.InitializeResult> asyncInitializeRequestHandler(
360360
}
361361
else {
362362
logger.warn(
363-
"Client requested unsupported protocol version: {}, so the server will sugggest the {} version instead",
363+
"Client requested unsupported protocol version: {}, so the server will suggest the {} version instead",
364364
initializeRequest.protocolVersion(), serverProtocolVersion);
365365
}
366366

mcp/src/main/java/io/modelcontextprotocol/server/transport/HttpServletSseServerTransportProvider.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44
package io.modelcontextprotocol.server.transport;
55

6-
import java.io.BufferedReader;
76
import java.io.IOException;
87
import java.io.PrintWriter;
98
import java.io.UncheckedIOException;
@@ -235,12 +234,11 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
235234
* and formats error responses according to the MCP specification.
236235
* @param request The HTTP servlet request
237236
* @param response The HTTP servlet response
238-
* @throws ServletException If a servlet-specific error occurs
239237
* @throws IOException If an I/O error occurs
240238
*/
241239
@Override
242240
protected void doPost(HttpServletRequest request, HttpServletResponse response)
243-
throws ServletException, IOException {
241+
throws IOException {
244242
if (isClosing.get()) {
245243
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Server is shutting down");
246244
return;

0 commit comments

Comments
 (0)