这是一个实现了模型上下文协议(MCP)的服务器,它能够全面配置和管理Higress。此仓库还提供了一个基于LangGraph和LangChain MCP Adapters构建的MCP客户端,通过精心设计的代理流程架构促进与Higress MCP服务器之间的交互。
https://github.com/user-attachments/assets/bae66b77-a158-452e-9196-98060bac0df7
将.env.example
文件复制为.env
并填写相应的值。
在标准输入输出模式下,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控制台API交互,在HigressClient中添加新方法
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:在服务器中注册您的工具类
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
]
