solon-ai-mcp is an extended feature of solon-ai. Provide support for the mcp protocol. Through it, you can easily publish Tool Service and use Tool Service.
Introducing dependency packages
<dependency>
<groupId></groupId>
<artifactId>solon-ai-mcp</artifactId>
<version>3.1.3-SNAPSHOT</version>
</dependency>
Server-side demonstration (release tool service)
After introducing the dependency package, the server will not be enabled by default and needs to be enabled through configuration.
:
enabled: true
sseEndpoint: "/mcp/sse"
After enabling mcp server, all components of@FunctionMapping
Method will automatically become the tool service of mcp server.
@Component
public class McpServerTool {
@FunctionMapping(description = "Query weather forecast")
public String getWeather(@FunctionParam(description = "City Location") String location) {
return "Sunny, 14 degrees";
}
}
public class McpServerApp {
public static void main(String[] args) {
(, args);
}
}
Client Demo (Use Tool Services)
The client can use the native modelcontextprotocol interface or use McpClientWrapper (packaging simplified)
- Call directly
public void case1(){
McpClientWrapper mcpClient = new McpClientWrapper("http://localhost:8080", "/mcp/sse");
String rst = ("getWeather", ("location", "Hangzhou"));
}
- Bind to use for the model
public void case2(){
McpClientWrapper mcpClient = new McpClientWrapper("http://localhost:8080", "/mcp/sse");
ChatModel chatModel = ("http://127.0.0.1:11434/api/chat")
.provider("ollama")
.model("qwen2.5:1.5b")
.build();
ChatResponse resp = ("How is the weather in Hangzhou today?")
.options(options -> {
//Convert to function set for binding
(());
})
.call();
}
Project warehouse address
- gitee:/opensolon/solon-ai
- gitcode: /opensolon/solon-ai
- github:/opensolon/solon-ai
Official website
- /article/learn-solon-ai