Skip to content

Commit 961b1ec

Browse files
committed
fix(tests): Failed to start process with command npx on Windows platform while running mvn test
1 parent 282e482 commit 961b1ec

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

mcp/src/test/java/io/modelcontextprotocol/client/StdioMcpAsyncClientTests.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ class StdioMcpAsyncClientTests extends AbstractMcpAsyncClientTests {
2222

2323
@Override
2424
protected McpClientTransport createMcpTransport() {
25-
ServerParameters stdioParams = ServerParameters.builder("npx")
26-
.args("-y", "@modelcontextprotocol/server-everything", "dir")
27-
.build();
28-
ServerParameters windowsStdioParams = ServerParameters.builder("cmd.exe")
29-
.args("/c", "npx.cmd", "-y", "@modelcontextprotocol/server-everything", "dir")
30-
.build();
31-
boolean isWindows = System.getProperty("os.name").toLowerCase().contains("win");
32-
return new StdioClientTransport(isWindows ? windowsStdioParams : stdioParams);
25+
ServerParameters stdioParams;
26+
if (System.getProperty("os.name").toLowerCase().contains("win")) {
27+
stdioParams = ServerParameters.builder("cmd.exe")
28+
.args("/c", "npx.cmd", "-y", "@modelcontextprotocol/server-everything", "dir")
29+
.build();
30+
}
31+
else {
32+
stdioParams = ServerParameters.builder("npx")
33+
.args("-y", "@modelcontextprotocol/server-everything", "dir")
34+
.build();
35+
}
36+
return new StdioClientTransport(stdioParams);
3337
}
3438

3539
protected Duration getInitializationTimeout() {

mcp/src/test/java/io/modelcontextprotocol/client/StdioMcpSyncClientTests.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@ class StdioMcpSyncClientTests extends AbstractMcpSyncClientTests {
3030

3131
@Override
3232
protected McpClientTransport createMcpTransport() {
33-
ServerParameters stdioParams = ServerParameters.builder("npx")
34-
.args("-y", "@modelcontextprotocol/server-everything", "dir")
35-
.build();
36-
ServerParameters windowsStdioParams = ServerParameters.builder("cmd.exe")
37-
.args("/c", "npx.cmd", "-y", "@modelcontextprotocol/server-everything", "dir")
38-
.build();
39-
boolean isWindows = System.getProperty("os.name").toLowerCase().contains("win");
40-
return new StdioClientTransport(isWindows ? windowsStdioParams : stdioParams);
33+
ServerParameters stdioParams;
34+
if (System.getProperty("os.name").toLowerCase().contains("win")) {
35+
stdioParams = ServerParameters.builder("cmd.exe")
36+
.args("/c", "npx.cmd", "-y", "@modelcontextprotocol/server-everything", "dir")
37+
.build();
38+
}
39+
else {
40+
stdioParams = ServerParameters.builder("npx")
41+
.args("-y", "@modelcontextprotocol/server-everything", "dir")
42+
.build();
43+
}
44+
return new StdioClientTransport(stdioParams);
4145
}
4246

4347
@Test

0 commit comments

Comments
 (0)