Skip to content

Support version in ai maintainer sdk and fix some errors when build#13401

Merged
KomachiSion merged 4 commits intoalibaba:v3.0-developfrom
luoxiner:support-ai-sdk
May 21, 2025
Merged

Support version in ai maintainer sdk and fix some errors when build#13401
KomachiSion merged 4 commits intoalibaba:v3.0-developfrom
luoxiner:support-ai-sdk

Conversation

@luoxiner
Copy link
Contributor

Please do not create a Pull Request without creating an issue first.

What is the purpose of the change

Support version in ai maintainer sdk.
Support display mcp server config.
Fix PMD errors.

Brief changelog

XX

Verifying this change

XXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

@github-actions
Copy link

Thanks for your this PR. 🙏
Please check again for your PR changes whether contains any usage/api/configuration change such as Add new API , Add new configuration, Change default value of configuration.
If so, please add or update documents(markdown type) in docs/next/ for repository nacos-group/nacos-group.github.io


感谢您提交的PR。 🙏
请再次查看您的PR内容,确认是否包含任何使用方式/API/配置参数的变更,如:新增API新增配置参数修改默认配置等操作。
如果是,请确保在提交之前,在仓库nacos-group/nacos-group.github.io中的docs/next/目录下添加或更新文档(markdown格式)。

@lingma-agents
Copy link

lingma-agents bot commented May 21, 2025

新增MCP服务器版本管理功能及前端界面优化

变更文件

文件路径 变更说明
ai/​src/​main/​java/​com/​alibaba/​nacos/​ai/​constant/​Constants.java 添加MAX_LIST_SIZE常量(值100)用于控制列表接口最大返回数量,统一参数校验配置。
ai/​src/​main/​java/​com/​alibaba/​nacos/​ai/​form/​mcp/​registryapi/​ListServerForm.java 将limit参数最大值校验从硬编码100改为引用Constants.MAX_LIST_SIZE常量。
ai/​src/​main/​java/​com/​alibaba/​nacos/​ai/​index/​McpServerIndex.java 为searchMcpServerByName方法新增search模式、分页参数offset和limit,支持模糊搜索与分页查询。
console-ui/src/locales/zh-CN.js 补充toolDetail/Name/Description等10项中文翻译条目,完善操作工具界面显示。
console-ui/​src/​pages/​AI/​McpDetail/​McpDetail.js 使用Tab组件动态展示多个backendEndpoints配置,新增无可用端点提示,并优化服务配置日志输出。
console-ui/​src/​pages/​AI/​NewMcpServer/​NewMcpServer.js 服务选择值格式改为`group@@name`组合,确保服务名称在不同命名空间下的唯一性。
maintainer-client/​src/​main/​java/​com/​alibaba/​nacos/​maintainer/​client/​ai/​McpMaintainerService.java 扩展getMcpServerDetail方法支持通过version参数获取特定版本服务器详情。
console/​src/​main/​java/​com/​alibaba/​nacos/​console/​handler/​ai/​McpHandler.java 为CRUD操作增加version和mcpId参数,支持基于版本和ID的精准服务器管理。
mcp-registry-adaptor/​src/​main/​java/​com/​alibaba/​nacos/​mcpregistry/​controller/​McpRegistryController.java 移除publishMcpServer端点,统一参数命名规范(如name→mcpName),强化版本化操作支持。

时序图

SequenceDiagram:
    participant Frontend as "前端McpDetail组件"
    participant MaintainerSDK as "Maintainer客户端SDK"
    participant RegistryAPI as "MCP注册中心API"
    Frontend->>MaintainerSDK: 调用getMcpServerDetail("server1", "v1.2")
    MaintainerSDK->>RegistryAPI: 发送GET请求携带mcpName和version参数
    RegistryAPI-->>MaintainerSDK: 返回指定版本的McpServerDetailInfo
    MaintainerSDK-->>Frontend: 返回数据供前端展示分页端点配置
    Frontend->>MaintainerSDK: 分页请求(offset=0, limit=50)
    MaintainerSDK->>RegistryAPI: 调用searchMcpServerByName接口
Loading

💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @Lingma-Agent 分析这个方法的性能瓶颈并提供优化建议。

  • @Lingma-Agent 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @Lingma-Agent 请总结上述讨论并提出解决方案。

  • @Lingma-Agent 请根据讨论内容生成优化代码。

Copy link

@lingma-agents lingma-agents bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 代码评审报告

🎯 评审意见概览

严重度 数量 说明
🔴 Blocker 0 阻断性问题,需立即修复。例如:系统崩溃、关键功能不可用或严重安全漏洞。
🟠 Critical 1 严重问题,高优先级修复。例如:核心功能异常或性能瓶颈影响用户体验。
🟡 Major 1 主要问题,建议修复。例如:非核心功能缺陷或代码维护性较差。
🟢 Minor 0 次要问题,酌情优化。例如:代码格式不规范或注释缺失。

总计: 2 个问题


📋 评审意见详情

💡 单文件建议

以下是文件级别的代码建议,聚焦于代码的可读性、可维护性和潜在问题。
☕ ai/src/main/java/com/alibaba/nacos/ai/index/McpServerIndex.java (1 💬)
📜 console-ui/src/pages/AI/McpDetail/McpDetail.js (1 💬)

🚀 跨文件建议

以下是对代码架构和设计的综合分析,聚焦于跨文件交互、系统一致性和潜在优化空间。
🔍 1. 接口参数名称变更导致前后端不一致性风险

在NacosAiMaintainerServiceImpl.java中,多个API方法的参数名称从"name"统一改为"mcpName",但未同步更新前端调用逻辑。例如console-ui/src/pages/AI/NewMcpServer/NewMcpServer.js中仍存在使用旧参数名的潜在风险。需检查前端所有相关接口调用是否同步更新参数名,否则可能导致接口参数传递错误。

📌 关键代码:

params.put("mcpName", mcpName);
serviceName: serviceName || ',

⚠️ 潜在风险: 可能导致前端与后端接口参数不匹配,引发400错误或数据获取失败

🔍 2. 版本控制功能缺乏跨模块一致性验证

McpMaintainerService.java新增了支持版本号的getMcpServerDetail方法,但McpHandler.java的deleteMcpServer方法仍仅依赖名称和命名空间删除服务器。需确保版本控制逻辑在创建/更新/删除等操作中保持一致,否则可能导致版本隔离失效或误删问题。

📌 关键代码:

public McpServerDetailInfo getMcpServerDetail(String mcpName, String version)
@param mcpId id of the mcp server

⚠️ 潜在风险: 可能引发版本数据不一致或误操作删除非目标版本

🔍 3. 已废弃API端点未清理依赖

McpRegistryController.java删除了publishMcpServer接口,但未检查其他模块是否存在对该端点的引用。需确认console-ui或其他客户端是否仍有调用该接口的代码,否则可能导致404错误。

📌 关键代码:

该方法已被删除

⚠️ 潜在风险: 可能导致现有功能因依赖废弃接口而失效

🔍 4. 分页参数验证未全局覆盖

在ListServerForm.java中新增MAX_LIST_SIZE验证,但McpServerIndex.java的searchMcpServerByName方法参数limit未在接口定义中明确最大值限制。需确保所有分页接口参数均遵循统一限制规则,否则可能引发后端数据溢出风险。

📌 关键代码:

if (limit > Constants.MAX_LIST_SIZE)
@param limit list limit

⚠️ 潜在风险: 可能导致后端处理超出预期范围的分页参数,引发性能问题或数据泄露

🔍 5. 版本控制功能测试覆盖不足

新增的版本控制功能(如McpMaintainerService.getDetailByVersion)缺少对应的单元测试案例,需补充针对版本参数不同场景(指定版本/未指定版本/无效版本)的测试用例,确保版本隔离逻辑正确。

⚠️ 潜在风险: 可能存在未发现的版本数据混乱或越权访问漏洞

🔍 6. 端点配置构建存在重复逻辑

McpDetail.js中构建endpoints的逻辑与PlainMcpServerIndex.java中的配置映射存在相似性,建议将endpoint组合规则提取为公共工具类,避免代码重复和维护成本增加。

📌 关键代码:

const endpoint = item.address + item.port + item.path
private Page<ConfigInfo> searchMcpServers(String namespace, String serverName, String search, int limit)

⚠️ 潜在风险: 代码冗余可能导致后续维护时出现配置不一致问题


💡 小贴士

与 lingma-agents 交流的方式

📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:

  • 在当前代码中添加详细的注释说明。

  • 请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。

📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:

  • @Lingma-Agent 分析这个方法的性能瓶颈并提供优化建议。

  • @Lingma-Agent 对这个方法生成优化代码。

📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:

  • @Lingma-Agent 请总结上述讨论并提出解决方案。

  • @Lingma-Agent 请根据讨论内容生成优化代码。

Comment on lines +31 to +35
* @param namespaceId namespaceId
* @param name mcp server name
* @param search search mode
* @param offset offset to list
* @param limit list limit
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

方法注释参数顺序与实际参数不一致

🟡 Major | 🧹 Code Smells

📋 问题详情

searchMcpServerByName方法的注释未包含新增的search、offset、limit参数,导致文档与代码不一致。这会误导开发者理解方法参数,影响代码可维护性。

💡 解决方案

需要将新增的参数在注释中按顺序正确描述:

-     * @param namespaceId namespaceId
-     * @param name mcp server name
-     * @param search search mode
-     * @param offset offset to list
-     * @param limit list limit
+     * @param namespaceId 命名空间ID
+     * @param name 服务名称
+     * @param search 搜索模式
+     * @param offset 分页起始偏移量
+     * @param limit 每页最大数量

committable_suggestion_code: |
/**

  • Search Mcp server by name and namespaceId.
  • @param namespaceId 命名空间ID
  • @param name 服务名称
  • @param search 搜索模式
  • @param offset 分页起始偏移量
  • @param limit 每页最大数量
  • @return MCP Server Summery
    */

您的反馈对我们很重要!(建议右键在新标签页中打开以下链接)

有用意见👍无用意见👎错误意见❌

});
}

console.log(result.data);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

生产代码中存在调试日志

🟠 Critical | 🔓 Vulnerabilities

📋 问题详情

第73行的console.log(result.data)属于调试语句,在生产环境中会泄露内部数据,存在安全风险且影响性能。

💡 解决方案

应移除调试日志:

-73 +    console.log(result.data);

committable_suggestion_code: ""


您的反馈对我们很重要!(建议右键在新标签页中打开以下链接)

有用意见👍无用意见👎错误意见❌

@KomachiSion KomachiSion merged commit 95c598e into alibaba:v3.0-develop May 21, 2025
3 checks passed
KomachiSion added a commit that referenced this pull request May 21, 2025
* Feat support mcp registry api (#13376)

* Support tag fuzzy search  (#13387)

* support tag fuzzy search

* support tag fuzzy search

* Merge pull request #13391 from luoxiner/support-mcp-multi-version

Feat Support Mcp Registry

* Add copyright for mcp-adapter pom.

* Support version in ai maintainer sdk and fix some errors when build (#13401)

* add version for ai maintainer sdk and support display mcp server config

* fix pmd errors

* fix empty endpoint

* remote publish api

* fix tag fuzzy search sql unit test (#13402)

* Fix unit test.

---------

Co-authored-by: Xin Luo <65529035+luoxiner@users.noreply.github.com>
Co-authored-by: Sunrisea <49605583+Sunrisea@users.noreply.github.com>
Co-authored-by: luoxin.luo <luoxin.luo@alibaba-inc.com>
@KomachiSion KomachiSion added this to the 3.0.1 milestone May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants