Skip to content

Conversation

@cr7258
Copy link
Collaborator

@cr7258 cr7258 commented Jun 29, 2025

Ⅰ. Describe what this PR did

使用 golang-filter 重新实现:https://github.com/higress-group/higress-ops-mcp-server

实现效果:

CleanShot 2025-06-29 at 23 26 36@2x

CleanShot 2025-06-29 at 23 26 46@2x

开源之夏的项目代码可以在 higress 目录下进行补充:

  • higress-api: Higress API MCP Server,调用 Higress Console API 进行配置
  • higress-ops:Higress Ops MCP Server,配置运维与诊断分析
  • nginx-migration: 实现 Nginx 配置自动转换

Ⅱ. Does this pull request fix one issue?

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

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@lingma-agents
Copy link

lingma-agents bot commented Jun 29, 2025

添加Higress API MCP服务器并支持多架构构建

变更概述

新功能

  • Higress API MCP服务器 (higress-api):
    • 新增路由管理功能:
      • list-routes: 获取所有路由列表
      • get-route: 查询指定路由详情
      • add-route: 创建新路由
      • update-route: 更新路由配置
    • 新增服务来源管理功能:
      • list-service-sources: 获取服务来源列表
      • get-service-source: 查询服务来源详情
      • add-service-source: 添加新服务来源
      • update-service-source: 更新服务来源配置
    • 新增插件管理功能:
      • get-plugin-config: 获取插件配置
      • update-request-block-config: 更新请求拦截插件配置
    • 支持通过Higress Console API进行配置交互,包含完整错误处理和参数校验机制
    • 新增Redis配置参数支持和会话保持路由规则配置

文档更新

  • plugins/golang-filter目录下:
    • 补充了ARM64架构构建说明(通过设置GOARCH=arm64
    • 更新了多语言(中文/英文)配置示例和参数说明文档

重构

  • mcp-server/config.go中:
    • 优化错误信息格式化,统一使用fmt.Errorf带嵌套错误
    • 新增对higress-api服务器的注册支持
变更文件
文件路径 变更说明
plugins/​golang-filter/​README.​md 补充ARM64架构的构建说明,新增GOARCH参数设置
plugins/​golang-filter/​README_​en.​md 补充ARM64架构的构建说明英文版
plugins/​golang-filter/​mcp-server/​config.​go 新增higress-api服务器注册及错误处理优化
plugins/​golang-filter/​mcp-server/​servers/​higress/​client.​go 实现Higress Console API客户端,包含请求封装和错误处理
plugins/​golang-filter/​mcp-server/​servers/​higress/​higress-api/​server.​go 实现Higress API MCP服务器核心逻辑和配置解析
plugins/​golang-filter/​mcp-server/​servers/​higress/​higress-api/​tools/​plugins/​common.​go 实现插件配置获取工具及参数校验
plugins/​golang-filter/​mcp-server/​servers/​higress/​higress-api/​tools/​plugins/​request-block.​go 实现请求拦截插件配置更新功能
plugins/​golang-filter/​mcp-server/​servers/​higress/​higress-api/​tools/​route.​go 实现路由管理的增删改查功能
plugins/​golang-filter/​mcp-server/​servers/​higress/​higress-api/​tools/​service.​go 实现服务来源管理的增删改查功能
时序图
sequenceDiagram
    participant MCPClient as MCP客户端
    participant HigressAPIServer as Higress API MCP Server
    participant HigressConsole as Higress Console
    MCPClient->>HigressAPIServer: 调用MCP工具(如add-route)
    HigressAPIServer->>HigressConsole: 发送HTTP请求到对应API端点
    HigressConsole-->>HigressAPIServer: 返回操作结果
    HigressAPIServer-->>MCPClient: 将结果返回给客户端
    opt 错误处理
        HigressAPIServer->>HigressAPIServer: 校验HTTP响应状态码
        HigressAPIServer->>MCPClient: 抛出带详细信息的错误
    end
Loading

💡 小贴士

与 lingma-agents 交流的方式

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

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

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

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

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

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

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

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

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

--- ### Add Higress API MCP server and support multi-architecture construction
Change Overview

New Features
Higress API MCP Server (higress-api):

  • Added routing management function:
    • list-routes: Get list of all routes
    • get-route: Query the specified route details
    • add-route: Create a new route
    • update-route: Update routing configuration
  • Added service source management function:
    • list-service-sources: Get the list of service sources
    • get-service-source: Query service source details
    • add-service-source: Add a new service source
    • update-service-source: Update service source configuration
  • Added plug-in management functions:
    • get-plugin-config: Get plugin configuration
    • update-request-block-config: Update request blocking plugin configuration
  • Supports configuration interaction through the Higress Console API, including complete error handling and parameter verification mechanism
  • Added Redis configuration parameters support and session keep routing rules configuration

Document Update

  • In the plugins/golang-filter directory:
    • Supplemented ARM64 architecture construction instructions (by setting GOARCH=arm64)
    • Updated multilingual (Chinese/English) configuration examples and parameter description documents

Refactor

  • In mcp-server/config.go:
    • Optimize error message formatting, use fmt.Errorf with nested errors
    • Added new registration support for higress-api server
Change file
File path Change instructions
plugins/​golang-filter/​README.​md Supplement the construction instructions of the ARM64 architecture and add GOARCH parameter settings
plugins/​golang-filter/​README_​en.​md English version of the construction instructions for supplementing the ARM64 architecture
plugins/​golang-filter/​mcp-server/​config.​go Added new higress-api server registration and error handling optimization
plugins/​golang-filter/​mcp-server/​servers/​higress/​client.​go Implement the Higress Console API client, including request encapsulation and error handling
plugins/​golang-filter/​mcp-server/​servers/​higress/​higress-api/​server.​go Implement the core logic and configuration analysis of the Higress API MCP server
plugins/​golang-filter/​mcp-server/​servers/​higress/​higress-api/​tools/​plugins/​common.​go Implement plug-in configuration acquisition tool and parameter verification
plugins/​golang-filter/​mcp-server/​servers/​higress/​higress-api/​tools/​plugins/​request-block.​go Implement the update function of request intercepting plug-in configuration
plugins/​golang-filter/​mcp-server/​servers/​higress/​higress-api/​tools/​route.​go Implement the function of adding, deleting, modifying and checking of route management
plugins/​golang-filter/​mcp-server/​servers/​higress/​higress-api/​tools/​service.​go Implement the function of adding, deleting, modifying and checking service source management
Sequence chart
sequenceDiagram
    participant MCPClient as MCP Client
    participant HigressAPIServer as Higress API MCP Server
    participant HigressConsole as Higress Console
    MCPClient->>HigressAPIServer: Calling MCP tools (such as add-route)
    HigressAPIServer->>HigressConsole: Send HTTP request to the corresponding API endpoint
    HigressConsole-->>HigressAPIServer: Return operation result
    HigressAPIServer-->>MCPClient: Return the result to the client
    opt error handling
        HigressAPIServer->>HigressAPIServer: Verify HTTP response status code
        HigressAPIServer->>MCPClient: Throw an error with details
    end
Loading

💡 Tips

How to communicate with lingma-agents

📜 Reply to comments directly
Reply to this comment directly and lingma-agents will automatically process your request. For example:

  • _Add detailed comment description in the current code. _

  • _Please introduce the LRU transformation plan you mentioned in detail and explain it using pseudo-code. _

**📜 Mark ** at line of code
Create comments at a specific location in the file and @lingma-agents. For example:

  • _@lingma-agents Analyze the performance bottlenecks of this method and provide optimization suggestions. _

  • _@lingma-agents Generate optimization code for this method. _

📜 Ask a question during discussion
In any discussion @lingma-agents to get help. For example:

  • _@lingma-agents Please summarize the above discussion and propose solutions. _

  • _@lingma-agents Please generate optimization code based on the discussion content. _

@codecov-commenter
Copy link

codecov-commenter commented Jun 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 46.04%. Comparing base (ef31e09) to head (ca30ec3).
Report is 598 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #2517       +/-   ##
===========================================
+ Coverage   35.91%   46.04%   +10.13%     
===========================================
  Files          69       81       +12     
  Lines       11576    13020     +1444     
===========================================
+ Hits         4157     5995     +1838     
+ Misses       7104     6680      -424     
- Partials      315      345       +30     

see 78 files 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

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

总计: 12 个问题

📋 评审意见详情
💡 代码实现建议
以下是文件级别的代码建议,聚焦于代码的可读性、可维护性和潜在问题。
🔹 plugins/golang-filter/mcp-server/servers/higress/client.go (3 💬)
📖 plugins/golang-filter/mcp-server/servers/higress/higress-api/README.md (1 💬)
🔹 plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/plugins/request-block.go (3 💬)
🔹 plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/plugins/util.go (2 💬)
🔹 plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/route.go (3 💬)
🚀 架构设计建议
以下是对代码架构和设计的综合分析,聚焦于跨文件交互、系统一致性和潜在优化空间。
🔍1. 硬编码配置参数导致系统灵活性不足

多个组件中存在硬编码配置值,如HigressClient的HTTP超时时间固定为30秒,且配置文件中密码以明文存储。这些设计会降低系统配置灵活性和安全性。建议将超时时间等参数改为可配置项,并引入加密存储方案处理敏感信息。

📌 关键代码

httpClient: &http.Client{
  Timeout: 30 * time.Second,
},
password: admin

⚠️ 潜在风险

固定超时时间可能导致不同环境性能差异,明文密码存储存在泄露风险,不符合安全规范

🔍2. 缺乏跨模块单元测试覆盖

新增的路由管理、服务源、插件配置等核心功能模块未提供单元测试。未覆盖HigressClient的错误处理路径、API参数校验逻辑等关键场景。建议为工具函数和核心API调用添加单元测试,确保功能可靠性。

📌 关键代码

// handleAddRoute 实现未包含测试
// handleUpdateRequestBlockConfig 未包含测试

⚠️ 潜在风险

缺乏测试可能导致功能缺陷未被发现,升级维护时存在高风险

🔍3. API路径拼接存在安全漏洞

BuildPluginPath函数直接拼接用户提供的resource_name参数,未进行路径规范化处理。例如ScopeDomain场景下使用resource_name作为路径组件,可能引发路径遍历攻击。建议增加路径验证逻辑,禁止特殊字符如../

📌 关键代码

return fmt.Sprintf("/v1/domains/%s/plugin-instances/%s", resourceName, pluginName)

⚠️ 潜在风险

恶意构造的resource_name参数可能导致访问受限资源

🔍4. 服务权重配置未实施边界验证

服务配置中的weight字段未限制数值范围(如0-100),且Schema未定义最大最小值。这可能导致API返回无效权重值,影响负载均衡逻辑。需在schema和参数校验中添加数值范围限制

📌 关键代码

"weight": {"type": "integer", "description": "Service weight"}

⚠️ 潜在风险

无效权重可能导致服务调用比例异常,影响系统稳定性

🔍5. 全局错误处理机制缺失

多个API调用未统一错误处理逻辑。例如client.Get/Post方法返回错误时未记录详细堆栈信息,且路由更新等操作未处理API返回的非2xx状态码。建议建立统一的错误捕获和日志记录机制

📌 关键代码

resp, err := c.httpClient.Do(req)
if err != nil {
    return nil, fmt.Errorf("request failed: %w", err)
}

⚠️ 潜在风险

错误信息不完整导致问题排查困难,潜在异常未被妥善处理

审查详情
📒 文件清单 (14 个文件)
新增: 11 个文件
📝 变更: 3 个文件

✅ 新增文件:

  • plugins/golang-filter/mcp-server/servers/higress/client.go
  • plugins/golang-filter/mcp-server/servers/higress/higress-api/README.md
  • plugins/golang-filter/mcp-server/servers/higress/higress-api/README_en.md
  • plugins/golang-filter/mcp-server/servers/higress/higress-api/server.go
  • plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/plugins/common.go
  • plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/plugins/request-block.go
  • plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/plugins/util.go
  • plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/route.go
  • plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/service.go
  • plugins/golang-filter/mcp-server/servers/higress/higress-ops/.keep
  • plugins/golang-filter/mcp-server/servers/higress/nginx-migration/.keep

📝 变更文件:

  • plugins/golang-filter/README.md
  • plugins/golang-filter/README_en.md
  • plugins/golang-filter/mcp-server/config.go

💡 小贴士

与 lingma-agents 交流的方式

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

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

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

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

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

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

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

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

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

Copy link
Collaborator

@johnlanni johnlanni left a comment

Choose a reason for hiding this comment

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

LGTM

@johnlanni johnlanni merged commit 45eb76d into alibaba:main Jul 3, 2025
12 checks passed
daixijun pushed a commit to daixijun/higress that referenced this pull request Jul 3, 2025
ink-hz pushed a commit to ink-hz/higress-ai-capability-auth that referenced this pull request Nov 5, 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.

3 participants