webmvcpom.xml文件示例:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.4.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- MCP -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-mcp-server-webmvc-spring-boot-starter</artifactId>
<version>1.0.0-M6</version>
</dependency>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- Apache HttpClient -->
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5-h2</artifactId>
</dependency>
<!-- Spring Boot Starter -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>spring:
application:
name:mcp-name
ai:
mcp:
server:
name:mcp-name
version:1.0.0
type:SYNC
sse-endpoint:/sse/**
*@date2025/03/27 14:52
**/
@Service
publicclassSmdMcpService{
@Autowired
privateRestTemplate restTemplate;
@Value("${smd.service.url}")
privateString smdServiceUrl;
@Tool(name = "getSmdInfo", description = "获取表结构信息")
publicStringgetSmdInfo(@ToolParam(description = "业务系统")String businessSystem,
@ToolParam(description = "表名")Set<String> tableNames){
Map<String, Object> params =newHashMap<>();
params.put("businessSystem", businessSystem);
params.put("tableNames", tableNames);
ResponseEntity<String> response = restTemplate.postForEntity(
smdServiceUrl +"/mcp/api/getSmdInfo",
params,
String.class);
returnresponse.getBody();
}
@Tool(name = "getCRUDCode", description = "根据表名生成增删改查代码")
publicList<Map<String, Object>>getCRUDByTable(@ToolParam(description = "业务系统")String businessSystem,
@ToolParam(description = "表名")Set<String> tableNames,
@ToolParam(description = "模块名,非必填")String moduleName
){
Map<String, Object> params =newHashMap<>();
params.put("businessSystem", businessSystem);
params.put("tableNames", tableNames);
params.put("moduleName", moduleName);
params.put("author","smd-mcp");
HttpEntity<Map<String, Object>> httpEntity = newHttpEntity<>(params);
ResponseEntity<List<Map<String, Object>>> response = restTemplate.exchange(
smdServiceUrl +"/mcp/api/crud",
HttpMethod.POST,
httpEntity,
newParameterizedTypeReference<List<Map<String, Object>>>() {});
returnresponse.getBody();
}
}/**
* MCP配置类
*
*@authorAI Assistant
*@date2024/03/21
*/
@Configuration
@Slf4j
publicclassMcpConfig{
@Bean
publicToolCallbackProvidersmdToolCallbackProvider(SmdMcpService smdMcpService, RulesMcpService rulesMcpService){
returnMethodToolCallbackProvider.builder()
.toolObjects(smdMcpService, rulesMcpService)
.build();
};
}使用支持MCP的客户端进行测试,客户端支持情况可查看:https://modelcontextprotocol.io/clients
这里使用Cursor进行测试:
配置mcp.json
{
"mcpServers":{
"mcp-name":{
"url":"http://localhost:8089/sse",
"env":{
"API_KEY":"value"
}
}
}
}配置后即可看到MCP Server提供的Tools,如下图所示:MCP 还处于发展初期,现阶段更重要的是生态构建,基于统一标准下构筑的生态也会正向的促进整个领域的发展。
对于普通开发者我们可以直接使用已有的MCP工具平台:https://mcp.so/
对于企业,我们可以通过代理的方式将已有HTTP接口暴露为MCP Server:
后续考虑将其做成MCP代理服务,通过简单配置即可将已有业务转换为MCP Server,为AI智能体打开新世界的大门。
| 欢迎光临 链载Ai (https://www.lianzai.com/) | Powered by Discuz! X3.5 |