You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by li...@apache.org on 2026/02/03 11:42:05 UTC

(shenyu) branch fix/fix_mcp created (now 308968be38)

This is an automated email from the ASF dual-hosted git repository.

liuhongyu pushed a change to branch fix/fix_mcp
in repository https://gitbox.apache.org/repos/asf/shenyu.git


      at 308968be38 fix: handle tool not found error and update requestConfig type to JsonElement

This branch includes the following new commits:

     new 308968be38 fix: handle tool not found error and update requestConfig type to JsonElement

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(shenyu) 01/01: fix: handle tool not found error and update requestConfig type to JsonElement

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liuhongyu pushed a commit to branch fix/fix_mcp
in repository https://gitbox.apache.org/repos/asf/shenyu.git

commit 308968be38837527c90ddd57146e3ba6a54ea718
Author: liuhy <li...@apache.org>
AuthorDate: Tue Feb 3 19:41:37 2026 +0800

    fix: handle tool not found error and update requestConfig type to JsonElement
---
 .../mcp/server/manager/ShenyuMcpServerManager.java | 17 ++++++++++++++
 .../mcp/server/model/ShenyuMcpServerTool.java      | 27 +++++++++++++++++++---
 2 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/manager/ShenyuMcpServerManager.java b/shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/manager/ShenyuMcpServerManager.java
index d0180f3f7c..e31493d587 100644
--- a/shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/manager/ShenyuMcpServerManager.java
+++ b/shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/manager/ShenyuMcpServerManager.java
@@ -432,6 +432,11 @@ public class ShenyuMcpServerManager {
                 LOG.info("Removed tool '{}' from shared server for path: {} (removed from protocols: {})",
                         name, normalizedPath, protocols);
             } catch (Exception e) {
+                if (isToolNotFoundError(e)) {
+                    LOG.debug("Tool '{}' not found on shared server for path: {} (skip removal)",
+                            name, normalizedPath);
+                    return;
+                }
                 LOG.error("Failed to remove tool '{}' from shared server for path: {}", name, normalizedPath, e);
             }
         } else {
@@ -439,6 +444,18 @@ public class ShenyuMcpServerManager {
         }
     }
 
+    private boolean isToolNotFoundError(final Throwable error) {
+        Throwable current = error;
+        while (Objects.nonNull(current)) {
+            String message = current.getMessage();
+            if (Objects.nonNull(message) && message.contains("Tool with name") && message.contains("not found")) {
+                return true;
+            }
+            current = current.getCause();
+        }
+        return false;
+    }
+
     /**
      * Get supported protocols for a server path.
      *
diff --git a/shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/model/ShenyuMcpServerTool.java b/shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/model/ShenyuMcpServerTool.java
index 964e97b837..b9fa2c4ddb 100644
--- a/shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/model/ShenyuMcpServerTool.java
+++ b/shenyu-plugin/shenyu-plugin-mcp-server/src/main/java/org/apache/shenyu/plugin/mcp/server/model/ShenyuMcpServerTool.java
@@ -18,6 +18,8 @@
 package org.apache.shenyu.plugin.mcp.server.model;
 
 import com.google.common.collect.Lists;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonPrimitive;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -43,7 +45,7 @@ public class ShenyuMcpServerTool {
     /**
      * requestTemplate of the tool .
      */
-    private String requestConfig;
+    private JsonElement requestConfig;
     
     /**
      * Parameters of the tool .
@@ -93,7 +95,13 @@ public class ShenyuMcpServerTool {
      * @return requestConfig
      */
     public String getRequestConfig() {
-        return requestConfig;
+        if (Objects.isNull(requestConfig) || requestConfig.isJsonNull()) {
+            return null;
+        }
+        if (requestConfig.isJsonPrimitive() && requestConfig.getAsJsonPrimitive().isString()) {
+            return requestConfig.getAsString();
+        }
+        return requestConfig.toString();
     }
     
     /**
@@ -102,6 +110,19 @@ public class ShenyuMcpServerTool {
      * @param requestConfig requestConfig
      */
     public void setRequestConfig(final String requestConfig) {
+        if (Objects.isNull(requestConfig)) {
+            this.requestConfig = null;
+            return;
+        }
+        this.requestConfig = new JsonPrimitive(requestConfig);
+    }
+
+    /**
+     * Setter for requestConfig.
+     *
+     * @param requestConfig requestConfig
+     */
+    public void setRequestConfig(final JsonElement requestConfig) {
         this.requestConfig = requestConfig;
     }
     
@@ -157,7 +178,7 @@ public class ShenyuMcpServerTool {
         return String.format("McpServerPluginRuleHandle: name: %s, description: %s, requestConfig: %s, parameters: %s",
                 name,
                 description,
-                requestConfig,
+                getRequestConfig(),
                 parameters);
     }
 }