This example demonstrates how to use Kong Gateway's ai-mcp-proxy plugin to expose REST APIs as MCP (Model Context Protocol) tools that AI agents can discover and invoke.
The MCP Proxy pattern shows two key capabilities:
- REST API to MCP Conversion - Transform existing REST APIs into MCP tools using the
conversion-listenermode - MCP Server Passthrough - Proxy existing MCP servers using the
passthrough-listenermode
AI Agent
↓
Kong Gateway (localhost:8000)
↓
├── /mcp/chucknorris → Chuck Norris API (converted to MCP)
│ └── Upstream: https://api.chucknorris.io
│
└── /mcp/fetch → Remote MCP Server (passthrough)
└── Upstream: https://remote.mcpservers.org/fetch/mcp
The Kong configuration (kong-config/kong.yaml) defines:
-
Chuck Norris Service
- Upstream:
https://api.chucknorris.io - Route:
/api/chucknorris - Direct REST API access
- Upstream:
-
Chuck Norris MCP Service
- Upstream:
http://host.docker.internal:8000 - Route:
/mcp/chucknorris - MCP tool interface (conversion mode)
- Upstream:
-
Fetch MCP Service
- Upstream:
https://remote.mcpservers.org/fetch/mcp - Route:
/mcp/fetch - MCP server passthrough
- Upstream:
Converts the Chuck Norris REST API into an MCP tool:
plugins:
- name: ai-mcp-proxy
route: chucknorris-mcp
config:
mode: conversion-listener
logging:
log_payloads: true
log_statistics: true
max_request_body_size: 16384
tools:
- annotations:
title: Chuck Norris Random Joke
description: Retrieve a random chuck joke in JSON format.
method: GET
path: /api/chucknorris/jokes/random
parameters:
- name: category
in: query
required: false
description: Retrieve a random chuck norris joke from a given category.
schema:
type: stringKey Features:
- Defines tool schema for AI agents
- Maps REST endpoint to MCP tool
- Supports query parameters
- Enables payload and statistics logging
Proxies an existing MCP server without modification:
plugins:
- name: ai-mcp-proxy
route: fetch-mcp-route
config:
mode: passthrough-listener
logging:
log_payloads: true
log_statistics: true
max_request_body_size: 1048576Key Features:
- Direct MCP protocol passthrough
- No tool schema definition needed
- Larger request body support (1MB)
- Full MCP protocol compatibility
- Docker and Docker Compose
- Kong Gateway with AI MCP Proxy plugin
- OpenAI API key (for testing with AI agents)
-
Start Kong Gateway
Deploy Kong with the configuration:
docker run -d --name kong-mcp-proxy \ -v $(pwd)/kong-config:/kong/declarative \ -e "KONG_DATABASE=off" \ -e "KONG_DECLARATIVE_CONFIG=/kong/declarative/kong.yaml" \ -e "KONG_PROXY_LISTEN=0.0.0.0:8000" \ -e "KONG_ADMIN_LISTEN=0.0.0.0:8001" \ -p 8000:8000 \ -p 8001:8001 \ kong/kong-gateway:latest
-
Verify Configuration
Check that Kong is running:
curl http://localhost:8001/status
Access the Chuck Norris API directly:
curl http://localhost:8000/api/chucknorris/jokes/randomWith a category:
curl "http://localhost:8000/api/chucknorris/jokes/random?category=dev"The MCP endpoints are designed to be accessed by AI agents using the MCP protocol. You can test them with:
- MCP Client Libraries - Use official MCP SDKs
- AI Agents - Configure agents to use
http://localhost:8000/mcp/chucknorris - Volcano SDK - See the
mcp-registry/volcano-agentexample
The plugin is configured with detailed logging:
log_payloads: true- Logs request/response payloadslog_statistics: true- Logs performance metrics
View Kong logs:
docker logs kong-mcp-proxy -fCheck loaded routes and services:
curl http://localhost:8001/routes
curl http://localhost:8001/services
curl http://localhost:8001/plugins- Legacy API Integration - Expose existing REST APIs to AI agents without modification
- API Aggregation - Combine multiple REST APIs into a unified MCP interface
- MCP Gateway - Centralize access to multiple MCP servers
- Tool Discovery - Provide a catalog of tools for AI agents
To expose additional REST APIs as MCP tools:
- Add a new service and route in
kong.yaml - Configure the
ai-mcp-proxyplugin with tool definitions - Reload Kong configuration
Modify max_request_body_size based on your API requirements:
- Small payloads:
16384(16KB) - Large payloads:
1048576(1MB) - Custom size: Any value in bytes
- MCP Registry Pattern - Dynamic tool discovery with registries
- Volcano Agent - AI agent using MCP tools