--- title: Debugging HTTP Traffic with AI Assistants description: AI assistants can use MockServer MCP tools to set up a forwarding proxy, capture traffic, retrieve request-response pairs, and diagnose mismatches. shortTitle: Debugging with AI layout: page pageOrder: 3 section: 'AI Integration' subsection: true sitemap: priority: 0.8 changefreq: 'monthly' lastmod: 2026-05-22T00:00:00+00:00 ---
One of the most powerful uses of MockServer's MCP integration is AI-assisted HTTP debugging. By combining MockServer's traffic recording capabilities with an AI assistant's ability to analyse data and suggest fixes, you can quickly diagnose and resolve HTTP integration issues.
The debugging workflow follows four steps:
Throughout this workflow, your AI assistant — such as Claude Code or OpenCode, or any other MCP-capable coding agent — uses MockServer's MCP tools to interact with the server. You describe the problem in natural language and the assistant handles the API calls.
Ask your AI assistant to configure MockServer as a forwarding proxy. This records all traffic while passing requests through to the real destination.
Example prompt:
"Set up MockServer to proxy all requests to /api/* to api.example.com on port 443 over HTTPS"
The AI assistant will use the create_forward_expectation tool:
{
"name": "create_forward_expectation",
"arguments": {
"path": "/api/.*",
"host": "api.example.com",
"port": 443,
"scheme": "HTTPS"
}
}
Now any request sent to http://localhost:1080/api/... will be forwarded to https://api.example.com/api/... and both the request and response will be recorded.
Configure your application or test to send requests through MockServer instead of directly to the destination. This typically means changing the base URL in your application configuration:
# Before (direct)
API_BASE_URL=https://api.example.com
# After (through MockServer)
API_BASE_URL=http://localhost:1080
For AI applications, point the LLM client's base URL at MockServer so every model call is recorded. The examples below use LangChain and LangGraph, but the same approach works for any agent framework, LLM SDK, or HTTP client that lets you override the base URL. They assume a forwarding proxy is already in place for the provider (Step 1) — for example forwarding /v1/.* to api.openai.com or api.anthropic.com.
LangChain chat model clients accept a base URL override — set it to MockServer:
from langchain_openai import ChatOpenAI
# Route the model client through MockServer instead of calling the provider directly
llm = ChatOpenAI(
model="gpt-4o",
base_url="http://localhost:1080/v1",
api_key="sk-...",
)
The same applies to other providers — for example ChatAnthropic(model="claude-sonnet-4-20250514", base_url="http://localhost:1080").
A LangGraph graph makes its HTTP calls through the LangChain model objects bound to its nodes, so the same base URL override applies. Configure the model before building the graph:
from langchain_anthropic import ChatAnthropic
from langgraph.prebuilt import create_react_agent
model = ChatAnthropic(
model="claude-sonnet-4-20250514",
base_url="http://localhost:1080",
)
# Every model call made by the agent's nodes is now recorded by MockServer
agent = create_react_agent(model, tools=tools)
If your AI agent or SDK does not allow the base URL to be changed, use MockServer as an HTTPS proxy instead — see AI Traffic Inspection.
Then run your application or test scenario as normal. MockServer will forward all requests and record the traffic.
Ask your AI assistant to retrieve the recorded request-response pairs for analysis.
Example prompt:
"Show me all requests and responses to /api/payments"
The assistant will use the retrieve_request_responses tool to fetch the recorded data, then present it in a readable format with analysis of status codes, response times, headers, and body content.
When a request doesn't match an expectation you've configured, the debug_request_mismatch tool provides detailed information about why the match failed.
Example prompt:
"Why didn't my POST to /api/users match the mock I set up?"
The assistant will use the tool to compare your request against active expectations and report the specific fields that didn't match — such as a missing header, incorrect content type, or a path mismatch.
Here are practical prompts you can use with your AI assistant for common debugging tasks:
The assistant will:
retrieve_request_responses to find the failing request and its responseThe assistant will:
retrieve_recorded_requests filtered by the pathThe assistant will:
mockserver://expectations resource to see active expectationsdebug_request_mismatch with the request detailsThe assistant will:
create_forward_expectation to set up forwardingThe assistant will:
raw_retrieve with type LOGS to find recent log entries and identify the correlation ID for the requestraw_retrieve with type LOGS and the correlationId parameter to get all log entries for that specific requestThis is particularly useful for intermittent failures where you need to understand exactly what happened for a specific request.
After a failed test run where requests returned 404 (no matching expectation), the assistant can diagnose all mismatches at once:
The assistant will:
explain_unmatched_requests to retrieve all recent requests that matched no expectationThis is the fastest way to diagnose mismatches after a test failure. Unlike debug_request_mismatch (which requires you to reconstruct the failing request), explain_unmatched_requests works from MockServer's own traffic log, so there is nothing to reconstruct.
The tool is also available as a REST endpoint (PUT /mockserver/explainUnmatched) and as an MCP resource (mockserver://unmatched).
Once you have recorded live traffic through a forwarding proxy (steps 1-3 above), you can convert that recorded traffic into active mock expectations in a single step using create_expectations_from_recorded_traffic. This "observe then mock" workflow lets you point MockServer at a real API once, record the responses, and then switch to mocked responses for repeatable offline testing.
Example prompt:
"Convert all the traffic you just recorded into mock expectations so I can run tests offline"
The assistant will:
create_expectations_from_recorded_traffic with preview=true to show you the expectations that would be createdpreview=false to activate themreset. Before a debugging session, ask the assistant to reset MockServer so you have a clean slate without noise from previous tests.verify_request check so you can confirm the fix works: "Verify that POST /api/orders is called exactly once with a valid Authorization header."