Skip to content

fix: fix nacos mcp server import with endpoint info#122

Merged
learnerjohn merged 1 commit intohigress-group:mainfrom
luoxiner:fix-nacos-mcp-import
Dec 15, 2025
Merged

fix: fix nacos mcp server import with endpoint info#122
learnerjohn merged 1 commit intohigress-group:mainfrom
luoxiner:fix-nacos-mcp-import

Conversation

@luoxiner
Copy link
Copy Markdown
Contributor

  • Refactor Nacos MCP endpoint URL building to use McpEndpointInfo directly
  • Add unit tests for endpoint URL construction and remote config
  • Manage Surefire plugin in parent pom so JUnit 5 tests run

Change-Id: Ic8287a5f8c1ce946c586d7360eead5f2faf2bceb

Description

  • Refactored Nacos MCP backend endpoint URL construction to use com.alibaba.nacos.api.ai.model.mcp.McpEndpointInfo directly (based on protocol/address/port/path), removing the previous Object/Map/reflection parsing to improve type-safety and maintainability. The implementation also handles inputs such as full URLs, host:port, and IPv6 forms.
  • Added unit tests to cover endpoint URL construction and buildRemoteConnectionConfig output to prevent regressions.
  • Managed maven-surefire-plugin in the parent pom.xml to ensure JUnit 5 tests are properly discovered and executed across modules.

Related Issues

#121

  • N/A

Checklist

  • Code has been formatted with mvn spotless:apply
  • Code is self-reviewed
  • Tests added/updated (if applicable)
  • Documentation updated (if applicable)
  • No breaking changes (or migration guide provided)

@lingma-agents
Copy link
Copy Markdown

lingma-agents Bot commented Dec 12, 2025

重构Nacos MCP服务器端点URL构建逻辑并添加单元测试

变更概述
  • 新功能

    • 引入了对McpEndpointInfo模型的直接使用,用于构建MCP后端端点URL。
    • 实现了更健壮的URL解析和构造方法,支持全URL、主机名加端口以及IPv6地址格式。
  • 重构

    • 移除了旧有的通过反射和Map处理端点信息的方式,改为类型安全的直接访问方式。
    • 重新组织了buildRemoteConnectionConfig方法中的逻辑以提高可读性和维护性。
  • 问题修复

    • 解决了当输入为完整URL时如何正确填充缺失的端口或路径的问题。
    • 改进了对于不同形式地址(如IPv6)的识别与处理能力。
  • 测试更新

    • 添加了针对extractEndpointUrl方法的全面单元测试用例,覆盖各种边界条件。
    • buildRemoteConnectionConfig方法也增加了验证其输出结构及内容的测试。
  • 依赖更新

    • 在父级pom.xml中升级了nacos.client.version至3.1.1版本。
    • 管理了maven-surefire-plugin插件版本,确保JUnit 5测试能够被正确执行。
  • 配置调整

    • 更新了项目根目录下的pom.xml文件,明确声明并管理maven-surefire-plugin插件版本。
变更文件
文件路径 变更说明
himarket-server/​src/​main/​java/​com/​alibaba/​himarket/​service/​impl/​NacosServiceImpl.​java 新增了导入语句以引入`McpEndpointInfo`类,并实现了新的私有方法来提取和规范化端点URL。同时改进了远程连接配置构建过程,使其更加清晰且易于维护。
himarket-server/​src/​test/​java/​com/​alibaba/​himarket/​service/​impl/​NacosServiceImplEndpointTest.​java 创建了一个全新的测试类,专门用来测试NacosServiceImpl中关于端点URL提取及相关配置生成的方法。该类包含了多个测试场景,保证代码质量。
pom.xml 在项目的主POM文件中更新了Nacos客户端版本号,并加入了对maven-surefire-plugin插件的版本控制,以便更好地支持现代测试框架。
时序图
sequenceDiagram
    participant NS as NacosServiceImpl
    participant ME as McpEndpointInfo
    NS->>ME: 获取协议、地址、端口和路径
    alt 地址是完整的URL
        NS->>NS: 解析URI并补全缺少的部分
    else 处理普通地址或IPv6地址
        NS->>NS: 根据规则拼接URL
    end
    NS->>NS: 返回构造好的URL字符串
Loading

💡 小贴士

与 lingma-agents 交流的方式

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

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

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

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

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

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

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

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

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

- Refactor Nacos MCP endpoint URL building to use McpEndpointInfo directly

- Add unit tests for endpoint URL construction and remote config

- Manage Surefire plugin in parent pom so JUnit 5 tests run

Fix higress-group#121

Change-Id: Ic8287a5f8c1ce946c586d7360eead5f2faf2bceb
@luoxiner luoxiner force-pushed the fix-nacos-mcp-import branch from df41436 to 10106ce Compare December 12, 2025 08:47
@learnerjohn learnerjohn merged commit d9e2404 into higress-group:main Dec 15, 2025
4 of 5 checks passed
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