Skip to content

Conversation

misakacoder
Copy link
Contributor

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

What is the purpose of the change

Fix #13460

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.

Copy link

github-actions bot commented Jun 4, 2025

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格式)。

Copy link

lingma-agents bot commented Jun 4, 2025

修复MCP管理中命名空间、ID及版本参数缺失导致的问题

变更文件

文件路径 变更说明
console/​src/​main/​java/​com/​alibaba/​nacos/​console/​handler/​impl/​remote/​ai/​McpRemoteHandler.java 在listMcpServers/getMcpServer/deleteMcpServer方法中补充namespaceId、mcpId和version参数,确保跨命名空间和版本的操作准确性
maintainer-client/​src/​main/​java/​com/​alibaba/​nacos/​maintainer/​client/​ai/​McpMaintainerService.java 修改getMcpServerDetail/deleteMcpServer方法签名,新增mcpId和version参数,并完善默认实现逻辑
maintainer-client/​src/​main/​java/​com/​alibaba/​nacos/​maintainer/​client/​ai/​NacosAiMaintainerServiceImpl.j​ava 在MCP详情获取和删除操作中增加参数校验,构造包含命名空间、ID和版本的完整请求参数

💡 小贴士

与 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 0 严重问题,高优先级修复。例如:核心功能异常或性能瓶颈影响用户体验。
🟡 Major 0 主要问题,建议修复。例如:非核心功能缺陷或代码维护性较差。
🟢 Minor 1 次要问题,酌情优化。例如:代码格式不规范或注释缺失。

总计: 1 个问题


📋 评审意见详情

💡 单文件建议

以下是文件级别的代码建议,聚焦于代码的可读性、可维护性和潜在问题。
☕ maintainer-client/src/main/java/com/alibaba/nacos/maintainer/client/ai/NacosAiMaintainerServiceImpl.java (1 💬)

🚀 跨文件建议

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

在McpMaintainerService接口中新增了mcpId和version参数,但部分默认方法实现未完整传递参数。例如deleteMcpServer的默认方法调用新接口时未传mcpId和version,可能导致空指针或逻辑错误。同时,其他依赖该接口的组件(如console模块)若未同步参数更新,将引发调用参数不匹配问题。需检查所有接口调用路径确保参数一致性。

📌 关键代码:

default boolean deleteMcpServer(String mcpName) throws NacosException {
    return deleteMcpServer(Constants.DEFAULT_NAMESPACE_ID, mcpName, null, null);
}
clientHolder.getAiMaintainerService().deleteMcpServer(namespaceId, mcpName, mcpId, version);

⚠️ 潜在风险: 参数不匹配可能导致接口调用失败、数据错误或空指针异常,特别是在旧版本客户端未升级时会出现兼容性问题。

🔍 2. 新增参数未在所有调用场景中处理导致潜在空值风险

新增的mcpId和version参数在getMcpServerDetail等方法中成为必填项,但部分调用场景(如默认方法实现)传递了null值。需确保所有调用方正确传递参数,避免因空值引发的业务逻辑错误或数据库查询异常。建议在接口参数添加非空校验或明确参数说明。

📌 关键代码:

default McpServerDetailInfo getMcpServerDetail(String mcpName, String version) throws NacosException {
    return getMcpServerDetail(Constants.DEFAULT_NAMESPACE_ID, mcpName, null, version);
}

⚠️ 潜在风险: 参数为空可能导致数据查询错误或存储不完整,影响MCP服务器管理功能的准确性。

🔍 3. 测试覆盖不足新增参数边界条件

新增的mcpId和version参数未在单元测试中覆盖空值、非法值等边界条件。需补充测试用例验证参数缺失、格式错误等场景,确保接口在参数异常时能正确处理并返回错误信息。

⚠️ 潜在风险: 未覆盖的异常场景可能导致线上运行时出现未处理异常或数据污染。

🔍 4. Map初始化容量调整缺乏合理性说明

在NacosAiMaintainerServiceImpl中将Map初始化容量从3/4改为8,但未说明容量调整依据。需评估实际存储需求是否需要扩容,避免过度分配浪费内存或容量不足频繁扩容。建议根据参数数量动态计算初始容量或保留原设计。

📌 关键代码:

Map<String, String> params = new HashMap<>(8);

⚠️ 潜在风险: 不合理的容量设置可能增加内存消耗或影响性能,尤其在高并发场景下可能引发频繁扩容问题。


💡 小贴士

与 lingma-agents 交流的方式

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

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

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

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

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

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

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

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

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

@@ -60,7 +60,7 @@ public Page<McpServerBasicInfo> listMcpServer(String namespaceId, String mcpName
if (StringUtils.isBlank(namespaceId)) {
namespaceId = AiConstants.Mcp.MCP_DEFAULT_NAMESPACE;
}
Map<String, String> params = new HashMap<>(3);
Map<String, String> params = new HashMap<>(8);
Copy link

Choose a reason for hiding this comment

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

Map初始化容量配置不合理

🟢 Minor | 🧹 Code Smells

📋 问题详情

listMcpServersearchMcpServer方法中,HashMap初始化容量设置为8,但实际仅需存储4个参数,导致内存浪费。

💡 解决方案

调整HashMap初始容量配置:

-Map<String, String> params = new HashMap<>(8);
+Map<String, String> params = new HashMap<>(4);

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

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

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.53%. Comparing base (c5aebb0) to head (d9f9a20).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             develop   #13462   +/-   ##
==========================================
  Coverage      70.52%   70.53%           
+ Complexity     11912    11911    -1     
==========================================
  Files           1621     1621           
  Lines          51826    51829    +3     
  Branches        5210     5210           
==========================================
+ Hits           36552    36558    +6     
+ Misses         12826    12822    -4     
- Partials        2448     2449    +1     
Files with missing lines Coverage Δ
...nsole/handler/impl/remote/ai/McpRemoteHandler.java 100.00% <100.00%> (ø)
...cos/maintainer/client/ai/McpMaintainerService.java 100.00% <100.00%> (ø)
...tainer/client/ai/NacosAiMaintainerServiceImpl.java 85.86% <100.00%> (+0.47%) ⬆️

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5aebb0...d9f9a20. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KomachiSion KomachiSion merged commit 19bdfed into alibaba:develop Jun 4, 2025
3 checks passed
@KomachiSion KomachiSion added this to the 3.0.2 milestone Jun 4, 2025
@KomachiSion KomachiSion added the kind/bug Category issues or prs related to bug. label Jun 4, 2025
@misakacoder misakacoder deleted the fix-13460 branch June 4, 2025 07:44
@wuyfee
Copy link

wuyfee commented Jun 4, 2025

$\color{red}{FAILURE}$
DETAILS
✅ - docker: success
❌ - deploy (standalone & cluster & standalone_auth): failure
❌ - e2e-java-test (standalone & cluster & standalone_auth): skipped
❌ - e2e-go-test (standalone & cluster): skipped
❌ - e2e-cpp-test (standalone & cluster): skipped
❌ - e2e-csharp-test (standalone & cluster): skipped
❌ - e2e-nodejs-test (standalone & cluster): skipped
❌ - e2e-python-test (standalone & cluster): skipped
✅ - clean (standalone & cluster & standalone_auth): success

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Category issues or prs related to bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Nacos 3.0] server和console分开启动时,MCP管理存在的一些问题
4 participants