MockServer

Mock any HTTP/1.1, HTTP/2, HTTP/3, HTTPS or gRPC service. Record and replay traffic, inject chaos, and debug live — with a built-in MCP server for AI assistants.

Fork MockServer on GitHub  
MockServer GitHub Project  Join MockServer Slack  BuildKite Build Status
 

Getting Started

MockServer is a single, self-hosted tool that mocks and proxies the services your application depends on, so you can develop and test against realistic, controllable behaviour instead of fragile real dependencies. It is free and open-source, runs anywhere, and needs no SaaS account.

To get started see the guide for mocking, proxying, connecting an AI assistant via MCP, or the code examples. The fastest way to try it:

docker run -d --rm -p 1080:1080 mockserver/mockserver
 

Your first mock in 30 seconds

Once MockServer is running, create an expectation and call it:

# 1. Create an expectation — return "Hello" for GET /hello
curl -s -X PUT http://localhost:1080/mockserver/expectation \
  -H "Content-Type: application/json" \
  -d '{
    "httpRequest":  { "method": "GET", "path": "/hello" },
    "httpResponse": { "statusCode": 200, "body": "Hello from MockServer!" }
  }'

# 2. Call the mock
curl http://localhost:1080/hello
# Hello from MockServer!

That's it. Read the Getting Started guide to learn how to match on headers, body, query parameters, and more, and how to verify what your code sent.

 

Quick links by use case

I want to… Start here
Write unit tests for a REST serviceGetting Started
Test an AI application that calls an LLMLLM Response Mocking
Cut my LLM / inference billLLM Cost Optimisation
Inject chaos / test resilienceChaos Testing
Run a load / performance test against an APILoad Injection
Assert which requests my code sentVerification
Mock a gRPC servicegRPC Mocking
Debug live traffic with breakpointsInteractive Breakpoints & Proxying
Model multi-step API flowsStateful Scenarios
Import a Postman collection or HAR fileImporting Expectations
 

What is MockServer

For any system you integrate with via HTTP or HTTPS MockServer can be used as:

  • a mock configured to return specific responses for different requests
  • a proxy recording and optionally modifying requests and responses
  • both a proxy for some requests and a mock for other requests at the same time
  • an MCP server that lets AI coding assistants drive the mock and proxy in natural language

Beyond mocking and proxying, the same MockServer instance also lets you:

It mocks far more than REST, and can build mocks from the contracts you already have:

And it is built to inspect, operate and scale:

MockServer is also AI-native: every instance ships a built-in Model Context Protocol (MCP) server at /mockserver/mcp with no extra configuration, and the documentation is published in machine-readable form for LLMs. In practice this means:

  • AI assistants (Claude Code, Cursor, Windsurf, Cline, OpenCode) can connect over MCP to create expectations, verify requests, retrieve recorded traffic, and debug mismatches — see MCP tools
  • Tools that don't yet speak MCP can fall back to MockServer's OpenAPI spec
  • LLMs can retrieve and cite the docs via llms.txt, llms-full.txt, and ai.txt

See AI & MCP Integration below for the full list of AI capabilities.

When MockServer receives a request it matches the request against active expectations that have been configured. Then, if no matches are found, it proxies the request if appropriate; otherwise a 404 is returned.

For each request received the following steps happen:

  1. find matching expectation and perform action
  2. if no matching expectation proxy request
  3. if not a proxy request return 404

An expectation defines the action that is taken, for example, a response could be returned.

MockServer supports the follow actions:

 

Chaos engineering & resilience testing

Most testing proves a system works when its dependencies behave. MockServer also lets you prove it survives when they don't. Because the same instance is already in the path of your traffic — as a mock or a proxy — it can deliberately degrade that traffic so failure modes are tested on purpose rather than discovered in production.

MockServer can inject:

  • latency — fixed or random delays before a response, to exercise timeouts, retries and back-pressure
  • error responses — return 5xx (or any) status codes, or a configurable rate of errors across requests
  • dropped & reset connections — close the socket before, during or after the response to simulate network faults
  • malformed responses — truncated bodies, bad framing and protocol-level corruption

Faults work for HTTP, gRPC and TCP, on both mocked and proxied traffic, and can be applied per expectation or as a global chaos experiment — including scheduled experiments with an automatic dead-man's-switch halt, and fleet-wide chaos for Kubernetes and service meshes. Live experiments can be started, watched and stopped from the dashboard.

Injecting chaos into proxied / forwarded real traffic — MockServer can sit in front of a real backend and degrade the responses it relays. HTTP-level faults reach proxied traffic through three mechanisms:

  • Forwarding expectation with a chaos clause — attach a chaos block to an httpForward expectation. The expectation forwards to the real upstream; MockServer applies the chaos profile to the upstream response before returning it to the caller. A catch-all forward expectation (match everything, forward to the real backend, inject faults) is the canonical "misbehaving upstream" pattern.
  • Service-scoped chaos — register a chaos profile for an upstream host with a single PUT /mockserver/serviceChaos call. MockServer applies it to all matched forwards to that host without touching any expectation. An optional ttlMillis auto-reverts the fault after a fixed window. Useful for live-patching a running deployment.
  • TCP-layer chaosPUT /mockserver/tcpChaos registers connection-level faults (drop, reset, bandwidth throttle, latency) that operate before HTTP is parsed, so they affect all traffic on a connection including proxied responses.

Note: the plain proxy fall-through (requests with no matching expectation) does not itself add HTTP-level chaos — HTTP faults on proxied traffic always flow through a forwarding expectation with a chaos clause or through service-scoped chaos. Connection-level faults flow through TCP chaos.

 

Proxying with MockServer

MockServer can:

  • proxy all requests using any of the following proxying methods:
    • Port Forwarding
    • Web Proxying (i.e. HTTP proxy)
    • HTTPS Tunneling Proxying (using HTTP CONNECT)
    • SOCKS Proxying (i.e. dynamic port forwarding)
  • verify proxied requests have been sent (i.e. in a test assertion)
  • record proxied requests and responses to analyse how a system behaves
  • pause proxied requests at breakpoints to inspect and modify the request or response in-flight, before it is forwarded upstream or returned to the client
  • inject chaos and faults into proxied traffic — latency, errors, dropped connections — to test how your system copes with a misbehaving upstream

MockServer supports the following proxying techniques:

  • Port Forwarding
  • Web Proxying (i.e. HTTP proxy)
  • Secure Web Proxying (i.e. HTTPS tunneling proxying)
    • requests are forwarded using a CONNECT request that sets up an HTTP tunnel
    • an SSL certificate is auto-generated allowing encrypted HTTPS traffic to be recorded transparently
    • to proxy requests the HTTP client should be configured to use an HTTP Proxy
  • SOCKS Proxying (i.e. dynamic port forwarding)
    • requests are forwarded using a SOCK CONNECT CMD request that established a socket tunnel
    • if the traffic is encrypted an SSL certificate is auto-generated allowing SSL traffic to be recorded transparently
    • to proxy requests the operating system (or JVM) should be configured to use an HTTP Proxy
  • SSL & Certificates
  • Port Unification
    • to simplify configuration all protocols (i.e. HTTP, HTTPS / TLS, SOCKS, etc) are supported on the same port
    • the protocol is detected dynamically by MockServer
  • Simultaneous Proxying & Mocking
    • if MockServer is being used as a proxy expectations can also be created
    • when a request is received it is first matched against active expectations that have been configured
    • if an expectation is matched its action will be performed instead of proxying the request
 

AI & MCP Integration

MockServer is built to be AI-native. A built-in Model Context Protocol (MCP) server lets AI coding assistants drive the mock server in natural language, and an OpenAPI spec provides a fallback for tools that don't yet speak MCP. All documentation, including llms.txt, llms-full.txt, and ai.txt, is structured for retrieval and citation by LLMs.

  • MCP Setup — connect Claude Code, Cursor, Windsurf, Cline, or OpenCode to a running MockServer at http://localhost:1080/mockserver/mcp over the MCP Streamable HTTP transport
  • MCP Tools Reference — every tool the AI assistant can invoke: create_expectation, verify_request, retrieve_recorded_requests, retrieve_logs, retrieve_request_responses, debug_request_mismatch, and more
  • AI-Assisted Debugging — diagnose request mismatches and inspect recorded request/response pairs through an AI assistant
  • AI-Assisted Verification — build test assertions using natural language
  • AI Traffic Inspection — record outbound traffic and let an AI assistant explain what happened
  • LLM Response Mocking — mock OpenAI, Anthropic, Bedrock and other LLM provider APIs, with realistic token-by-token streaming, for fast and deterministic AI-app tests
  • LLM Cost Optimisation — proxy real LLM traffic, then export a one-click optimisation brief (Markdown or JSON) from the dashboard LLM Optimise screen to find deterministic ways to cut inference cost
  • AI Protocol Mocking — mock MCP, A2A, SSE and WebSocket AI-protocol servers
  • OpenAPI Fallback for AI — use MockServer's OpenAPI spec with AI tools that don't yet support MCP

For example, put MockServer in front of a real provider to record live traffic, then export a one-click cost-optimisation brief:

Proxy LLM traffic and export a cost-optimisation brief

The MCP endpoint requires no extra configuration — start MockServer and the AI surface is on the same port:

docker run -d --rm -p 1080:1080 mockserver/mockserver
# MCP endpoint immediately available at http://localhost:1080/mockserver/mcp
 

Why use MockServer

MockServer allows you to mock any server or service via HTTP or HTTPS, such as a REST or RPC service.

This is useful in the following scenarios:

  • testing
    • easily recreate all types of responses for HTTP dependencies such as REST or RPC services to test applications easily and effectively
    • isolate the system-under-test to ensure tests run reliably and only fail when there is a genuine bug. It is important only the system-under-test is tested and not its dependencies to avoid tests failing due to irrelevant external changes such as network failure or a server being rebooted / redeployed.
    • easily set up mock responses independently for each test to ensure test data is encapsulated with each test. Avoid sharing data between tests that is difficult to manage and maintain and risks tests infecting each other
    • create test assertions that verify the requests the system-under-test has sent
  • de-coupling development
    • start working against a service API before the service is available. If an API or service is not yet fully developed MockServer can mock the API allowing any team who is using the service to start work without being delayed
    • isolate development teams during the initial development phases when the APIs / services may be extremely unstable and volatile. Using MockServer allows development work to continue even when an external service fails
  • resilience & chaos testing
    • verify your system copes when its dependencies misbehave by injecting chaos and faults — latency, errors, dropped connections and malformed responses (HTTP, gRPC and TCP) — so failure modes are tested deliberately rather than discovered in production
  • interactive debugging
    • set interactive breakpoints to pause a matched or proxied request in the dashboard, inspect and modify the request or response live, then continue — useful for reproducing edge cases and stepping through how the system-under-test reacts
  • isolate single service
    • during deployment and debugging it is helpful to run a single application or service, or handle a sub-set of requests, on a local machine in debug mode. Using MockServer it is easy to selectively forward requests to a local process running in debug mode, while all other requests are forwarded to the real services, for example running in a QA or UAT environment

Mocking Dependencies & Verifying Request

Given a system with service dependencies, as follows:

System In Production

MockServer could be used to mock the service dependencies, as follows:

Mocking service dependencies with MockServer

Isolating Single Service / Application

A single page application may load static resources such as HTML, CSS and JavaScript from a web server and also make AJAX calls to one or more separate services, as follows:

Single Page Application

To isolate a single AJAX service, for development or debugging, the MockServer can selectively forward specific requests to local instance of the service:

Isolating Single Service

Using MockServer as a content routing load balancer is described in more detail in the section called Isolate Single Service.

Why use MockServer as a proxy

MockServer allows you to record requests from the system-under-test, or to analyse an existing system by recording its outbound requests.

This is useful in the following scenarios:

  • testing
    • create test assertions that verify the requests the system-under-test has been sent, without needing to mock any requests
  • analyse existing system
    • record all outbound requests so it is possible to analyse and understand what outbound requests an existing system is making
  • debug HTTP interactions
    • log all outbound requests so it is possible to visualise all interactions (for example from a browser) to external services. This is particularly important as network analysis tools in browsers such as Chrome do not accurately show all network interactions, such as, favicon.ico requests. In addition, many proxies do not handle encrypted HTTPS traffic, however, MockServer auto-generates certificates using a single MockServer root CA certificate enabling the root certificate to be easily imported
  • record & replay
    • all recorded requests can be converted into Java code or JSON expectations to simplify the creation of mocks for complex test scenarios

Recording Requests & Analysing Behaviour

MockServer can record all proxied requests, as follows:

Recording service requests with MockServer Proxy

Verifying Requests

MockServer can verify proxied service requests, as follows:

Verifying service requests with MockServer Proxy

Verifying Responses

MockServer records the responses returned when it proxies requests, so a test can verify the responses received using request matchers:

Verifying service responses with MockServer Proxy

 

Developer Documentation

For detailed information about MockServer's internal architecture, infrastructure, build system, and operations, see the Contributing page, which links to comprehensive technical documentation on GitHub.