Skip to content

Commit 35ccb83

Browse files
test: fix STDIO integration test and quiet expected error logs
Run MCP client verification synchronously, launch the STDIO subprocess with the correct config, and avoid starting STDIO in-process during config tests. Suppress intentional ERROR logs in test logback configuration. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent c047eb3 commit 35ccb83

4 files changed

Lines changed: 22 additions & 15 deletions

File tree

src/test/java/com/github/thought2code/mcp/annotated/integration/McpApplicationIntegrationTest.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import io.modelcontextprotocol.json.McpJsonDefaults;
2727
import java.time.Duration;
2828
import java.util.Random;
29-
import java.util.concurrent.Executors;
3029
import org.junit.jupiter.api.BeforeAll;
3130
import org.junit.jupiter.api.Tag;
3231
import org.junit.jupiter.api.Test;
@@ -59,14 +58,8 @@ private void startServer(McpServerConfiguration configuration) {
5958
mcpServer.start();
6059
}
6160

62-
private void startServer(String configFileName) {
63-
startServer(new McpConfigurationLoader(configFileName).loadConfig());
64-
}
65-
6661
@Test
6762
void stdioTransport_shouldServeAllFixtureComponents() {
68-
TestMcpStdioServer.main(new String[] {});
69-
7063
String classpath = System.getProperty("java.class.path");
7164
ServerParameters serverParameters =
7265
ServerParameters.builder("java")
@@ -76,8 +69,7 @@ void stdioTransport_shouldServeAllFixtureComponents() {
7669
new StdioClientTransport(serverParameters, McpJsonDefaults.getMapper());
7770

7871
try (McpSyncClient client = McpClient.sync(transport).requestTimeout(requestTimeout).build()) {
79-
Executors.newSingleThreadExecutor()
80-
.execute(() -> McpClientVerificationSupport.verifyAll(client));
72+
McpClientVerificationSupport.verifyAll(client);
8173
}
8274
}
8375

@@ -126,11 +118,14 @@ void disabledConfiguration_shouldNotStartServer() {
126118
assertFalse(configuration.enabled());
127119
}
128120

121+
/**
122+
* STDIO mode binds to System.in/out, starting it in-process would block or break subprocess
123+
* tests.
124+
*/
129125
@Test
130-
void stdioModeConfig_shouldLoadAndStartWithoutError() {
126+
void stdioModeConfig_shouldLoadWithoutStartingInProcessServer() {
131127
McpServerConfiguration configuration =
132128
new McpConfigurationLoader("test-mcp-server-enable-stdio-mode.yml").loadConfig();
133-
assertDoesNotThrow(() -> startServer(configuration));
134129
assertEquals(ServerMode.STDIO, configuration.mode());
135130
}
136131

@@ -154,6 +149,9 @@ void streamableModeConfig_shouldLoadAndStartWithoutError() {
154149
void unknownModeConfig_shouldFailDuringLoad() {
155150
assertThrows(
156151
McpServerConfigurationException.class,
157-
() -> startServer("test-mcp-server-enable-unknown-mode.yml"));
152+
() ->
153+
startServer(
154+
new McpConfigurationLoader("test-mcp-server-enable-unknown-mode.yml")
155+
.loadConfig()));
158156
}
159157
}

src/test/java/com/github/thought2code/mcp/annotated/test/TestMcpStdioServer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
public class TestMcpStdioServer {
66

7+
private static final String STDIO_CONFIG = "test-mcp-server-enable-stdio-mode.yml";
8+
79
public static void main(String[] args) {
8-
McpApplication.run(TestMcpStdioServer.class, args);
10+
McpApplication.run(TestMcpStdioServer.class, args, STDIO_CONFIG);
911
}
1012
}

src/test/resources/logback.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@
1212
</appender>
1313

1414
<logger name="org.eclipse.jetty" level="WARN"/>
15+
<logger name="io.modelcontextprotocol" level="WARN"/>
1516

16-
<root level="DEBUG">
17+
<!-- Expected failure paths in unit/integration tests intentionally emit ERROR logs. -->
18+
<logger name="com.github.thought2code.mcp.annotated.util.JacksonHelper" level="OFF"/>
19+
<logger name="com.github.thought2code.mcp.annotated.reflect.MethodInvoker" level="OFF"/>
20+
<logger name="com.github.thought2code.mcp.annotated.reflect.ComponentInvocationSupport" level="OFF"/>
21+
<logger name="com.github.thought2code.mcp.annotated.server.JettyHttpServer" level="OFF"/>
22+
23+
<root level="WARN">
1724
<appender-ref ref="CONSOLE"/>
1825
</root>
1926

src/test/resources/test-mcp-server-enable-stdio-mode.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mode: STDIO
33
name: mcp-server
44
version: 1.0.0
55
type: SYNC
6-
instructions: You are a helpful AI assistant
6+
instructions: test
77
request-timeout: 60000
88
capabilities:
99
resource: true

0 commit comments

Comments
 (0)