Log MCP traffic for autogenerated MCP Weather API tools

Incompatible with
konnect
Related Resources
Minimum Version
Kong Gateway - 3.12
TL;DR

Use the AI MCP Proxy plugin to expose the upstream WeatherAPI as an MCP tool, then use the HTTP Log plugin to capture tool calls and validate their payloads and responses.

Prerequisites

This page is part of the Autogenerate and observe MCP tools for Weather API series.

Complete the previous page, Autogenerate MCP tools for Weather API before completing this page.

decK is a CLI tool for managing Kong Gateway declaratively with state files. To complete this tutorial, install decK version 1.43 or later.

This guide uses deck gateway apply, which directly applies entity configuration to your Gateway instance. We recommend upgrading your decK installation to take advantage of this tool.

You can check your current decK version with deck version.

Reconfigure the AI MCP Proxy plugin

To observe traffic for MCP tools, you first must enable logging and statistics on the AI MCP Proxy plugin. Apply the below configuration for the AI MCP Proxy plugin with enabled logging capabilities:

echo '
_format_version: "3.0"
plugins:
  - name: ai-mcp-proxy
    route: weather-route
    config:
      logging:
        log_payloads: true
        log_statistics: true
      mode: conversion-listener
      tools:
      - description: Get current weather for a location
        method: GET
        path: "/weather"
        parameters:
        - name: q
          in: query
          required: true
          schema:
            type: string
          description: Location query. Accepts US Zipcode, UK Postcode, Canada Postalcode,
            IP address, latitude/longitude, or city name.
      server:
        timeout: 60000
' | deck gateway apply -

Log MCP traffic

Before we send tool calls, we need to set up the HTTP Logs plugin to check how many tokens we’ve managed to save by using our configuration. First, create an HTTP logs plugin:

echo '
_format_version: "3.0"
plugins:
  - name: http-log
    service: weather-service
    config:
      http_endpoint: http://host.docker.internal:9999/
      headers:
        Authorization: Bearer some-token
      method: POST
      timeout: 3000
' | deck gateway apply -

Let’s run a simple log collector script which collect logs at 9999 port. Copy and run this snippet in your terminal:

cat <<EOF > log_server.py
from http.server import BaseHTTPRequestHandler, HTTPServer
import datetime

LOG_FILE = "kong_logs.txt"

class LogHandler(BaseHTTPRequestHandler):
    def do_POST(self):
        timestamp = datetime.datetime.now().isoformat()

        content_length = int(self.headers['Content-Length'])
        post_data = self.rfile.read(content_length).decode('utf-8')

        log_entry = f"{timestamp} - {post_data}\n"
        with open(LOG_FILE, "a") as f:
            f.write(log_entry)

        print("="*60)
        print(f"Received POST request at {timestamp}")
        print(f"Path: {self.path}")
        print("Headers:")
        for header, value in self.headers.items():
            print(f"  {header}: {value}")
        print("Body:")
        print(post_data)
        print("="*60)

        # Send OK response
        self.send_response(200)
        self.end_headers()
        self.wfile.write(b"OK")

if __name__ == '__main__':
    server_address = ('', 9999)
    httpd = HTTPServer(server_address, LogHandler)
    print("Starting log server on http://0.0.0.0:9999")
    httpd.serve_forever()
EOF

Now, run this script with Python:

python3 log_server.py

If the script is successful, you’ll receive the following prompt in your terminal:

Starting log server on http://0.0.0.0:9999

Validate MCP tools configuration

You can validate that the HTTP Logs plugin is collecting metrics by generating MCP traffic to the weather-service. Enter the following question in the Cursor chat:

What is the current weather in New York?

Once Cursor agent has finished reasoning, you will see the following MCP audit log entries logged by the HTTP plugin in your terminal:

{
  "..."
  "ai": {
    "mcp": {
      "mcp_session_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "rpc": [
        {
          "tool_name": "weather-route-1",
          "id": "19",
          "latency": 200,
          "response_body_size": 1053,
          "payload": {
            "request": "{\"params\":{\"name\":\"weather-route-1\",\"arguments\":{\"query_key\":\"02e7c45e34024e6ca7e52559251908\",\"query_q\":\"New York\"},\"_meta\":{\"progressToken\":19}},\"id\":19,\"jsonrpc\":\"2.0\",\"method\":\"tools/call\"}",
            "response": "{\"result\":{\"isError\":false,\"content\":[{\"type\":\"text\",\"text\":\"{\\\"location\\\":{\\\"name\\\":\\\"New York\\\",\\\"region\\\":\\\"New York\\\",\\\"country\\\":\\\"United States of America\\\",\\\"lat\\\":40.7142,\\\"lon\\\":-74.0064,\\\"tz_id\\\":\\\"America/New_York\\\",\\\"localtime_epoch\\\":1755764969,\\\"localtime\\\":\\\"2025-08-21 04:29\\\"},\\\"current\\\":{\\\"temp_c\\\":15.4,\\\"temp_f\\\":59.7,\\\"condition\\\":{\\\"text\\\":\\\"Light rain\\\"}}}]}},\"id\":19,\"jsonrpc\":\"2.0\"}"
          },
          "method": "tools/call"
        }
      ]
    }
  }
}

Cleanup

curl -Ls https://get.konghq.com/quickstart | bash -s -- -d
Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!