Add mcp-sdk-plain module: MCP server on the plain Java SDK 2.1.0 over stdio and Streamable HTTP, fat jar, wire transcripts and a Spring AI client
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b5oh78z7gcH6QkxafF
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
package com.ankurm.mcpplain.client;
|
||||
|
||||
import io.modelcontextprotocol.client.McpSyncClient;
|
||||
import io.modelcontextprotocol.spec.McpSchema.CallToolRequest;
|
||||
import io.modelcontextprotocol.spec.McpSchema.TextContent;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/** Spring AI builds one McpSyncClient per configured connection; we only list tools and call one. */
|
||||
@SpringBootApplication
|
||||
public class ClientApp {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ClientApp.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
CommandLineRunner run(List<McpSyncClient> clients) {
|
||||
return args -> {
|
||||
System.out.println("clients: " + clients.size());
|
||||
for (McpSyncClient c : clients) {
|
||||
System.out.println("server: " + c.getServerInfo().name() + " " + c.getServerInfo().version());
|
||||
c.listTools().tools().forEach(t -> System.out.println("tool: " + t.name()));
|
||||
var r = c.callTool(new CallToolRequest("word_stats", Map.of("text", "spring ai meets plain sdk")));
|
||||
System.out.println("word_stats -> " + ((TextContent) r.content().get(0)).text());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
spring:
|
||||
main:
|
||||
web-application-type: none
|
||||
ai:
|
||||
mcp:
|
||||
client:
|
||||
streamable-http:
|
||||
connections:
|
||||
notes:
|
||||
url: http://127.0.0.1:18090
|
||||
endpoint: /mcp
|
||||
Reference in New Issue
Block a user