From 5fd7c2b38f8396bb40bb5435d9c383585c8618fd Mon Sep 17 00:00:00 2001 From: jbaross Date: Fri, 31 Jul 2026 10:03:55 +0100 Subject: [PATCH 1/7] init --- ...autogenerated-mcp-tools-for-weather-api.md | 202 ++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md diff --git a/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md b/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md new file mode 100644 index 0000000000..2c8993bdbe --- /dev/null +++ b/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md @@ -0,0 +1,202 @@ +--- +title: Log MCP traffic for autogenerated MCP Weather API tools +content_type: how_to +related_resources: + - text: "{{site.ai_gateway}}" + url: /ai-gateway/v1/ + - text: AI MCP Proxy + url: /plugins/ai-mcp-proxy/ + - text: HTTP Long + url: /plugins/http-log/ + +description: | + Enable logging in the AI MCP Proxy plugin to capture MCP tool calls, then use the HTTP Log plugin to record and inspect the payloads and responses from the WeatherAPI tool. + +products: + - ai-gateway + +permalink: /ai-gateway/observe-autogenerated-mcp-tools-for-weather-api/ + +series: + id: mcp-conversion-2-0 + position: 2 + +works_on: + - konnect + +min_version: + ai-gateway: '2.0' + +tags: + - ai + - mcp + +tldr: + q: How do I observe and validate MCP traffic from autogenerated tools? + a: | + 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. + +tools: + - kongctl + +cleanup: + inline: + - title: Destroy the {{site.base_gateway}} container + include_content: cleanup/products/gateway + icon_url: /assets/icons/gateway.svg + - title: Clean up {{site.konnect_short_name}} environment + include_content: cleanup/platform/konnect + icon_url: /assets/icons/gateway.svg + +automated_tests: false + +--- + +## Reconfigure the AI MCP Proxy plugin + +To observe traffic for MCP tools, you first must **enable logging and statistics** on the AI MCP. Apply the below configuration to reconfigure the entity while preserving the WeatherAPI key in `tools[].query`: + +{% entity_examples %} + +{% endentity_examples %} + + +{% entity_examples %} +entities: + 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" + query: + key: + - ${key} + 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 +variables: + key: + value: $WEATHERAPI_API_KEY +{% endentity_examples %} + + +## 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: + +{% entity_examples%} +entities: + plugins: + - name: http-log + service: weather-service + config: + http_endpoint: http://host.docker.internal:9999/ + headers: + Authorization: Bearer some-token + method: POST + timeout: 3000 +{% endentity_examples%} + +Let's run a simple log collector script which collect logs at `9999` port. Copy and run this snippet in your terminal: + +``` +cat < 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: + +```sh +python3 log_server.py +``` + +If the script is successful, you'll receive the following prompt in your terminal: + +```sh +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: + +```text +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: + + +```json +{ + "..." + "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" + } + ] + } + } +} +``` From 335b65ff72710130b15ec1299c2a1b89152da16f Mon Sep 17 00:00:00 2001 From: jbaross Date: Fri, 31 Jul 2026 15:36:54 +0100 Subject: [PATCH 2/7] v2 configs --- ...autogenerated-mcp-tools-for-weather-api.md | 151 +++++++++++++----- 1 file changed, 108 insertions(+), 43 deletions(-) diff --git a/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md b/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md index 2c8993bdbe..a2402e1bc2 100644 --- a/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md +++ b/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md @@ -1,5 +1,5 @@ --- -title: Log MCP traffic for autogenerated MCP Weather API tools +title: Monitor MCP traffic with the HTTP Log plugin content_type: how_to related_resources: - text: "{{site.ai_gateway}}" @@ -54,61 +54,126 @@ automated_tests: false ## Reconfigure the AI MCP Proxy plugin -To observe traffic for MCP tools, you first must **enable logging and statistics** on the AI MCP. Apply the below configuration to reconfigure the entity while preserving the WeatherAPI key in `tools[].query`: +To observe traffic for MCP tools, you first must **enable logging and statistics** on the AI MCP. Apply the below configuration to reconfigure the AI MCP to log full payloads: {% entity_examples %} - -{% endentity_examples %} - - -{% entity_examples %} -entities: - 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" - query: - key: - - ${key} - parameters: - - name: q +ai_gateway_mcp_servers: + - ref: marketplace-mcp + ai_gateway: !lookup {id: $AI_GATEWAY_ID} + name: marketplace-mcp + display_name: "Marketplace API" + type: conversion-listener + enabled: true + policies: [] + access: + acl_attribute_type: consumer + acls: + allow: [] + default_tool_acls: + deny: [] + config: + url: http://host.docker.internal:3000 + route: + paths: + - /marketplace + logging: + payloads: true + statistics: true + server: + timeout: 60000 + tools: + - name: get-users + description: Get users + method: GET + path: /marketplace/users + parameters: + - name: id + in: query + required: false + schema: + type: string + description: Optional user ID + - name: get-orders-for-user + description: Get orders for a user + method: GET + path: /marketplace/orders + parameters: + - description: User ID to filter orders in: query + name: userid 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 -variables: - key: - value: $WEATHERAPI_API_KEY {% endentity_examples %} ## 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: +Before we send tool calls, we need to set up the a HTTP Logs Policy to check how many tokens we've managed to save by using our configuration. + +Apply the below config to create an HTTP logs Policy and attach it to the AI MCP entity: {% entity_examples%} -entities: - plugins: - - name: http-log - service: weather-service - config: - http_endpoint: http://host.docker.internal:9999/ - headers: - Authorization: Bearer some-token - method: POST - timeout: 3000 +ai_gateway_policies: + - ref: my-http-log-policy + name: my-http-log-policy + ai_gateway: !lookup {id: $AI_GATEWAY_ID} + type: http-log + enabled: true + global: false + config: + http_endpoint: http://host.docker.internal:9999/ + headers: + Authorization: Bearer some-token + method: POST + timeout: 3000 +ai_gateway_mcp_servers: + - ref: marketplace-mcp + ai_gateway: !lookup {id: $AI_GATEWAY_ID} + name: marketplace-mcp + display_name: "Marketplace API" + type: conversion-listener + enabled: true + policies: [ !ref my-http-log-policy#name ] + access: + acl_attribute_type: consumer + acls: + allow: [] + default_tool_acls: + deny: [] + config: + url: http://host.docker.internal:3000 + route: + paths: + - /marketplace + logging: + payloads: true + statistics: true + server: + timeout: 60000 + tools: + - name: get-users + description: Get users + method: GET + path: /marketplace/users + parameters: + - name: id + in: query + required: false + schema: + type: string + description: Optional user ID + - name: get-orders-for-user + description: Get orders for a user + method: GET + path: /marketplace/orders + parameters: + - description: User ID to filter orders + in: query + name: userid + required: true + schema: + type: string {% endentity_examples%} Let's run a simple log collector script which collect logs at `9999` port. Copy and run this snippet in your terminal: From 041ea7ae4c44caec8ac649723a5df0251dedd5fe Mon Sep 17 00:00:00 2001 From: jbaross Date: Fri, 31 Jul 2026 16:11:45 +0100 Subject: [PATCH 3/7] functioning config and verification --- ...autogenerated-mcp-tools-for-weather-api.md | 160 +++++++++++++++--- 1 file changed, 133 insertions(+), 27 deletions(-) diff --git a/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md b/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md index a2402e1bc2..8cf388a373 100644 --- a/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md +++ b/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md @@ -56,7 +56,8 @@ automated_tests: false To observe traffic for MCP tools, you first must **enable logging and statistics** on the AI MCP. Apply the below configuration to reconfigure the AI MCP to log full payloads: -{% entity_examples %} +```sh +kongctl apply -f - --auto-approve --pat "$KONNECT_TOKEN" < Date: Fri, 31 Jul 2026 16:34:59 +0100 Subject: [PATCH 4/7] cleanup --- .../observe-autogenerated-mcp-tools-for-weather-api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md b/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md index 8cf388a373..a4c0085af5 100644 --- a/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md +++ b/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md @@ -244,7 +244,7 @@ You can validate that the HTTP Logs plugin is collecting metrics by generating M what has bob ordered ? ``` -Once Cursor agent has finished reasoning, you will see the following MCP audit log entries logged by the HTTP plugin in your terminal: +Once Chatwise has finished reasoning, you will see MCP audit log entries logged by the HTTP plugin in your terminal similar to the following: ```sh From 85e1bf42371d773509bd22f7e685350736ad12c4 Mon Sep 17 00:00:00 2001 From: jbaross Date: Fri, 31 Jul 2026 16:52:16 +0100 Subject: [PATCH 5/7] rename --- app/_config/releases/ai-gateway/v1.yml | 3 +-- ...r-api.md => monitor-mcp-traffic-with-http-log.md} | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) rename app/_how-tos/ai-gateway/{observe-autogenerated-mcp-tools-for-weather-api.md => monitor-mcp-traffic-with-http-log.md} (98%) diff --git a/app/_config/releases/ai-gateway/v1.yml b/app/_config/releases/ai-gateway/v1.yml index 4ecc0e8dd1..959284b2e7 100644 --- a/app/_config/releases/ai-gateway/v1.yml +++ b/app/_config/releases/ai-gateway/v1.yml @@ -57,8 +57,7 @@ app/_how-tos/ai-gateway/v1/mcp/map-API-to-mcp-tools.md: app/_how-tos/ai-gateway/v1/mcp/map-weather-api-to-mcp-tools.md: canonical_url: /ai-gateway/get-started-with-mcp-server/ app/_how-tos/ai-gateway/v1/mcp/observe-autogenerated-mcp-tools-for-weather-api.md: - status: pending - canonical_url: /ai-gateway/mcp/ + canonical_url: /ai-gateway/monitor-mcp-traffic-with-http-log/ app/_how-tos/ai-gateway/v1/mcp/observe-mcp-traffic-with-acls.md: status: pending canonical_url: /ai-gateway/mcp/ diff --git a/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md b/app/_how-tos/ai-gateway/monitor-mcp-traffic-with-http-log.md similarity index 98% rename from app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md rename to app/_how-tos/ai-gateway/monitor-mcp-traffic-with-http-log.md index a4c0085af5..f5853d4292 100644 --- a/app/_how-tos/ai-gateway/observe-autogenerated-mcp-tools-for-weather-api.md +++ b/app/_how-tos/ai-gateway/monitor-mcp-traffic-with-http-log.md @@ -3,11 +3,11 @@ title: Monitor MCP traffic with the HTTP Log plugin content_type: how_to related_resources: - text: "{{site.ai_gateway}}" - url: /ai-gateway/v1/ - - text: AI MCP Proxy - url: /plugins/ai-mcp-proxy/ - - text: HTTP Long - url: /plugins/http-log/ + url: /ai-gateway/ + - text: AI MCP Server entity + url: /ai-gateway/entities/ai-mcp-server/ + - text: HTTP Log + url: /ai-gateway/policies/http-log/ description: | Enable logging in the AI MCP Proxy plugin to capture MCP tool calls, then use the HTTP Log plugin to record and inspect the payloads and responses from the WeatherAPI tool. @@ -15,7 +15,7 @@ description: | products: - ai-gateway -permalink: /ai-gateway/observe-autogenerated-mcp-tools-for-weather-api/ +permalink: /ai-gateway/monitor-mcp-traffic-with-http-log/ series: id: mcp-conversion-2-0 From 49d5a6ce77343f782c4877881a556b74df49a6b0 Mon Sep 17 00:00:00 2001 From: jbaross Date: Fri, 31 Jul 2026 17:28:47 +0100 Subject: [PATCH 6/7] cleanup --- app/_how-tos/ai-gateway/monitor-mcp-traffic-with-http-log.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/_how-tos/ai-gateway/monitor-mcp-traffic-with-http-log.md b/app/_how-tos/ai-gateway/monitor-mcp-traffic-with-http-log.md index f5853d4292..cb9aca7bea 100644 --- a/app/_how-tos/ai-gateway/monitor-mcp-traffic-with-http-log.md +++ b/app/_how-tos/ai-gateway/monitor-mcp-traffic-with-http-log.md @@ -10,7 +10,7 @@ related_resources: url: /ai-gateway/policies/http-log/ description: | - Enable logging in the AI MCP Proxy plugin to capture MCP tool calls, then use the HTTP Log plugin to record and inspect the payloads and responses from the WeatherAPI tool. + Create an AI MCP from a mock API using `conversion-listener` mode, then use the HTTP Log plugin to record and inspect the payloads and responses from the example MCP. products: - ai-gateway @@ -34,7 +34,7 @@ tags: tldr: q: How do I observe and validate MCP traffic from autogenerated tools? a: | - 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. + Use an AI MCP entity to expose a mock API as an MCP tool, then use the HTTP Log plugin to capture tool calls and validate their payloads and responses. tools: - kongctl From 1a5212f40e93b0b1c667f5d1b91b330a94ddf815 Mon Sep 17 00:00:00 2001 From: jbaross Date: Thu, 6 Aug 2026 14:46:24 +0100 Subject: [PATCH 7/7] cleanup --- app/_how-tos/ai-gateway/monitor-mcp-traffic-with-http-log.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/_how-tos/ai-gateway/monitor-mcp-traffic-with-http-log.md b/app/_how-tos/ai-gateway/monitor-mcp-traffic-with-http-log.md index cb9aca7bea..ffe2e28d57 100644 --- a/app/_how-tos/ai-gateway/monitor-mcp-traffic-with-http-log.md +++ b/app/_how-tos/ai-gateway/monitor-mcp-traffic-with-http-log.md @@ -10,7 +10,7 @@ related_resources: url: /ai-gateway/policies/http-log/ description: | - Create an AI MCP from a mock API using `conversion-listener` mode, then use the HTTP Log plugin to record and inspect the payloads and responses from the example MCP. + Create an AI MCP from a mock API using `conversion-listener` mode, then use the HTTP Log Policy to record and inspect the payloads and responses from the example MCP. products: - ai-gateway @@ -34,7 +34,7 @@ tags: tldr: q: How do I observe and validate MCP traffic from autogenerated tools? a: | - Use an AI MCP entity to expose a mock API as an MCP tool, then use the HTTP Log plugin to capture tool calls and validate their payloads and responses. + Use an AI MCP entity to expose a mock API as an MCP tool, then use the HTTP Log Policy to capture tool calls and validate their payloads and responses. tools: - kongctl