fix: Improve MCP server stability and test reliability
- Replace bounded elastic schedulers with single thread executors - Add timeouts to MCP server tests - Enhance error handling in StdioServerTransport - Comment out unused PaginatedRequest unmarshalling - Simplify shutdown logic in StdioServerTransport
This commit is contained in:
parent
fcf0ff0ae2
commit
ad3cdd20a9
6 changed files with 50 additions and 41 deletions
|
|
@ -66,6 +66,7 @@ public abstract class AbstractMcpSyncServerTests {
|
|||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
// onStart();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
package org.springframework.ai.mcp.server;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
import org.springframework.http.server.reactive.HttpHandler;
|
||||
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
|
||||
import org.springframework.web.reactive.function.server.RouterFunctions;
|
||||
|
|
@ -31,6 +33,7 @@ import org.springframework.ai.mcp.spec.McpTransport;
|
|||
*
|
||||
* @author Christian Tzolov
|
||||
*/
|
||||
@Timeout(15) // Giving extra time beyond the client timeout
|
||||
class SseMcpAsyncServerTests extends AbstractMcpAsyncServerTests {
|
||||
|
||||
private static final int PORT = 8181;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
package org.springframework.ai.mcp.server;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
import org.springframework.http.server.reactive.HttpHandler;
|
||||
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
|
||||
import org.springframework.web.reactive.function.server.RouterFunctions;
|
||||
|
|
@ -31,6 +33,7 @@ import org.springframework.ai.mcp.spec.McpTransport;
|
|||
*
|
||||
* @author Christian Tzolov
|
||||
*/
|
||||
@Timeout(15) // Giving extra time beyond the client timeout
|
||||
class SseMcpSyncServerTests extends AbstractMcpSyncServerTests {
|
||||
|
||||
private static final int PORT = 8182;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.ai.mcp.server;
|
||||
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
import org.springframework.ai.mcp.server.transport.StdioServerTransport;
|
||||
import org.springframework.ai.mcp.spec.McpTransport;
|
||||
|
||||
|
|
@ -24,6 +26,7 @@ import org.springframework.ai.mcp.spec.McpTransport;
|
|||
*
|
||||
* @author Christian Tzolov
|
||||
*/
|
||||
@Timeout(15) // Giving extra time beyond the client timeout
|
||||
class StdioMcpAsyncServerTests extends AbstractMcpAsyncServerTests {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.ai.mcp.server;
|
||||
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
import org.springframework.ai.mcp.server.transport.StdioServerTransport;
|
||||
import org.springframework.ai.mcp.spec.McpTransport;
|
||||
|
||||
|
|
@ -24,6 +26,7 @@ import org.springframework.ai.mcp.spec.McpTransport;
|
|||
*
|
||||
* @author Christian Tzolov
|
||||
*/
|
||||
@Timeout(15) // Giving extra time beyond the client timeout
|
||||
class StdioMcpSyncServerTests extends AbstractMcpSyncServerTests {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package org.springframework.ai.mcp.server.transport;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
|
|
@ -51,8 +50,6 @@ class StdioServerTransportTests {
|
|||
|
||||
private ByteArrayOutputStream testOut;
|
||||
|
||||
private ByteArrayInputStream testIn;
|
||||
|
||||
private ByteArrayOutputStream testErr;
|
||||
|
||||
private PrintStream testOutPrintStream;
|
||||
|
|
@ -89,7 +86,6 @@ class StdioServerTransportTests {
|
|||
void shouldHandleIncomingMessages() throws Exception {
|
||||
// Prepare test input
|
||||
String jsonMessage = "{\"jsonrpc\":\"2.0\",\"method\":\"test\",\"params\":{},\"id\":1}";
|
||||
testIn = new ByteArrayInputStream((jsonMessage + "\n").getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
// Create transport with test streams
|
||||
transport = new StdioServerTransport(objectMapper);
|
||||
|
|
|
|||
Loading…
Reference in a new issue