-
Notifications
You must be signed in to change notification settings - Fork 3k
fix: improve MCP server plugin path handling and backward compatibility for argsPosition #6293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
dcbc652
31c9f53
7544378
823830c
a92191f
057eca9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,24 +78,17 @@ public void handlerSelector(final SelectorData selectorData) { | |
| return; | ||
| } | ||
|
|
||
| // Get the URI from selector data | ||
| String uri = selectorData.getConditionList().stream() | ||
| .filter(condition -> Constants.URI.equals(condition.getParamType())) | ||
| .map(ConditionData::getParamValue) | ||
| .findFirst() | ||
| .orElse(null); | ||
|
|
||
| String path = StringUtils.removeEnd(uri, SLASH); | ||
| path = StringUtils.removeEnd(path, STAR); | ||
| String uri = extractSelectorUri(selectorData); | ||
| String path = normalizeSelectorPath(uri); | ||
| ShenyuMcpServer shenyuMcpServer = GsonUtils.getInstance().fromJson(StringUtils.isBlank(selectorData.getHandle()) ? DEFAULT_MESSAGE_ENDPOINT : selectorData.getHandle(), ShenyuMcpServer.class); | ||
| shenyuMcpServer.setPath(path); | ||
| CACHED_SERVER.get().cachedHandle( | ||
| selectorData.getId(), | ||
| shenyuMcpServer); | ||
| String messageEndpoint = shenyuMcpServer.getMessageEndpoint(); | ||
| // Get or create McpServer for this URI | ||
| if (StringUtils.isNotBlank(uri) && !shenyuMcpServerManager.hasMcpServer(uri)) { | ||
| shenyuMcpServerManager.getOrCreateMcpServerTransport(uri, messageEndpoint); | ||
| if (StringUtils.isNotBlank(path) && !shenyuMcpServerManager.hasMcpServer(path)) { | ||
| shenyuMcpServerManager.getOrCreateMcpServerTransport(path, messageEndpoint); | ||
| } | ||
| if (StringUtils.isNotBlank(path)) { | ||
| shenyuMcpServerManager.getOrCreateStreamableHttpTransport(path + STREAMABLE_HTTP_PATH); | ||
|
|
@@ -108,31 +101,27 @@ public void handlerSelector(final SelectorData selectorData) { | |
|
|
||
| @Override | ||
| public void removeSelector(final SelectorData selectorData) { | ||
| if (Objects.isNull(selectorData) || Objects.isNull(selectorData.getId())) { | ||
| return; | ||
| } | ||
| UpstreamCacheManager.getInstance().removeByKey(selectorData.getId()); | ||
| MetaDataCache.getInstance().clean(); | ||
| CACHED_TOOL.get().removeHandle(CacheKeyUtils.INST.getKey(selectorData.getId(), Constants.DEFAULT_RULE)); | ||
|
|
||
| // Remove the McpServer for this URI | ||
| // First try to get URI from handle, then from condition list | ||
| String uri = selectorData.getHandle(); | ||
| if (StringUtils.isBlank(uri)) { | ||
| // Try to get URI from condition list | ||
| uri = selectorData.getConditionList().stream() | ||
| .filter(condition -> Constants.URI.equals(condition.getParamType())) | ||
| .map(ConditionData::getParamValue) | ||
| .findFirst() | ||
| .orElse(null); | ||
| } | ||
| String path = normalizeSelectorPath(extractSelectorUri(selectorData)); | ||
|
|
||
| CACHED_SERVER.get().removeHandle(selectorData.getId()); | ||
|
|
||
| if (StringUtils.isNotBlank(uri) && shenyuMcpServerManager.hasMcpServer(uri)) { | ||
| shenyuMcpServerManager.removeMcpServer(uri); | ||
| if (StringUtils.isNotBlank(path) && shenyuMcpServerManager.hasMcpServer(path)) { | ||
| shenyuMcpServerManager.removeMcpServer(path); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void handlerRule(final RuleData ruleData) { | ||
| if (Objects.isNull(ruleData)) { | ||
| return; | ||
| } | ||
| Optional.ofNullable(ruleData.getHandle()).ifPresent(s -> { | ||
| ShenyuMcpServerTool mcpServerTool = GsonUtils.getInstance().fromJson(s, ShenyuMcpServerTool.class); | ||
| CACHED_TOOL.get().cachedHandle(CacheKeyUtils.INST.getKey(ruleData), mcpServerTool); | ||
|
Comment on lines
127
to
133
|
||
|
|
@@ -158,10 +147,15 @@ public void handlerRule(final RuleData ruleData) { | |
|
|
||
| @Override | ||
| public void removeRule(final RuleData ruleData) { | ||
| if (Objects.isNull(ruleData)) { | ||
| return; | ||
| } | ||
| Optional.ofNullable(ruleData.getHandle()).ifPresent(s -> { | ||
| CACHED_TOOL.get().removeHandle(CacheKeyUtils.INST.getKey(ruleData)); | ||
| ShenyuMcpServer server = CACHED_SERVER.get().obtainHandle(ruleData.getSelectorId()); | ||
| shenyuMcpServerManager.removeTool(server.getPath(), ruleData.getName()); | ||
| if (Objects.nonNull(server) && StringUtils.isNotBlank(server.getPath())) { | ||
| shenyuMcpServerManager.removeTool(server.getPath(), ruleData.getName()); | ||
| } | ||
| }); | ||
| MetaDataCache.getInstance().clean(); | ||
| } | ||
|
|
@@ -171,4 +165,24 @@ public String pluginNamed() { | |
| return PluginEnum.MCP_SERVER.getName(); | ||
| } | ||
|
|
||
| private String extractSelectorUri(final SelectorData selectorData) { | ||
| if (Objects.isNull(selectorData) || CollectionUtils.isEmpty(selectorData.getConditionList())) { | ||
| return null; | ||
| } | ||
| return selectorData.getConditionList().stream() | ||
| .filter(condition -> Constants.URI.equals(condition.getParamType())) | ||
| .map(ConditionData::getParamValue) | ||
| .findFirst() | ||
| .orElse(null); | ||
| } | ||
|
|
||
| private String normalizeSelectorPath(final String selectorUri) { | ||
| if (StringUtils.isBlank(selectorUri)) { | ||
| return selectorUri; | ||
| } | ||
| String path = StringUtils.removeEnd(selectorUri, STAR); | ||
| path = StringUtils.removeEnd(path, SLASH); | ||
| return StringUtils.defaultIfBlank(path, SLASH); | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.