Observe GitHub MCP traffic with Kong AI Gateway
Use the AI Proxy Advanced plugin to enable detailed logging of request payloads and statistics for all AI models. Then enable and configure the Prometheus plugin on Kong AI Gateway to scrape these metrics. This setup allows you to monitor MCP traffic in real time and analyze model usage and performance with Prometheus.
Prerequisites
Series Prerequisites
This page is part of the Secure, govern and observe MCP traffic with Kong AI Gateway series.
Complete the previous page, Use Kong AI Gateway to govern GitHub MCP traffic before completing this page.
Reconfigure the AI Proxy Advanced plugin
Now, you can enable detailed logging for all configured models in the AI Proxy Advanced plugin. This captures request/response payloads and performance statistics. You can then scrape those statistics using the Prometheus plugin for monitoring and analysis. Apply the configuration below to enable logging for both models.
echo '
_format_version: "3.0"
plugins:
- name: ai-proxy-advanced
config:
balancer:
algorithm: round-robin
targets:
- model:
name: gpt-4
provider: openai
options:
max_tokens: 512
temperature: 1.0
route_type: llm/v1/responses
logging:
log_payloads: true
log_statistics: true
auth:
header_name: Authorization
header_value: Bearer ${{ env "DECK_OPENAI_API_KEY" }}
weight: 50
- model:
name: gpt-4o
provider: openai
options:
max_tokens: 512
temperature: 1.0
route_type: llm/v1/responses
logging:
log_payloads: true
log_statistics: true
auth:
header_name: Authorization
header_value: Bearer ${{ env "DECK_OPENAI_API_KEY" }}
weight: 50
' | deck gateway apply -
Enable the Prometheus plugin
Before you configure Prometheus, enable the Prometheus plugin on Kong Gateway:
echo '
_format_version: "3.0"
plugins:
- name: prometheus
config:
status_code_metrics: true
ai_metrics: true
' | deck gateway apply -
Configure Prometheus
Create a prometheus.yml
file:
touch prometheus.yml
Now, add the following to the prometheus.yml
file to configure Prometheus to scrape Kong Gateway metrics:
scrape_configs:
- job_name: 'kong'
scrape_interval: 5s
static_configs:
- targets: ['kong-quickstart-gateway:8001']
scrape_configs:
- job_name: 'kong'
scrape_interval: 5s
static_configs:
- targets: ['kong-quickstart-gateway:8100']
Run a Prometheus server, and pass it the configuration file created in the previous step:
docker run -d --name kong-quickstart-prometheus \
--network=kong-quickstart-net -p 9090:9090 \
-v $(PWD)/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus:latest
Prometheus will begin to scrape metrics data from Kong Gateway.
Validate
You can validate that the plugin is collecting metrics by generating traffic to the example service.
Now, we can run the script from the previous tutorial again:
for i in {1..5}; do
echo -n "Request #$i — Model: "
curl -s -X POST "http://localhost:8000/anything" \
-H "Accept: application/json" \
-H "apikey: hello_world" \
-H "Content-Type: application/json" \
--json "{
\"tools\": [
{
\"type\": \"mcp\",
\"server_label\": \"gitmcp\",
\"server_url\": \"https://api.githubcopilot.com/mcp/x/repos\",
\"require_approval\": \"never\",
\"headers\": {
\"Authorization\": \"Bearer $GITHUB_PAT\"
}
}
],
\"input\": \"test\"
}" | jq -r '.model'
sleep 10
done
Run the following to query the collected kong_ai_llm_requests_total
metric data:
curl -s 'localhost:9090/api/v1/query?query=kong_ai_llm_requests_total'
This should return something like the following:
{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"kong_ai_llm_requests_total","ai_model":"gpt-4o","ai_provider":"openai","instance":"kong-quickstart-gateway:8001","job":"kong","workspace":"default"},"value":[1750768729.300,"21"]},{"metric":{"__name__":"kong_ai_llm_requests_total","ai_model":"gpt-4","ai_provider":"openai","instance":"kong-quickstart-gateway:8001","job":"kong","workspace":"default"},"value":[1750768729.300,"19"]},{"metric":{"__name__":"kong_ai_llm_requests_total","ai_model":"gpt-4.1","ai_provider":"UNSPECIFIED","instance":"kong-quickstart-gateway:8001","job":"kong","workspace":"default"},"value":[1750768729.300,"1"]}]}}
You can also view the Prometheus expression viewer by opening http://localhost:9090/graph in a browser.