Token导航 LogoToken导航TokenDH.com
Kong Gateway MCP Plugins logo
AI代理未说明官方级别未说明来源级核验

Kong Gateway MCP Plugins

MCP Server

Kong API网关服务,提供MCP特定插件的速率限制和遥测功能,适用于API管理和监控场景。

工具数

0

提示词数

0

GitHub Stars

0

资源数

0
微服务API网关AI代理

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

100rbh

提供方

100rbh

最后核验

2026/5/17 20:22

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

MCP上的Kong网关设置

此目录包含一个完整的Kong API网关设置,其中集成了MCP特定的限流和遥测插件,与Apisix设置中使用的相同MCP服务器并行运行。

🏗️ 建筑学

Client → Kong Gateway → MCP Rate Limiter Plugin → MCP Telemetry Plugin → MCP Server
              ↓
        Redis (Rate Limiting) + OpenTelemetry (Telemetry)

🚀 快速入门

  1. 启动 Kong Gateway 堆栈:
   cd kong-gateway-mcp-plugins
   docker-compose up -d
  1. 等孔(Kong)准备好然后配置服务和路由:
   ./setup-kong.sh
  1. 测试设置
   ./test-kong.sh

📂 目录结构

kong-gateway-mcp-plugins/
├── docker-compose.yml          # Kong stack with PostgreSQL, Redis, monitoring
├── config/
│   └── kong.conf              # Kong configuration
├── plugins/
│   ├── mcp-rate-limiter/      # Rate limiting plugin for Kong
│   │   ├── handler.lua        # Plugin logic
│   │   └── schema.lua         # Configuration schema
│   └── mcp-telemetry/         # Telemetry plugin for Kong
│       ├── handler.lua        # Plugin logic
│       └── schema.lua         # Configuration schema
├── setup-kong.sh              # Service/route/plugin configuration script
├── test-kong.sh               # End-to-end test script
└── README.md                  # This file

🔧 配置

服务和路线

安装脚本配置:

  • 服务mcp-http-serverhttp://mcp-http-server:8002
  • 路线: /mcp/http/*mcp-http-server
  • 服务: mcp-sse-serverhttp://mcp-sse-server:8001
  • 路线/mcp/sse/*mcp-sse-server

已应用插件

  1. MCP 速率限制器

- 每分钟3次请求的基本限制 - 1次突发配额(总计:4次请求) - 基于Redis的滑动窗口

  1. MCP遥测:

- OpenTelemetry 追踪和指标 - 基于会话的追踪 - 特定工具的指标

  1. CORS(跨源资源共享):

- 支持跨域的Web客户端

🧪 测试

自动化测试

./test-kong.sh

预期输出:

Request 1: SUCCESS - Current time: 2025-01-01 12:00:00
Request 2: SUCCESS - Current time: 2025-01-01 12:00:00
Request 3: SUCCESS - Current time: 2025-01-01 12:00:00
Request 4: SUCCESS - Current time: 2025-01-01 12:00:00
Request 5: RATE LIMITED (HTTP 429) - Retry after: 60s
Request 6: RATE LIMITED (HTTP 429) - Retry after: 60s
...

手动测试

  1. 初始化MCP会话
   curl -X POST "http://localhost:8000/mcp/http/mcp/" \
     -H "Content-Type: application/json" \
     -H "mcp-session-id: test-123" \
     -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "initialize",
       "params": {
         "protocolVersion": "2024-11-05",
         "capabilities": {},
         "clientInfo": {"name": "test-client", "version": "1.0.0"}
       }
     }'
  1. 调用MCP工具
   curl -X POST "http://localhost:8000/mcp/http/mcp/" \
     -H "Content-Type: application/json" \
     -H "mcp-session-id: test-123" \
     -d '{
       "jsonrpc": "2.0",
       "id": 2,
       "method": "tools/call",
       "params": {
         "name": "get_current_time",
         "arguments": {}
       }
     }'

📊 监控

Kong 管理API

  • 管理APIhttp://localhost:8001
  • 查看服务: curl http://localhost:8001/services
  • 查看路线: curl http://localhost:8001/routes
  • 查看插件: curl http://localhost:8001/plugins

可观测性堆栈

  • Jaeger UI(界面)http://localhost:16686 (分布式追踪)
  • 普罗米修斯http://localhost:9090(指标)
  • Grafana(中文可译为“格拉夫纳”或直接保留原名,根据上下文选择是否翻译)http://localhost:3000(仪表板,管理员账号:admin/admin)

日志

# Kong logs
docker logs kong-gateway-mcp-plugins_kong_1

# Redis logs
docker logs kong-gateway-mcp-plugins_redis_1

# MCP server logs
docker logs kong-gateway-mcp-plugins_mcp-http-server_1

🔍 插件详情

MCP限速插件

  • 位置plugins/mcp-rate-limiter/
  • 优先级2000(在请求生命周期早期运行)
  • 特点/功能

- 特定工具的速率限制 - 基于Redis的滑动窗口 - 原子操作防止竞态条件 - 可配置的突发限制

MCP遥测插件

  • 位置: plugins/mcp-telemetry/
  • 优先权1500(限流后运行)
  • 特点/特性

- 基于会话的追踪 - 特定工具的指标 - OpenTelemetry标准合规性 - 异步遥测导出

🆚 Kong 与 Apisix 对比

功能KongApisix
数据库PostgreSQLetcd
插件语言LuaLua
配置 管理员API + 数据库YAML + etcd
演出
生态系统企业 + 开源软件(OSS)Apache 基金会
速率限制Redis + Lua 脚本Redis + Lua 脚本
遥测OpenTelemetryOpenTelemetry

两种实现都提供了相同的功能,包括基于Redis的速率限制和OpenTelemetry遥测功能。

🐛 故障排除

Kong 未启动

# Check database connection
docker logs kong-gateway-mcp-plugins_kong-migrations_1

# Check Kong logs
docker logs kong-gateway-mcp-plugins_kong_1

# Verify Kong config
docker exec kong-gateway-mcp-plugins_kong_1 kong config -c /etc/kong/kong.conf

插件未加载

# Check if plugins are installed
docker exec kong-gateway-mcp-plugins_kong_1 ls -la /opt/kong/plugins/

# Verify plugin configuration
curl http://localhost:8001/plugins

# Check Kong error logs
docker logs kong-gateway-mcp-plugins_kong_1 | grep -i error

速率限制问题

# Check Redis connectivity
docker exec kong-gateway-mcp-plugins_kong_1 nc -zv redis 6379

# Monitor Redis keys
docker exec kong-gateway-mcp-plugins_redis_1 redis-cli KEYS "mcp_rate_limit:*"

# Check plugin logs
docker logs kong-gateway-mcp-plugins_kong_1 | grep "mcp-rate-limiter"

🔄 配置更新

修改速率限制

  1. 使用管理API:
   # Get plugin ID
   PLUGIN_ID=$(curl -s http://localhost:8001/plugins | jq -r '.data[] | select(.name=="mcp-rate-limiter") | .id')

   # Update configuration
   curl -X PATCH "http://localhost:8001/plugins/${PLUGIN_ID}" \
     -d 'config.rate_limits.default.per_minute.requests=5'
  1. 重新运行设置 (将更新现有配置):
   ./setup-kong.sh

添加新的工具限制

更新设置脚本或使用管理员API:

curl -X PATCH "http://localhost:8001/plugins/${PLUGIN_ID}" \
  -d 'config.rate_limits.tools.new_tool.per_minute.requests=10' \
  -d 'config.rate_limits.tools.new_tool.per_minute.window=60' \
  -d 'config.rate_limits.tools.new_tool.per_minute.burst=2'

🔐 安全

  • docker-compose 中的数据库凭据(生产环境需更改)
  • 管理API已暴露在8001端口(生产环境中请限制访问)
  • MCP端点无需认证(根据需要添加Kong认证插件)
  • 未启用认证的 Redis(生产环境请添加密码)

📚 额外资源

目录标签

目录标签

微服务API网关AI代理Lua本地部署速率限制遥测MCP协议

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

session

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明session部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP