lmmock guide

Overview

lmmock combines a pure-Go loopback HTTP/1.x and TLS server, an embedded lmcode-go bytecode VM, a multi-provider LLM and OAuth2 fixture catalog, a stdio JSON-RPC host for ACP and MCP, a binary wire protocol engine (WebSocket, HTTP/2, gRPC, Redis, Kafka, MongoDB, Postgres, MQTT, SMTP, IMAP, AMQP), and a traffic-capture scrubber inside a single dependency-free executable.

HTTP mock architecture and execution lifecycle

Every scripted HTTP mock separates startup route registration from per-request execution:

Built-in LLM, OAuth2, and SaaS connector fixtures

lmmock ships both precompiled embedded presets (--builtin) and source fixtures under examples/ for offline testing of AI SDKs and workflow connectors:

Stdio ACP/MCP, wire protocols, and database brokers

Beyond HTTP/1.x, lmmock provides three specialized protocol families:

TLS, traffic capture scrubbing, and security boundaries

When --tls is passed to serve or exec, lmmock generates an ephemeral in-memory CA and server keypair for 127.0.0.1, ::1, localhost, and any --tls-host DNS or IP identities. Only the public CA certificate is written to a temporary directory and exported to the exec child via LMMOCK_CA_CERT, SSL_CERT_FILE, NODE_EXTRA_CA_CERTS, REQUESTS_CA_BUNDLE, and CURL_CA_BUNDLE; machine trust stores are never modified.

For recording-driven fixtures, lmmock scenario scrub ingests raw lminspect JSONL captures, decompresses gzip payloads, normalizes dynamic provider IDs and timestamps, and scrubs Authorization headers, API keys, cookies, and escaped JSON credentials across all exchanges before writing safe flows.jsonl and scenario.json artifacts. lmmock scenario verify replays scrubbed flows against a live loopback mock to assert byte-for-byte and event-order fidelity.

Standard lmcode_std_v3 REST and CLI interfaces

Every lmmock HTTP program also embeds the 226-signature lmcode_std_v3 standard catalog. Scripts can combine native Handler(Exchange) routes with standard RestExchange interfaces and stateless CLI dispatch:

p = _lmcode_ schema="examples/schema.json";
@"--prefix-tag"
fn opt_tag(x: RestExchange) -> void implements CliOption {
  x.set("tag", x.query("prefix-tag"));
}

@"status"
fn cmd_status(x: RestExchange) -> void implements CliCommand {
  let n = x.increment("cli_calls");
  x.send(x.get("tag") + ":" + str(n));
}

@"/items/:id"
fn get_item(x: RestExchange) -> void implements RestGet {
  x.json("{\"id\":\"" + x.param("id") + "\",\"tag\":\"" + x.get("tag") + "\"}");
}

rest_config("prefix", "/v1");
assert_eq(rest_cli(str_split("--prefix-tag=ci status", " ")), "ci:1");
assert_eq(rest_cli(str_split("--prefix-tag=ci /v1/items/99", " ")), "{\"id\":\"99\",\"tag\":\"ci\"}");
end _lmcode_