Skip to main content

Kong API Gateway Integration Guide

Complete guide for integrating MCP Server with LangGraph with Kong API Gateway for rate limiting, authentication, and API management.

Table of Contents

Overview

Kong API Gateway provides:
  • Rate Limiting: Per-consumer, per-service, global limits
  • Authentication: JWT, API Key, OAuth2, Basic Auth
  • Traffic Control: Request/response transformation, routing
  • Security: IP restriction, bot detection, CORS
  • Observability: Prometheus metrics, logging, tracing

Installation

Option 2: Kong DB-less (Declarative Configuration)

Rate Limiting

Basic Rate Limiting (All Users)

Apply to Ingress:

Redis-based Rate Limiting (Distributed)

For multi-replica Kong deployments, use Redis for shared state:

Tiered Rate Limiting

Free Tier (60 req/min, 1,000 req/hour):
Premium Tier (300 req/min, 10,000 req/hour):
Enterprise Tier (1,000 req/min, 100,000 req/hour):

Advanced Rate Limiting

Per-consumer with consumer groups:

Authentication

API Key Authentication

1. Create KongPlugin:
2. Create Consumer:
3. Test:

JWT Authentication

1. Create KongPlugin:
2. Create Consumer with JWT:
3. Generate and test JWT:

OAuth2 Authentication

Deployment

Deploy with Kubernetes Manifests

Deploy with Helm

Custom values file:

Multi-Tenancy

Separate Endpoints per Tier

Free Tier:
Premium Tier:
Enterprise Tier:

Path-based Routing

Consumer Groups

Monitoring

Prometheus Metrics

Enable Prometheus plugin:
Metrics exposed at:
Example metrics:

ServiceMonitor for Prometheus Operator

Request Logging

Advanced Features

Request/Response Transformation

IP Restriction

Bot Detection

Circuit Breaker

Enable during maintenance:

Canary Releases

Troubleshooting

Check Kong Status

Test Rate Limiting

Check Rate Limit Headers

Debug Kong Logs

Common Issues

Rate limiting not working:
  • Check plugin is applied to route/service
  • Verify Redis connectivity (for distributed)
  • Check consumer credentials
Authentication failures:
  • Verify consumer exists
  • Check credential format
  • Review JWT expiration
502 Bad Gateway:
  • Check backend service is running
  • Verify service name in Kong configuration
  • Check health checks

Kong Admin API

Testing Rate Limits

Python Test Script

Production Checklist

  • Use Redis for distributed rate limiting
  • Configure appropriate rate limits per tier
  • Enable authentication (JWT or API Key)
  • Set up monitoring and alerting
  • Configure health checks
  • Enable request logging
  • Set up IP whitelisting if needed
  • Configure bot detection
  • Test rate limiting before production
  • Document rate limits in API docs
  • Set up consumer management
  • Configure CORS appropriately
  • Enable Prometheus metrics
  • Test failover scenarios

Resources