Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Commit 68c21d2

Browse files
committed
Clean the code and add more tests
1 parent 1982c39 commit 68c21d2

20 files changed

+312
-732
lines changed

mcp/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
<version>5.11.0</version>
5656
<scope>test</scope>
5757
</dependency>
58+
<dependency>
59+
<groupId>io.projectreactor</groupId>
60+
<artifactId>reactor-test</artifactId>
61+
<scope>test</scope>
62+
</dependency>
5863

5964
<!-- <dependency>
6065
<groupId>org.springframework.ai</groupId>
@@ -114,4 +119,4 @@
114119
</repository>
115120
</repositories>
116121

117-
</project>
122+
</project>

mcp/src/main/java/spring/ai/mcp/client/McpAsyncClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.fasterxml.jackson.core.type.TypeReference;
66
import com.fasterxml.jackson.databind.ObjectMapper;
77
import reactor.core.publisher.Mono;
8+
import spring.ai.mcp.spec.McpAsyncSession;
89
import spring.ai.mcp.spec.McpAsyncTransport;
910
import spring.ai.mcp.spec.McpSchema;
1011

mcp/src/main/java/spring/ai/mcp/client/McpClient.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,9 @@
1616
package spring.ai.mcp.client;
1717

1818
import java.time.Duration;
19-
import java.util.concurrent.CompletableFuture;
2019

21-
import com.fasterxml.jackson.core.type.TypeReference;
2220
import com.fasterxml.jackson.databind.ObjectMapper;
2321
import spring.ai.mcp.spec.McpAsyncTransport;
24-
import spring.ai.mcp.spec.McpTransport;
25-
import spring.ai.mcp.spec.McpSchema;
26-
import spring.ai.mcp.spec.McpSession;
27-
import spring.ai.mcp.spec.McpTransport;
28-
import spring.ai.mcp.spec.McpSchema.CallToolRequest;
29-
import spring.ai.mcp.spec.McpSchema.CallToolResult;
30-
import spring.ai.mcp.spec.McpSchema.ClientCapabilities;
31-
import spring.ai.mcp.spec.McpSchema.Implementation;
32-
import spring.ai.mcp.spec.McpSchema.InitializeRequest;
33-
import spring.ai.mcp.spec.McpSchema.InitializeResult;
34-
import spring.ai.mcp.spec.McpSchema.ListResourceTemplatesResult;
35-
import spring.ai.mcp.spec.McpSchema.ListResourcesResult;
36-
import spring.ai.mcp.spec.McpSchema.ListToolsResult;
37-
import spring.ai.mcp.spec.McpSchema.PaginatedRequest;
38-
import spring.ai.mcp.spec.McpSchema.ReadResourceRequest;
39-
import spring.ai.mcp.spec.McpSchema.Resource;
40-
import spring.ai.mcp.spec.McpSchema.SubscribeRequest;
41-
import spring.ai.mcp.spec.McpSchema.UnsubscribeRequest;
42-
import spring.ai.mcp.spec.McpSchema.ClientCapabilities.RootCapabilities;
4322

4423
/**
4524
* The MCP client is the main entry point for interacting with the Model Context Protocol

mcp/src/main/java/spring/ai/mcp/client/stdio/StdioServerParameters.java renamed to mcp/src/main/java/spring/ai/mcp/client/stdio/ServerParameters.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
import java.util.Map;
88
import java.util.stream.Collectors;
99

10+
import com.fasterxml.jackson.annotation.JsonInclude;
1011
import com.fasterxml.jackson.annotation.JsonProperty;
1112
import spring.ai.mcp.client.util.Assert;
1213

1314
/**
1415
* Server parameters for stdio client.
1516
*/
16-
public class StdioServerParameters {
17+
@JsonInclude(JsonInclude.Include.NON_ABSENT)
18+
public class ServerParameters {
1719

1820
// Environment variables to inherit by default
1921
private static final List<String> DEFAULT_INHERITED_ENV_VARS = System.getProperty("os.name")
@@ -32,7 +34,7 @@ public class StdioServerParameters {
3234
@JsonProperty("env")
3335
private Map<String, String> env;
3436

35-
private StdioServerParameters(String command, List<String> args, Map<String, String> env) {
37+
private ServerParameters(String command, List<String> args, Map<String, String> env) {
3638
Assert.notNull(command, "The command can not be null");
3739
Assert.notNull(args, "The args can not be null");
3840

@@ -105,8 +107,8 @@ public Builder addEnvVar(String key, String value) {
105107
return this;
106108
}
107109

108-
public StdioServerParameters build() {
109-
return new StdioServerParameters(command, args, env);
110+
public ServerParameters build() {
111+
return new ServerParameters(command, args, env);
110112
}
111113

112114
}

mcp/src/main/java/spring/ai/mcp/client/util/McpServerParameterParser.java renamed to mcp/src/main/java/spring/ai/mcp/client/stdio/ServerParametersParser.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,31 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package spring.ai.mcp.client.util;
16+
package spring.ai.mcp.client.stdio;
1717

1818
import java.util.Map;
19+
import java.util.List;
1920

2021
import com.fasterxml.jackson.annotation.JsonInclude;
2122
import com.fasterxml.jackson.annotation.JsonProperty;
2223
import com.fasterxml.jackson.databind.ObjectMapper;
23-
import spring.ai.mcp.client.util.McpServerParameterParser.McpServers.McpServer;
24+
import spring.ai.mcp.client.stdio.ServerParametersParser.McpServerConfigurations.McpServerConfiguration;
2425

2526
/**
2627
* @author Christian Tzolov
2728
* @since 1.0.0
2829
*/
2930

30-
public class McpServerParameterParser {
31+
public class ServerParametersParser {
3132

3233
@JsonInclude(JsonInclude.Include.NON_ABSENT)
33-
public record McpServers(// @formatter:off
34-
@JsonProperty("mcpServers") Map<String, McpServer> mcpServers) {
34+
public record McpServerConfigurations(// @formatter:off
35+
@JsonProperty("mcpServers") Map<String, McpServerConfiguration> mcpServers) {
3536

3637
@JsonInclude(JsonInclude.Include.NON_ABSENT)
37-
public record McpServer(
38+
public record McpServerConfiguration(
3839
@JsonProperty("command") String command,
39-
@JsonProperty("args") String[] args,
40+
@JsonProperty("args") List<String> args,
4041
@JsonProperty("env") Map<String, String> env) {
4142
}
4243
} // @formatter:on
@@ -72,10 +73,10 @@ public static void main(String[] args) throws Exception {
7273
""";
7374

7475
// Deserialize JSON into McpServers
75-
McpServers servers = objectMapper.readValue(jsonInput, McpServers.class);
76+
McpServerConfigurations servers = objectMapper.readValue(jsonInput, McpServerConfigurations.class);
7677

7778
// Access individual servers
78-
for (Map.Entry<String, McpServer> entry : servers.mcpServers().entrySet()) {
79+
for (Map.Entry<String, McpServerConfiguration> entry : servers.mcpServers().entrySet()) {
7980
System.out.println("Key: " + entry.getKey());
8081
System.out.println("Command: " + entry.getValue().command());
8182
System.out.println("Arguments: " + String.join(", ", entry.getValue().args()));

0 commit comments

Comments
 (0)