首页
学习
活动
专区
圈层
工具
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
首页
学习
活动
专区
圈层
工具
MCP广场
MCP广场 >详情页
higress-ops-mcp-server2025-05-210分享
github
一种模型上下文协议服务器,通过设计精良的代理流架构,实现对 Higress 的全面配置和管理。
By higress-group
2025-05-210
github
详情内容

Higress OPS MCP 服务器

这是一个实现了模型上下文协议(MCP)的服务器,它能够全面配置和管理Higress。此仓库还提供了一个基于LangGraphLangChain MCP Adapters构建的MCP客户端,通过精心设计的代理流程架构促进与Higress MCP服务器之间的交互。

演示

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

配置环境变量

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

启动MCP客户端和MCP服务器

在标准输入输出模式下,MCP服务器进程由MCP客户端程序启动。运行以下命令来启动MCP客户端和MCP服务器:

uv run client.py

添加新工具

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

  • 如果是添加一个全新的工具类别,请在tools目录下创建一个新文件。
  • 或者如果您的工具适合现有的类别,则可以将其添加到现有的类中。
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控制台API交互,在HigressClient中添加新方法

  • 在utils/higress_client.py中添加封装了API调用的方法。
  • 使用现有的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会自动设置logger和higress_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
]
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档