Two currently known mcp-server java application development frameworks (ID class, the encapsulation experience is relatively simple):
- spring-ai-mcp, supports java17 or above
- Solon-ai-mcp, supports java8 or above (also supports integration into third-party frameworks such as springboot2, jfinal, etc.)
The following are two frameworks to build a weather query mcp tool service.
1. Spring ai mcp server (supports java17 or above)
Add key dependency packages (version number and springboot are independent)
<dependency>
<groupId></groupId>
<artifactId>spring-ai-mcp-server-spring-boot-starter</artifactId>
<version>1.0.0-M6</version>
</dependency>
Add configuration (name the service endpoint)
: jdbc-mcp-server
Sample code (build the service and then publish it as ToolCallbackProvider)
@Service
public class JdbcQueryService {
@Tool(description = "Query weather forecast")
public String getWeather(@ToolParam(description = "City Location") String location) {
return "Sunny, 14 degrees";
}
}
@Configuration
public class McpConfig {
@Bean
ToolCallbackProvider jdbcQueryTools(JdbcQueryService jdbcQueryService) {
return MethodToolCallbackProvider
.builder()
.toolObjects(jdbcQueryService)
.build();
}
}
2. Solon ai mcp server (supports java8 or above)
Add key dependency packages (version number is consistent with solon)
<dependency>
<groupId></groupId>
<artifactId>solon-ai-mcp</artifactId>
<version>3.2.0</version>
</dependency>
Sample code (very similar to mvc development)
@McpServerEndpoint(name="mcp-case1", sseEndpoint = "/case1/sse")
public class McpServerTool {
@ToolMapping(description = "Query weather forecast")
public String getWeather(@ToolParam(description = "City Location") String location) {
return "Sunny, 14 degrees";
}
}
Solon ai mcp server supports multi-endpoints. It is just a service that can provide multiple sets of tools (for different scenarios, with better flexibility):
- There can be a set of tools about weather
- There can be another set of tools for maps
3. Summary
Comparison of development experience
Compare | srping-ai-mcp | solon-ai-mcp |
---|---|---|
Development | Component-based development | Component-based development |
Configuration | Configure via yaml | Components, that is, configuration (can also refer to yaml configuration) |
release | Published as ToolCallbackProvider via configurator | Components are released |
jdk requirements | jdk17 or above | jdk8 or above |
Endpoint Support | It seems that there can only be one (within one service) | Supports multiple endpoints (within one service) |
The development of solon-ai-mcp is relatively simple and trinity. And supports multi-endpoints.