-
Notifications
You must be signed in to change notification settings - Fork 902
feat: Add Higress API MCP server #2517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
添加Higress API MCP服务器并支持多架构构建变更概述新功能
文档更新
重构
变更文件
时序图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
💡 小贴士与 lingma-agents 交流的方式📜 直接回复评论
📜 在代码行处标记
📜 在讨论中提问
Change OverviewNew Features
Document Update
Refactor
Change file
Sequence chartsequenceDiagram
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
💡 TipsHow to communicate with lingma-agents📜 Reply to comments directly
**📜 Mark ** at line of code
📜 Ask a question during discussion
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ 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 🚀 New features to boost your workflow:
|
There was a problem hiding this 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 💬)
- HTTP客户端的超时时间不可配置 (L28-L30)
- 未检查HTTP状态码可能导致错误响应未被正确处理 (L76-L80)
- JSON解析错误时未记录详细日志 (L88-L92)
📖 plugins/golang-filter/mcp-server/servers/higress/higress-api/README.md (1 💬)
- 配置示例中密码以明文形式存储 (L72)
🔹 plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/plugins/request-block.go (3 💬)
- API路径拼接存在潜在安全风险 (L32)
- 需要对resource_name参数进行非法字符验证以防止路径遍历攻击 (L52)
- JSON反序列化时未处理嵌套结构 (L66-L67)
🔹 plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/plugins/util.go (2 💬)
- 插件作用域验证逻辑可优化 (L17-L21)
- BuildPluginPath函数的默认分支逻辑存在冗余 (L39)
🔹 plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/route.go (3 💬)
- 路由名称参数未进行路径注入防护 (L66)
- 路由更新的Schema未限制域名数量违反注释说明 (L194-L199)
- 添加路由时未校验服务权重合理性 (L249)
🚀 架构设计建议
以下是对代码架构和设计的综合分析,聚焦于跨文件交互、系统一致性和潜在优化空间。
🔍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.goplugins/golang-filter/mcp-server/servers/higress/higress-api/README.mdplugins/golang-filter/mcp-server/servers/higress/higress-api/README_en.mdplugins/golang-filter/mcp-server/servers/higress/higress-api/server.goplugins/golang-filter/mcp-server/servers/higress/higress-api/tools/plugins/common.goplugins/golang-filter/mcp-server/servers/higress/higress-api/tools/plugins/request-block.goplugins/golang-filter/mcp-server/servers/higress/higress-api/tools/plugins/util.goplugins/golang-filter/mcp-server/servers/higress/higress-api/tools/route.goplugins/golang-filter/mcp-server/servers/higress/higress-api/tools/service.goplugins/golang-filter/mcp-server/servers/higress/higress-ops/.keepplugins/golang-filter/mcp-server/servers/higress/nginx-migration/.keep
📝 变更文件:
plugins/golang-filter/README.mdplugins/golang-filter/README_en.mdplugins/golang-filter/mcp-server/config.go
💡 小贴士
与 lingma-agents 交流的方式
📜 直接回复评论
直接回复本条评论,lingma-agents 将自动处理您的请求。例如:
-
在当前代码中添加详细的注释说明。
-
请详细介绍一下你说的 LRU 改造方案,并使用伪代码加以说明。
📜 在代码行处标记
在文件的特定位置创建评论并 @lingma-agents。例如:
-
@lingma-agents 分析这个方法的性能瓶颈并提供优化建议。
-
@lingma-agents 对这个方法生成优化代码。
📜 在讨论中提问
在任何讨论中 @lingma-agents 来获取帮助。例如:
-
@lingma-agents 请总结上述讨论并提出解决方案。
-
@lingma-agents 请根据讨论内容生成优化代码。
plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/plugins/request-block.go
Show resolved
Hide resolved
plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/plugins/util.go
Show resolved
Hide resolved
plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/plugins/util.go
Show resolved
Hide resolved
plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/route.go
Show resolved
Hide resolved
plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/route.go
Show resolved
Hide resolved
plugins/golang-filter/mcp-server/servers/higress/higress-api/tools/route.go
Show resolved
Hide resolved
johnlanni
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Ⅰ. Describe what this PR did
使用 golang-filter 重新实现:https://github.com/higress-group/higress-ops-mcp-server
实现效果:
开源之夏的项目代码可以在 higress 目录下进行补充:
Ⅱ. 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