Skip to content

MCP Server

mockd includes a built-in Model Context Protocol (MCP) server with 18 tools for creating, managing, and debugging mocks directly from AI-powered editors.

The Model Context Protocol (MCP) is an open standard from Anthropic that lets AI assistants interact with external tools and data sources. Instead of copy-pasting curl commands or switching between your editor and terminal, your AI assistant talks to mockd directly — creating mocks, inspecting traffic, injecting chaos, and verifying behavior in a single conversation.

mockd’s MCP server is built on the official mcp-go SDK and exposes mockd’s full capabilities as structured tools that any MCP-compatible client can discover and invoke.

Terminal window
# Start mockd with MCP support (stdio transport)
# Auto-starts a background daemon if no server is running — zero setup needed.
mockd mcp
# Or enable MCP alongside the mock server (HTTP transport)
mockd serve --mcp

When you run mockd mcp, it automatically handles server lifecycle:

  1. Already running? Connects to the existing mockd server (via PID file or default URL)
  2. Nothing running? Auto-starts a background daemon (mockd start --detach --no-auth)
  3. Daemon is shared — it survives the MCP session, so multiple AI assistants (e.g., two Claude windows) share the same server and mocks persist across sessions

Stop the daemon with mockd stop when you’re done.

Use --data-dir to start a separate daemon per project, avoiding conflicts when working across multiple codebases:

{
"mcpServers": {
"mockd": {
"command": "mockd",
"args": ["mcp", "--data-dir", "./mockd-data"]
}
}
}

Project daemons run on different ports (14280/14290 by default) and store their PID file inside the data directory. Multiple sessions in the same project share the same daemon.

FlagDescriptionDefault
--admin-urlConnect to a specific admin API URL (skips auto-start)
--data-dirProject-scoped data directory (starts separate daemon)
--configConfig file to load on daemon startup
--portMock server port for project daemon4280 (or 14280 with --data-dir)
--admin-portAdmin API port for project daemon4290 (or 14290 with --data-dir)
--log-levelLog level for stderr outputwarn

Add to your MCP config (~/.claude/claude_code_config.json or Claude Desktop settings):

{
"mcpServers": {
"mockd": {
"command": "mockd",
"args": ["mcp"]
}
}
}

Add to .cursor/mcp.json in your project root:

{
"mcpServers": {
"mockd": {
"command": "mockd",
"args": ["mcp"]
}
}
}

Add to ~/.codeium/windsurf/mcp_config.json:

{
"mcpServers": {
"mockd": {
"command": "mockd",
"args": ["mcp"]
}
}
}

mockd’s MCP server exposes 18 tools organized by function:

ToolActionsDescription
manage_mocklist, get, create, update, delete, toggleFull CRUD for mock endpoints across all 7 protocols
ToolDescription
import_mocksImport from OpenAPI, Postman, HAR, WireMock, Mockoon, cURL, WSDL, or mockd YAML/JSON
export_mocksExport all mocks as YAML or JSON
ToolDescription
get_server_statusServer health, ports, uptime, and statistics
get_request_logsView captured request/response logs with protocol filtering
clear_request_logsClear all logs for test isolation
ToolDescription
get_chaos_configView current chaos fault injection settings
set_chaos_configConfigure latency, error rates, bandwidth throttling, apply named profiles, or define rules with stateful faults
reset_chaos_statsReset injection statistics counters
get_stateful_faultsView status of all stateful chaos fault instances (circuit breakers, retry-after trackers, progressive degradation)
manage_circuit_breakerManually trip or reset a chaos circuit breaker by its state key
ToolDescription
verify_mockAssert a mock was called the expected number of times
get_mock_invocationsView detailed request/response pairs for a specific mock
reset_verificationClear verification data for test isolation
ToolActionsDescription
manage_stateoverview, add_resource, list_items, get_item, create_item, resetManage CRUD collections that persist data across requests
ToolActionsDescription
manage_custom_operationlist, get, register, delete, executeMulti-step operations on stateful resources
ToolActionsDescription
manage_contextget, switchSwitch between mockd server contexts (multi-environment)
manage_workspacelist, switchSwitch between isolated workspace configurations

When you ask your AI editor “Create an endpoint that returns a list of users,” the AI calls the manage_mock tool behind the scenes:

Tool call (manage_mock with action create):

{
"action": "create",
"type": "http",
"http": {
"matcher": { "method": "GET", "path": "/api/users" },
"response": {
"statusCode": 200,
"headers": { "Content-Type": "application/json" },
"body": "[{\"id\":1,\"name\":\"{{faker.name}}\",\"email\":\"{{faker.email}}\"}]"
}
}
}

Tool response:

{
"action": "created",
"id": "http_a1b2c3d4",
"message": "Created http mock"
}

The AI can then verify it works by calling verify_mock after sending test traffic, or inject chaos with set_chaos_config to test your app’s error handling — all without leaving the editor.

Here’s what a full AI-assisted development session looks like:

  1. Create mocks — “Create a REST API for a todo app with GET, POST, PUT, DELETE”
  2. Send test traffic — The AI calls get_request_logs to verify traffic is flowing
  3. Verify behaviorverify_mock asserts the right endpoints were called the right number of times
  4. Inject chaos — Apply the flaky profile with set_chaos_config to test resilience
  5. Manage statemanage_state creates CRUD collections, seeds data, resets between tests
  6. Exportexport_mocks saves the full configuration for version control

The MCP server exposes 5 static resources for AI context, plus dynamic per-mock resources:

Resource URIDescription
mock://chaosCurrent chaos configuration, including stateful fault state (circuit breaker states, retry-after counters)
mock://verificationMock verification summary (template — use mock://verification/{mockId} for specific mocks)
mock://logsRecent request logs
mock://configCurrent server configuration
mock://contextCurrent context and workspace info

The server also generates resources for each configured mock, using URI patterns like mock:///api/users#GET (HTTP), mock://websocket/ws/chat (WebSocket), mock://graphql/graphql (GraphQL), mock://grpc/{id} (gRPC), mock://mqtt/{id} (MQTT), mock://soap/soap (SOAP), and mock://stateful/{name} (stateful resources).

mockd supports two MCP transports:

TransportCommandUse Case
stdiomockd mcpEditor integration (recommended)
HTTPmockd serve --mcpRemote access, shared server

The stdio transport is recommended for local editor integration. The HTTP transport runs alongside the mock server and is useful when the mockd server is running on a remote machine or in a container.

Every MCP tool has a corresponding CLI command. Use these interchangeably:

MCP ToolCLI Equivalent
manage_mock (create)mockd add http --path /api/users --status 200
verify_mockmockd verify check <mock-id> --exactly 3
get_mock_invocationsmockd verify invocations <mock-id>
set_chaos_config (profile)mockd chaos apply flaky
get_request_logsmockd logs --requests
import_mocksmockd import openapi.yaml
export_mocksmockd export --format yaml

See the CLI Reference for the full command list, including mockd mcp and mockd verify.