lmmock
lmmock is a scriptable multi-protocol mock server and LMScript host for HTTP, OAuth2, LLM APIs, stdio ACP and MCP, WebSocket, HTTP/2, gRPC, and wire protocols. It binds loopback listeners, executes annotated lmcode handlers, and wraps integration test commands with automatic lifecycle cleanup.
Quick reference
npm install -g @lmctl-ai/lmctl@latest
lmmock --version
lmmock --lmcode-schema --json
lmmock --lmcode-signatures
| Interface or flag | Signature or syntax | Purpose |
|---|---|---|
| CLI exec wrapper | lmmock exec --lmcode FILE [flags] -- COMMAND [ARG...] | Bind an ephemeral loopback listener, export LMMOCK_URL to the child command, and shut down on exit. |
| CLI standalone server | lmmock serve --lmcode FILE [--listen 127.0.0.1:0] [--ready-file FILE] | Start a loopback mock server, emit readiness JSON on stdout, and serve until SIGINT or SIGTERM. |
| CLI built-in presets | lmmock exec|serve --builtin llm-api|oauth-codex-device [--config FILE] | Run embedded OpenAI, Anthropic, Gemini, Ollama, or Codex OAuth device-flow mocks without compiling scripts. |
| CLI wire and proto servers | lmmock proto <name> | lmmock wire serve|exec <ws|http2|grpc|line> | Run in-memory Kafka, MongoDB, Postgres, Redis, MQTT, SMTP, IMAP, AMQP, WebSocket, HTTP/2, or gRPC mocks. |
| CLI stdio and scenarios | lmmock stdio acp|mcp|mcp-client|agent | lmmock scenario scrub|import|verify | Mock stdio JSON-RPC agents and MCP servers, or scrub and verify recorded lminspect traffic captures. |
| CLI assertion runner | lmmock check --suite FILE [--url URL] | Run multi-step declarative HTTP assertion suites with dot-path JSON checks and variable capture. |
| Handler and Exchange | @name fn h(x: Exchange) -> void implements Handler | Handle HTTP requests with status, headers, buffered json/send, ordered stream_event, delay, or faults. |
| Host functions | route(method, path, ann) | config() | form_get() | sha256_url() | Register ServeMux routes, read JSON config, parse forms and Basic auth, and generate PKCE hashes or tokens. |
| Standard REST and CLI | RestGet..RestOptions, RestHandler, CliCommand, CliOption | Define standard lmcode_std_v3 HTTP routes (:param) and stateless CLI commands dispatched via rest_cli. |
p = _lmcode_ cli="lmmock" install="github:lmctl-ai/lmmock@latest";
@health
fn healthcheck(x: Exchange) -> void implements Handler {
x.json("{\"ok\":true,\"hits\":" + str(x.increment("hits")) + "}");
}
route("GET", "/health", "health");
@"--env"
fn opt_env(x: RestExchange) -> void implements CliOption {
x.set("env", x.query("env"));
}
@"/users/:id"
fn get_user(x: RestExchange) -> void implements RestGet {
x.json("{\"id\":\"" + x.param("id") + "\",\"env\":\"" + x.get("env") + "\"}");
}
rest_config("session", "global");
assert_eq(rest_cli(str_split("--env=test /users/42", " ")), "{\"id\":\"42\",\"env\":\"test\"}");
end _lmcode_
res = run_lmcode(p, {command: ["lmmock", "exec", "--lmcode", "$DSLFILE", "--", "lmmock", "check", "--suite", "examples/api-client.json"]});
require(res.ok, json_stringify(res));
Documentation pages
- Skill — agent authoring rules, CLI modes, loopback safety boundaries, exit codes, and verification steps.
- Guide — HTTP handler architecture, LLM and OAuth fixtures, stdio and wire protocols, TLS and capture replay, and standard REST and CLI interfaces.
- Reference — complete CLI subcommands and flags, Exchange and RPC methods, host functions, standard lmcode_std_v3 interfaces, and exit codes.