Skip to content

Comments

fix: skip unhealthy or disabled services form nacos and always marshal AllowTools field#3220

Merged
Erica177 merged 5 commits intoalibaba:mainfrom
Aias00:fix/Issue_3192
Jan 15, 2026
Merged

fix: skip unhealthy or disabled services form nacos and always marshal AllowTools field#3220
Erica177 merged 5 commits intoalibaba:mainfrom
Aias00:fix/Issue_3192

Conversation

@Aias00
Copy link
Contributor

@Aias00 Aias00 commented Dec 14, 2025

Ⅰ. Describe what this PR did

skip unhealthy or disabled services form nacos and always marshal AllowTools field

Ⅱ. Does this pull request fix one issue?

fixes #3192

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

Ⅵ. AI Coding Tool Usage Checklist (if applicable)

Please check all applicable items:

  • For new standalone features (e.g., new wasm plugin or golang-filter plugin):

    • I have created a design/ directory in the plugin folder
    • I have added the design document to the design/ directory
    • I have included the AI Coding summary below
  • For regular updates/changes (not new plugins):

    • I have provided the prompts/instructions I gave to the AI Coding tool below
    • I have included the AI Coding summary below

AI Coding Prompts (for regular updates)

AI Coding Summary

Copilot AI review requested due to automatic review settings December 14, 2025 10:11
@lingma-agents
Copy link

lingma-agents bot commented Dec 14, 2025

修复Nacos服务健康检查与工具字段序列化问题

变更概述
  • 问题修复

    • 修复了从Nacos注册中心获取服务时未过滤不健康或禁用服务的问题。现在在生成ServiceEntry时会跳过Healthy为false或Enable为false的服务实例,确保只有可用的服务被纳入管理。
    • 修正了AllowTools字段在JSON序列化时可能被忽略的问题。通过移除omitempty标签,保证该字段始终被正确marshal到输出中,即使其值为空数组。
  • 其他

    • 调整了MCP模型和Nacos watcher中的逻辑处理方式,以提高数据一致性和系统稳定性。
变更文件
文件路径 变更说明
registry/mcp_model.go 修改了McpServerRule结构体中的AllowTools字段,去除了omitempty选项,使其在序列化时总是包含该字段。
registry/​nacos/​mcpserver/​watcher.​go 在处理Nacos服务列表时增加了对服务健康状态和启用状态的检查,并在生成ServiceEntry前跳过非健康或禁用的服务;同时初始化allowTools切片用于后续处理。

💡 小贴士

与 lingma-agents 交流的方式

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

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

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

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

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

  • @lingma-agents 对这个方法生成优化代码。

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

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

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

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 个问题

📋 评审意见详情
💡 代码实现建议
以下是文件级别的代码建议,聚焦于代码的可读性、可维护性和潜在问题。
🔹 registry/mcp_model.go (1 💬)
🔹 registry/nacos/mcpserver/watcher.go (1 💬)
🚀 架构设计建议
以下是对代码架构和设计的综合分析,聚焦于跨文件交互、系统一致性和潜在优化空间。
🔍1. Nacos服务实例过滤逻辑可能影响服务发现的完整性

generateServiceEntry函数中新增了对不健康或禁用服务实例的跳过逻辑。虽然这可以防止无效服务被注册到服务网格,但需确保该策略不会导致某些依赖这些状态信息进行决策的上层系统出现行为异常。建议明确文档说明此过滤机制,并评估是否需要提供配置开关以支持不同场景下的需求。

📌 关键代码

if !service.Healthy || !service.Enable {
		continue
	}

⚠️ 潜在风险

可能导致部分监控、告警或自动化运维工具无法获取完整的服务实例列表,从而影响故障排查和自动恢复能力。

🔍2. `AllowTools`字段强制序列化可能引发兼容性问题

修改后的AllowTools字段去除了omitempty标签,这意味着即使为空也会出现在JSON输出中。这种变更可能会破坏现有客户端的反序列化逻辑,特别是那些未预期接收到空数组字段的旧版本客户端。应进行全面回归测试并考虑引入版本控制来管理API演化。

📌 关键代码

AllowTools []string      `json:"allowTools"`

⚠️ 潜在风险

与历史客户端的向后兼容性风险;潜在的数据传输体积增加。

🔍3. 工具配置处理中的空切片初始化缺乏上下文一致性检查

processToolConfig方法中初始化了一个新的allowTools空切片,但在后续代码中没有看到对该变量的实际使用。如果这是为将来功能预留,则应当添加注释说明意图;如果是遗漏使用的错误,则应及时修正或移除冗余代码,以免造成资源浪费和维护困惑。

📌 关键代码

allowTools := []string{}

⚠️ 潜在风险

代码可读性和维护性的降低;未来扩展时可能出现意料之外的行为。

审查详情
📒 文件清单 (2 个文件)
📝 变更: 2 个文件

📝 变更文件:

  • registry/mcp_model.go
  • registry/nacos/mcpserver/watcher.go

💡 小贴士

与 lingma-agents 交流的方式

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

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

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

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

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

  • @lingma-agents 对这个方法生成优化代码。

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

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

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

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.90%. Comparing base (0ada107) to head (a231e6a).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3220      +/-   ##
==========================================
+ Coverage   46.83%   46.90%   +0.06%     
==========================================
  Files          87       87              
  Lines       12922    12922              
==========================================
+ Hits         6052     6061       +9     
+ Misses       6479     6471       -8     
+ Partials      391      390       -1     

see 1 file with indirect coverage changes

🚀 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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements two distinct fixes for the Nacos MCP server integration: filtering out unhealthy/disabled services from service discovery and ensuring the AllowTools field is always present in JSON marshaling output.

  • Adds health and enabled status checking for Nacos service instances before including them in ServiceEntry endpoints
  • Changes AllowTools field to always marshal (removes omitempty tag) and initializes it as an empty slice instead of nil
  • Aligns AllowTools marshaling behavior with other critical MCP API fields like RequestTemplate, ResponseTemplate, and Security

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
registry/nacos/mcpserver/watcher.go Adds health check filtering (lines 820-822) and initializes allowTools as empty slice (line 437) to ensure non-nil value
registry/mcp_model.go Removes omitempty from AllowTools JSON tag to ensure field is always present in marshaled output

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Erica177
Copy link
Collaborator

please sign the license/cla

@Aias00
Copy link
Contributor Author

Aias00 commented Jan 13, 2026

please sign the license/cla

i dont know why, i allready signed. and im not first time to submit a pr

@CH3CHO
Copy link
Collaborator

CH3CHO commented Jan 13, 2026

Could you push another dummy commit and trigger the check again?

@Aias00
Copy link
Contributor Author

Aias00 commented Jan 13, 2026

Could you push another dummy commit and trigger the check again?

okay, i will try

@Aias00
Copy link
Contributor Author

Aias00 commented Jan 13, 2026

please sign the license/cla

hi,cla check is passed.

@Erica177 Erica177 merged commit eb7b22d into alibaba:main Jan 15, 2026
8 checks passed
Jing-ze pushed a commit that referenced this pull request Jan 19, 2026
…l `AllowTools` field (#3220)

Co-authored-by: EricaLiu <30773688+Erica177@users.noreply.github.com>
johnlanni pushed a commit that referenced this pull request Jan 31, 2026
…l `AllowTools` field (#3220)

Co-authored-by: EricaLiu <30773688+Erica177@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants