McpTool Service Integration
This document is intended to help the mcpTool service access the Apache ShenYu gateway. The Apache ShenYu gateway uses the mcpServer plugin to connect with mcpTool services.
Before the connection, start shenyu-admin correctly, start mcpServer plugin and add related dependencies on the gateway and mcpTool application client service side. You can refer to the previous Quick Start with McpServer.
For details about client access configuration, see Application Client Access Config .
For details about data synchronization configurations, see Data Synchronization Config .
Add mcpServer and proxy plugins in gateway
- Add the following dependencies to the gateway’s
pom.xmlfile:
<!--Mcp Server Plugin Start-->
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-plugin-mcp-server</artifactId>
<version>${project.version}</version>
</dependency>
<!--Mcp Server Plugin End-->
Integrate mcpTool with the gateway (for springMvc)
Refer to the example project: shenyu-examples-mcp
-
SpringBootUsers- Add the following dependencies to your
mcpToolservice’spom.xmlfile:
<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-client-mcp</artifactId>
<version>${shenyu.version}</version>
</dependency>- Add the following configuration in
application.yaml:
shenyu:
register:
registerType: http #zookeeper #etcd #nacos #consul
serverLists: http://localhost:9095 #localhost:2181 #http://localhost:2379 #localhost:8848
props:
username: admin
password: 123456
client:
mcp:
props:
contextPath: /mcp
appName: mcp - Add the following dependencies to your
-
SpringUsersAdd the following dependencies to your HTTP service’s
pom.xmlfile:<dependency>
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-client-mcp</artifactId>
<version>${shenyu.version}</version>
</dependency>Then add the following bean definitions to your XML configuration file:
<bean id="clientConfig" class="org.apache.shenyu.register.common.config.PropertiesConfig">
<property name="props">
<map>
<entry key="contextPath" value="/yourContextPath"/>
<entry key="appName" value="yourAppName"/>
</map>
</property>
</bean>
<bean id="shenyuRegisterCenterConfig" class="org.apache.shenyu.register.common.config.ShenyuRegisterCenterConfig">
<property name="registerType" value="http"/>
<property name="serverList" value="http://localhost:9095"/>
</bean>
<bean id="shenyuClientRegisterRepository" class="org.apache.shenyu.client.core.register.ShenyuClientRegisterRepositoryFactory" factory-method="newInstance">
<property name="shenyuRegisterCenterConfig" ref="shenyuRegisterCenterConfig"/>
</bean>
<bean id="McpServiceEventListener" class="org.apache.shenyu.client.mcp.McpServiceEventListener">
<constructor-arg name="clientConfig" ref="clientConfig"/>
<constructor-arg name="shenyuClientRegisterRepository" ref="shenyuClientRegisterRepository"/>
<constructor-arg name="env" ref="environment"/>
</bean>Add the
@ShenyuMcpToolannotations to your controller interfaces.You need to add the
@ShenyuMcpToolannotation on theControllerclass. Only controllers annotated with@ShenyuMcpToolwill be recognized asmcpTool.
Example 1
This example demonstrates full McpTool configuration. You can fully customize your configuration by annotations, including parameter information defined in the operation.
@GetMapping("/findById")
@ShenyuMcpTool(
operation = @Operation(
method = "GET", description = "find order by id"
),
requestConfig = @ShenyuMcpRequestConfig(
bodyToJson = "false",
headers = {
@ShenyuMcpHeader(key = "aaa", value = "bbb")
}
),
enabled = true, toolName = "findOrderById"
)
@ApiDoc(desc = "findById")
public OrderDTO findById(@ShenyuMcpToolParam(
parameter = @Parameter(
name = "id",
in = ParameterIn.PATH,
description = "the id of order",
required = true,
schema = @Schema(
type = "string",
defaultValue = "1"
)
)
) @RequestParam("id") final String id) {
OrderDTO dto = new OrderDTO();
dto.setId(id);
return dto;
}