Skip to content

Conversation

Aias00
Copy link
Contributor

@Aias00 Aias00 commented May 12, 2025

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

What is the purpose of the change

[issue #13365] fix mcp server group error

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

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 May 12, 2025

修复MCP服务器组名称初始化和参数传递错误

变更文件

文件路径 变更说明
console-ui/​src/​pages/​AI/​NewMcpServer/​NewMcpServer.js 在初始化表单数据时新增groupName字段的赋值逻辑,并在服务参数构造时优先使用服务组定义的groupName,若缺失则采用表单输入值。

时序图

sequenceDiagram
    participant NewMcpServer
    participant remoteServerConfig
    participant serviceList
    NewMcpServer->>remoteServerConfig: 获取serviceRef.groupName
    NewMcpServer->>initFileData: 赋值groupName字段
    NewMcpServer->>serviceList: 查询服务组信息
    serviceList-->>NewMcpServer: 返回包含groupName的服务对象
    NewMcpServer->>NewMcpServer: 合并serverGroup.groupName与values.groupName
    NewMcpServer->>endpointSpecification: 传递合并后的groupName参数
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 0 严重问题,高优先级修复。例如:核心功能异常或性能瓶颈影响用户体验。
🟡 Major 2 主要问题,建议修复。例如:非核心功能缺陷或代码维护性较差。
🟢 Minor 0 次要问题,酌情优化。例如:代码格式不规范或注释缺失。

总计: 2 个问题


📋 评审意见详情

💡 单文件建议

以下是文件级别的代码建议,聚焦于代码的可读性、可维护性和潜在问题。
📜 console-ui/src/pages/AI/NewMcpServer/NewMcpServer.js (2 💬)

🚀 跨文件建议

以下是对代码架构和设计的综合分析,聚焦于跨文件交互、系统一致性和潜在优化空间。
🔍 1. 跨文件的空值处理逻辑需要统一规范

当前在NewMcpServer.js中对groupName字段的空值处理存在两种不同实现方式:第108行使用可选链直接赋值,而第212行采用条件判断合并serverGroup和表单值。这种不一致可能在其他组件中也存在类似问题,导致系统行为不一致。建议建立统一的空值处理规范(如中央化验证函数或配置),避免分散的逻辑导致维护困难。

📌 关键代码:

initFileData['groupName'] = remoteServerConfig?.serviceRef?.groupName;
const groupName = serverGroup?.groupName || values?.groupName;

⚠️ 潜在风险: 不一致的空值处理可能导致不同场景下出现undefined值,引发后续接口调用失败或数据不一致问题,增加排查难度。

🔍 2. 潜在的代码重复风险

第212行和第108行均实现了对groupName的空值防护逻辑,但实现方式不同。若其他组件(如EditMcpServer.js或服务端接口)也存在类似逻辑,可能产生重复代码。建议将这类字段验证逻辑提取为共享的辅助函数(如getSafeGroupName),提升代码复用性和维护效率。

📌 关键代码:

initFileData['groupName'] = remoteServerConfig?.serviceRef?.groupName;
const groupName = serverGroup?.groupName || values?.groupName;

⚠️ 潜在风险: 重复逻辑会增加维护成本,当业务规则变更时需同步修改多处代码,容易遗漏导致系统行为不一致。

🔍 3. 缺乏对空值场景的端到端测试覆盖

当前PR仅在组件层面增加了空值保护,但未提供针对groupName缺失时的端到端测试案例。例如未验证当remoteServerConfig.serviceRef.groupNamevalues.groupName同时为undefined时,接口参数是否能正确回退到空字符串。建议补充对应测试用例,确保边界场景的稳定性。

⚠️ 潜在风险: 未覆盖的边缘场景可能在生产环境中引发nullundefined值传递到后端,导致服务端错误或数据污染。

🔍 4. 服务组(serverGroup)的关联性未做系统性校验

第211行通过serviceList.find获取serverGroup对象,但未验证其是否存在。若serverGroupnull时,后续serverGroup?.groupName的逻辑可能无法满足业务需求(如强制要求组名存在)。需确保服务选择与组名存在性之间的业务规则一致性。

📌 关键代码:

const serverGroup = serviceList.find(item => item.value === values?.service);

⚠️ 潜在风险: 可能导致无效的组名被提交到后端,引发配置错误或服务启动失败。


💡 小贴士

与 lingma-agents 交流的方式

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

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

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

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

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

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

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

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

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

@@ -105,7 +105,7 @@ class NewMcpServer extends React.Component {
: false;
initFileData['namespace'] = remoteServerConfig?.serviceRef?.namespaceId;
initFileData['service'] = remoteServerConfig?.serviceRef?.serviceName;

initFileData['groupName'] = remoteServerConfig?.serviceRef?.groupName;
Copy link

Choose a reason for hiding this comment

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

为groupName字段添加空值保护逻辑

🟡 Major | 🧹 Code Smells

📋 问题详情

在第108行直接使用可选链赋值可能导致groupName字段为undefined。如果后端要求该字段必须存在,未处理空值可能导致接口调用失败或数据异常。需确保该字段在空值时提供合理默认值或校验

💡 解决方案

应为groupName字段添加默认值保护,例如使用空字符串或业务约定的默认值:

- initFileData['groupName'] = remoteServerConfig?.serviceRef?.groupName;
+ initFileData['groupName'] = remoteServerConfig?.serviceRef?.groupName || '';

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

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

@@ -209,15 +209,15 @@ class NewMcpServer extends React.Component {
);
// 添加服务
const serverGroup = serviceList.find(item => item.value === values?.service);

const groupName = serverGroup?.groupName || values?.groupName;
Copy link

Choose a reason for hiding this comment

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

改进serverGroup的空值处理逻辑

🟡 Major | 🐞 Bugs

📋 问题详情

在第212行,当serviceList.find未找到匹配项时serverGroup可能为undefined,此时访问serverGroup.groupName会导致空值穿透。需确保在serverGroup不存在时提供备用值或校验

💡 解决方案

建议增加对serverGroup存在的校验,并明确备用逻辑:

- const serverGroup = serviceList.find(item => item.value === values?.service);
- const groupName = serverGroup?.groupName || values?.groupName;
+ const serverGroup = serviceList.find(item => item.value === values?.service);
+ const groupName = serverGroup ? serverGroup.groupName : (values?.groupName || '');

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

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

@Aias00 Aias00 changed the title [fix] fix mcp server group error [fix] [issue #13365]fix mcp server group error May 12, 2025
@Aias00 Aias00 changed the title [fix] [issue #13365]fix mcp server group error [fix] fix mcp server group error May 12, 2025
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.33%. Comparing base (4c3552d) to head (72b0362).

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##             develop   #13364      +/-   ##
=============================================
- Coverage      70.34%   70.33%   -0.01%     
  Complexity     11714    11714              
=============================================
  Files           1592     1592              
  Lines          50984    50984              
  Branches        5149     5149              
=============================================
- Hits           35865    35860       -5     
- Misses         12688    12696       +8     
+ Partials        2431     2428       -3     

see 5 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 4c3552d...72b0362. 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 11722cf into alibaba:develop May 14, 2025
3 checks passed
@wuyfee
Copy link

wuyfee commented May 14, 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

@Aias00
Copy link
Contributor Author

Aias00 commented May 14, 2025

F A I L U R E 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

image hi, the error info shows `helm install failed`

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.

4 participants