This is an automated email from the ASF dual-hosted git repository.
liuhongyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 80596c87ab fix:shenyu-examples-mcp (#6226)
80596c87ab is described below
commit 80596c87ab50bad1fd86e9058ffddcacc3b31f2b
Author: Yu Siheng <[email protected]>
AuthorDate: Sat Nov 8 07:33:23 2025 +0800
fix:shenyu-examples-mcp (#6226)
---
.../shenyu/client/mcp/generator/McpRequestConfigGenerator.java | 3 ++-
shenyu-examples/shenyu-examples-mcp/pom.xml | 6 ++++++
.../main/java/org/apache/shenyu/controller/OrderController.java | 7 ++++++-
.../shenyu-examples-mcp/src/main/resources/application.yml | 4 ++++
.../shenyu/plugin/mcp/server/callback/ShenyuToolCallback.java | 3 +++
5 files changed, 21 insertions(+), 2 deletions(-)
diff --git
a/shenyu-client/shenyu-client-mcp/shenyu-client-mcp-common/src/main/java/org/apache/shenyu/client/mcp/generator/McpRequestConfigGenerator.java
b/shenyu-client/shenyu-client-mcp/shenyu-client-mcp-common/src/main/java/org/apache/shenyu/client/mcp/generator/McpRequestConfigGenerator.java
index 3017e1d6bb..b5c8ddf608 100644
---
a/shenyu-client/shenyu-client-mcp/shenyu-client-mcp-common/src/main/java/org/apache/shenyu/client/mcp/generator/McpRequestConfigGenerator.java
+++
b/shenyu-client/shenyu-client-mcp/shenyu-client-mcp-common/src/main/java/org/apache/shenyu/client/mcp/generator/McpRequestConfigGenerator.java
@@ -87,7 +87,8 @@ public class McpRequestConfigGenerator {
JsonArray headers = new JsonArray();
shenyuMcpRequestConfig.getHeaders().forEach((key, value) -> {
JsonObject headerJson = new JsonObject();
- headerJson.addProperty(key, value);
+ headerJson.addProperty("key", key);
+ headerJson.addProperty("value", value);
headers.add(headerJson);
});
requestTemplate.add(RequestTemplateConstants.HEADERS_KEY, headers);
diff --git a/shenyu-examples/shenyu-examples-mcp/pom.xml
b/shenyu-examples/shenyu-examples-mcp/pom.xml
index 270a061e40..27b0857e9a 100644
--- a/shenyu-examples/shenyu-examples-mcp/pom.xml
+++ b/shenyu-examples/shenyu-examples-mcp/pom.xml
@@ -55,5 +55,11 @@
<artifactId>shenyu-spring-boot-starter-client-mcp</artifactId>
<version>${project.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+
<artifactId>shenyu-spring-boot-starter-client-springmvc</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</project>
diff --git
a/shenyu-examples/shenyu-examples-mcp/src/main/java/org/apache/shenyu/controller/OrderController.java
b/shenyu-examples/shenyu-examples-mcp/src/main/java/org/apache/shenyu/controller/OrderController.java
index bcf723fc63..a2b8636825 100644
---
a/shenyu-examples/shenyu-examples-mcp/src/main/java/org/apache/shenyu/controller/OrderController.java
+++
b/shenyu-examples/shenyu-examples-mcp/src/main/java/org/apache/shenyu/controller/OrderController.java
@@ -29,6 +29,7 @@ import
org.apache.shenyu.client.mcp.common.annotation.ShenyuMcpHeader;
import org.apache.shenyu.client.mcp.common.annotation.ShenyuMcpRequestConfig;
import org.apache.shenyu.client.mcp.common.annotation.ShenyuMcpTool;
import org.apache.shenyu.client.mcp.common.annotation.ShenyuMcpToolParam;
+import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
import org.apache.shenyu.dto.OrderDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -45,6 +46,7 @@ import org.springframework.web.bind.annotation.RestController;
servers = @Server(url = "http://localhost:8150")
)
)
+@ShenyuSpringMvcClient("/order")
@ApiModule(value = "order")
public class OrderController {
@@ -67,6 +69,7 @@ public class OrderController {
),
enabled = true, toolName = "findOrderById"
)
+ @ShenyuSpringMvcClient("/findById")
@ApiDoc(desc = "findById")
public OrderDTO findById(@ShenyuMcpToolParam(
parameter = @Parameter(
@@ -103,9 +106,10 @@ public class OrderController {
),
enabled = true, toolName = "findAllOrder"
)
+ @ShenyuSpringMvcClient("/findAll")
@ApiDoc(desc = "findAll")
public String findAll() {
- return "findAll success";
+ return "hello apache shenyu , mcp findAll success";
}
/**
@@ -116,6 +120,7 @@ public class OrderController {
*/
@GetMapping("/findByName")
@ShenyuMcpTool
+ @ShenyuSpringMvcClient("/findByName")
@ApiDoc(desc = "findName")
public OrderDTO findByName(@ShenyuMcpToolParam final String name) {
OrderDTO dto = new OrderDTO();
diff --git
a/shenyu-examples/shenyu-examples-mcp/src/main/resources/application.yml
b/shenyu-examples/shenyu-examples-mcp/src/main/resources/application.yml
index b257d6d25e..30a89cd200 100644
--- a/shenyu-examples/shenyu-examples-mcp/src/main/resources/application.yml
+++ b/shenyu-examples/shenyu-examples-mcp/src/main/resources/application.yml
@@ -33,3 +33,7 @@ shenyu:
props:
contextPath: /order
appName: /order
+ http:
+ props:
+ contextPath: /order
+ appName: order
\ No newline at end of file
diff --git
a/shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/callback/ShenyuToolCallback.java
b/shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/callback/ShenyuToolCallback.java
index e7db8c1515..7522e0d45f 100644
---
a/shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/callback/ShenyuToolCallback.java
+++
b/shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/callback/ShenyuToolCallback.java
@@ -310,6 +310,9 @@ public class ShenyuToolCallback implements ToolCallback {
*/
private JsonObject parseInput(final String input) {
try {
+ if (org.apache.commons.lang3.StringUtils.isBlank(input)) {
+ return new JsonObject();
+ }
final JsonObject inputJson =
GsonUtils.getInstance().fromJson(input, JsonObject.class);
if (Objects.isNull(inputJson)) {
throw new IllegalArgumentException("Invalid input JSON
format");