Skip to content

Fix MCP protocol, related commands cannot be executed under Windows, such as npx #3323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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 @@ -16,9 +16,7 @@

package org.springframework.ai.mcp.client.autoconfigure.properties;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonInclude;
Expand All @@ -45,6 +43,10 @@ public class McpStdioClientProperties {

public static final String CONFIG_PREFIX = "spring.ai.mcp.client.stdio";

private static final List<String> WIN_COMMAND = List.of("npx");

private static final String OS_NAME = System.getProperty("os.name").toLowerCase();

/**
* Resource containing the MCP servers configuration.
* <p>
Expand Down Expand Up @@ -128,6 +130,11 @@ public record Parameters(
@JsonProperty("env") Map<String, String> env) {

public ServerParameters toServerParameters() {
if (OS_NAME.contains("win") && WIN_COMMAND.contains(command)) {
List<String> winArgs = new LinkedList<>(Arrays.asList("/c", this.command()));
winArgs.addAll(this.args);
return ServerParameters.builder("cmd.exe").args(winArgs).env(this.env()).build();
}
return ServerParameters.builder(this.command()).args(this.args()).env(this.env()).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public EvaluationResponse evaluate(EvaluationRequest evaluationRequest) {
.call()
.content();

boolean passing = evaluationResponse.equalsIgnoreCase("yes");
boolean passing = evaluationResponse.toLowerCase().contains("yes");
return new EvaluationResponse(passing, "", Collections.emptyMap());
}

Expand Down