
模型上下文协议(MCP)服务器实现,实现Higress的全面配置和管理。
概览
一个模型上下文协议(MCP)服务器实现,实现Higress的全面配置和管理。该仓库还基于LangGraph和LangChain MCP适配器构建了一个MCP客户端,通过设计良好的代理流架构促进与Higress MCP服务器的交互。 https://github.com/user-attachments/assets/bae66b77-a158-452e-9196-98060bac0df7 将 .env.example 文件复制到 .env 并填写相应的值。 在stdio模式下,MCP客户端程序启动MCP服务器进程。执行以下命令启动MCP客户端和MCP服务器: - 如果添加全新的工具类别,则在工具目录中创建新文件- 或者如果工具符合现有类别,则将其添加到已有类别 - 在 utils/higress_client.py 中添加封装 API 调用的方法- 使用现有的 HTTP 方法(get、put、post)进行实际 API 通信 - 将你的工具类添加到服务器的tool_classes列表。
概述(AI 翻译)
一个模型上下文协议(MCP)服务器实现,实现Higress的全面配置和管理。该仓库还基于LangGraph和LangChain MCP适配器构建了一个MCP客户端,通过设计良好的代理流架构促进与Higress MCP服务器的交互。
演示
https://github.com/user-attachments/assets/bae66b77-a158-452e-9196-98060bac0df7
配置环境变量
将 .env.example 文件复制到 .env,并填写相应的数值。
启动MCP客户端和MCP服务器
在stdio模式下,MCP客户端程序启动MCP服务器进程。执行以下命令启动MCP客户端和MCP服务器:
添加一个新工具
步骤1:创建新工具类或扩展现有工具类
- 如果添加全新的工具类别,则在工具目录中创建新文件
- 或者如果工具符合现有类别,将其添加到已有类别中
步骤2:如果您的工具需要与Higress控制台API交互,请为HigressClient添加新方法
- 在utils/higress_client.py中添加封装API调用的方法
- 使用现有的HTTP方法(get、put、post)进行实际API通信
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
Higress OPS MCP Server
A Model Context Protocol (MCP) server implementation that enables comprehensive configuration and management of Higress. This repository also provides an MCP client built on top of LangGraph and LangChain MCP Adapters, facilitating interaction with the Higress MCP Server through a well-designed agent flow architecture.
Demo
https://github.com/user-attachments/assets/bae66b77-a158-452e-9196-98060bac0df7
Config Environment Variables
Copy the .env.example file to .env and fill in the corresponding values.
Start MCP Client and MCP Server
In stdio mode, the MCP server process is started by the MCP client program. Run the following command to start the MCP client and MCP server:
uv run client.py
Add a new tool
Step 1: Create a new tool class or extend an existing one
- Create a new file in the tools directory if adding a completely new tool category
- Or add your tool to an existing class if it fits an existing category
from typing import Dict, List, Any
from fastmcp import FastMCP
class YourTools:
def register_tools(self, mcp: FastMCP):
@mcp.tool()
async def your_tool_function(arg1: str, arg2: int) -> List[Dict]:
"""
Your tool description.
Args:
arg1: Description of arg1
arg2: Description of arg2
Returns:
Description of the return value
Raises:
ValueError: If the request fails
"""
# Implementation using self.higress_client to make API calls
return self.higress_client.your_api_method(arg1, arg2)
Step 2: Add a new method to HigressClient if your tool needs to interact with the Higress Console API
- Add methods to utils/higress_client.py that encapsulate API calls
- Use the existing HTTP methods (get, put, post) for actual API communication
def your_api_method(self, arg1: str, arg2: int) -> List[Dict]:
"""
Description of what this API method does.
Args:
arg1: Description of arg1
arg2: Description of arg2
Returns:
Response data
Raises:
ValueError: If the request fails
"""
path = "/v1/your/api/endpoint"
data = {"arg1": arg1, "arg2": arg2}
return self.put(path, data) # or self.get(path) or self.post(path, data)
Step 3: Register your tool class in the server
- Add your tool class to the tool_classes list in server.py
- This list is used by ToolsRegister to instantiate and register all tools
- The ToolsRegister will automatically set logger and higress_client attributes
tool_classes = [
CommonTools,
RequestBlockTools,
RouteTools,
ServiceSourceTools,
YourTools # Add your tool class here
]
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →