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 flagSignature or syntaxPurpose
CLI exec wrapperlmmock 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 serverlmmock 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 presetslmmock 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 serverslmmock 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 scenarioslmmock stdio acp|mcp|mcp-client|agent | lmmock scenario scrub|import|verifyMock stdio JSON-RPC agents and MCP servers, or scrub and verify recorded lminspect traffic captures.
CLI assertion runnerlmmock 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 HandlerHandle HTTP requests with status, headers, buffered json/send, ordered stream_event, delay, or faults.
Host functionsroute(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 CLIRestGet..RestOptions, RestHandler, CliCommand, CliOptionDefine 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

Source repository and releases