APISIX 模型上下文协议 (MCP) 服务器用于连接大型语言模型 (LLMs) 和 APISIX 管理 API。其目标是通过与 MCP 兼容的 AI 客户端实现基于自然语言的交互,以查看和管理 APISIX 中的资源。
https://github.com/user-attachments/assets/081e878c-225e-4ff8-a9c5-5813f4784cfe
get_resource: 根据类型检索资源(路由、服务、上游等)delete_resource: 根据ID删除资源send_request_to_gateway: 向 APISIX 网关发送请求或多个请求create_route/update_route/delete_route: 管理路由create_service/update_service/delete_service: 管理服务create_upstream/update_upstream/delete_upstream: 管理上游create_ssl/update_ssl/delete_ssl: 管理 SSL 证书create_or_update_proto: 管理 protobuf 定义create_or_update_stream_route: 管理流路由get_all_plugin_names: 获取所有可用插件名称get_plugin_info/get_plugins_by_type/get_plugin_schema: 检索插件配置create_plugin_config/update_plugin_config: 管理插件配置create_global_rule/update_global_rule: 管理插件全局规则get_plugin_metadata/create_or_update_plugin_metadata/delete_plugin_metadata: 管理插件元数据get_secret_by_id/create_secret/update_secret: 管理密钥create_or_update_consumer/delete_consumer: 管理消费者get_credential/create_or_update_credential/delete_credential/: 管理消费者凭证create_consumer_group/delete_consumer_group: 管理消费者组按照 APISIX 的 入门指南 设置并运行 APISIX。
要通过 Smithery 自动安装 APISIX 模型上下文协议服务器:
npx -y @smithery/cli install @api7/apisix-mcp --client claude
配置您的 AI 客户端(如 Cursor、Claude、Copilot 等)如下设置:
{
"mcpServers": {
"apisix-mcp": {
"command": "npx",
"args": [
"-y",
"apisix-mcp"
],
"env": {
"APISIX_SERVER_HOST": "your-apisix-server-host",
"APISIX_SERVER_PORT": "your-apisix-server-port",
"APISIX_ADMIN_API_PORT": "your-apisix-admin-api-port",
"APISIX_ADMIN_API_PREFIX": "your--apisix-admin-api-prefix",
"APISIX_ADMIN_KEY": "your-apisix-api-key"
}
}
}
}
首先克隆 apisix-mcp 仓库:
git clone https://github.com/api7/apisix-mcp.git
cd apisix-mcp
安装依赖项并构建项目:
pnpm install
pnpm build
配置您的 AI 客户端(如 Cursor、Claude、Copilot 等)如下设置:
{
"mcpServers": {
"apisix-mcp": {
"command": "node",
"args": [
"your-apisix-mcp-path/dist/index.js"
],
"env": {
"APISIX_SERVER_HOST": "your-apisix-server-host",
"APISIX_SERVER_PORT": "your-apisix-server-port",
"APISIX_ADMIN_API_PORT": "your-apisix-admin-api-port",
"APISIX_ADMIN_API_PREFIX": "your-apisix-admin-api-prefix",
"APISIX_ADMIN_KEY": "your-apisix-api-key"
}
}
}
}
| 变量 | 描述 | 默认值 |
|---|---|---|
APISIX_SERVER_HOST | 可访问您的 APISIX 服务器的主机 | http://127.0.0.1 |
APISIX_SERVER_PORT | APISIX 服务器端口 | 9080 |
APISIX_ADMIN_API_PORT | 管理 API 端口 | 9180 |
APISIX_ADMIN_API_PREFIX | 管理 API 前缀 | /apisix/admin |
APISIX_ADMIN_KEY | 管理 API 认证密钥 | edd1c9f034335f136f87ad84b625c8f1 |
要查看或修改 APISIX 中的管理 API 配置,请参阅 管理 API 文档。
示例:搜索服务器和工具
import anthropic
import mcp_marketplace as mcpm
result_q = mcpm.search(query="apisix mcp", mode="list", page_id=0, count_per_page=100, config_name="deepnlp") # 按类别搜索服务器,选择各种端点
result_id = mcpm.search(id="api7/apisix-mcp", mode="list", page_id=0, count_per_page=100, config_name="deepnlp") # 按 ID 搜索服务器,选择各种端点
tools = mcpm.list_tools(id="api7/apisix-mcp", config_name="deepnlp_tool")
# 调用 Claude 来选择工具函数调用
client = anthropic.Anthropic()
response = client.messages.create(model="claude-3-7-sonnet-20250219", max_tokens=1024, tools=tools, messages=[])