Higress配置管理服务器

基于MCP协议的Higress网关配置管理服务器,提供通过LangGraph/LangChain代理架构的客户端交互能力

  • by higress-group
  • Python
  • 本地部署
  • 23 星标
  • 更新于
在 GitHub 查看 higress-group/higress-ops-mcp-server

使用说明

Higress OPS MCP服务器

一种模型上下文协议(MCP)服务器实现,支持对 Higress此存储库还提供了一个基于以下内容构建的MCP客户端 LangGraph 和 LangChain MCP适配器,通过精心设计的代理流架构促进与Higress MCP Server的交互。

演示

https://github.com/user-attachments/assets/bae66b77-a158-452e-9196-98060bac0df7

配置环境变量

复制 .env.example 文件到 .env 并填写相应的值。

启动MCP客户端和MCP服务器

在stdio模式下,MCP服务器进程由MCP客户端程序启动。运行以下命令以启动MCP客户端和MCP服务器:

uv run client.py

添加新工具

步骤1:创建新的工具类或扩展现有的工具类

  • 如果添加一个全新的工具类别,请在工具目录中创建一个新文件
  • 或者,如果工具符合现有类别,则将其添加到现有类中
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)

步骤2:如果您的工具需要与Higress Console API交互,请向HigressClient添加一个新方法

  • 将封装API调用的方法添加到utils/higress_client.py
  • 使用现有的HTTP方法(get、put、post)进行实际的API通信
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)

步骤3:在服务器中注册您的工具类

  • 将您的工具类添加到server.py中的tool_classes列表中
  • 此列表由ToolsRegister用于实例化和注册所有工具
  • ToolsRegister将自动设置记录器和highress_client属性
tool_classes = [
    CommonTools,
    RequestBlockTools,
    RouteTools,
    ServiceSourceTools,
    YourTools  # Add your tool class here
]

步骤4:将您的工具添加到 SENSITIVE_TOOLS 如果需要人工确认

  • 此列表中的工具在执行前需要人工确认
# Define write operations that require human confirmation
SENSITIVE_TOOLS = [
    "add_route", 
    "add_service_source",
    "update_route",
    "update_request_block_plugin", 
    "update_service_source",
    "your_tool_function"  # Add your tool name here if it requires confirmation
]