API reference #

Litmus exposes two equivalent surfaces over the same Python code:

  1. HTTP API at http://localhost:8000/api/* when litmus serve is running. Use from any HTTP client.
  2. MCP server for AI agents (Claude Code, Cursor, Cline, etc.). Use the Model Context Protocol over stdio.

The MCP tools are thin wrappers around the same Python functions that back the HTTP routes; behavior is identical.

Live API explorer #

When litmus serve is running, the HTTP API exposes three introspection endpoints. They live under /api/* (not at FastAPI's usual top-level paths — the top-level /docs route is the in-app documentation viewer) and reflect the current litmus build on the bench:

URLWhat it serves
http://localhost:8000/api/openapi.jsonThe raw OpenAPI 3 schema (JSON). Feed it to your favorite client generator (openapi-typescript-codegen, openapi-python-client, etc.) to produce typed clients.
http://localhost:8000/api/docsSwagger UI — an interactive request-builder. Pick a route, fill in parameters, click Execute, see the actual response from the running server. Best for "what does this endpoint return on my bench".
http://localhost:8000/api/redocReDoc — a single-page reference rendering of the same schema with nested response models expanded. Best for "I just want to read the whole API".

The schema is generated from the same FastAPI route signatures and Pydantic response models that the route tables below document — so the Swagger / ReDoc views are always in sync with the actual deployed code. No build step.

For setup details (how to start the server, how to register the MCP equivalent), see the litmus serve CLI reference.

Generated tables #

The route and tool tables below are generated from source — src/litmus/api/app.py for the HTTP routes and src/litmus/mcp/server.py for the MCP tools. To regenerate after touching either, run:

uv run python scripts/generate_reference_docs.py api

The pre-commit hook runs the same generator in --check mode, so source / docs drift fails the commit.

MCP server #

For AI agents (Claude Code, Cursor, Cline, etc.) over stdio. The MCP tools wrap the same Python functions that back the HTTP routes; behavior is identical.

Setup #

litmus setup claude-code     # Claude Code
litmus setup claude-desktop  # Claude Desktop
litmus setup copilot         # GitHub Copilot
litmus setup cursor          # Cursor
litmus setup cline           # Cline (VS Code)
litmus mcp serve             # Manual stdio server (auto-launched by the setup commands)

Tools #

Twelve tools, all prefixed litmus_. Each tool's parameter shape and full docstring is also available via the MCP tools/list protocol method; the table below summarizes.

ToolParametersSummary
litmus_channelschannel_id, session_id, last_n, max_points, projectQuery channel data from the streaming channel store.
litmus_discoverprotocolsScan for connected instruments across all protocols.
litmus_eventssession_id, event_type, role, since, limit, projectQuery events from the event store.
litmus_matchproduct_id, station_id, fixture_id, requirements, projectCheck compatibility between products, stations, and fixtures.
litmus_metricsaction, product, station, phase, since, until, period, top_n, min_samples, projectQuery manufacturing-test analytics (DuckDB SQL aggregated from parquet rows).
litmus_opentype, id, base_urlGet URL to view/edit an entity in the browser UI.
litmus_projectaction, type, id, path, content, create, scaffold, projectUnified Litmus operations: init, list, get, save, read.
litmus_runtest, station, serial, projectExecute tests and return results.
litmus_runsaction, run_id, limit, projectQuery the runs table — denormalized run-level summaries.
litmus_schemayaml_typeGet JSON Schema for a Litmus YAML file type.
litmus_sessionsprojectList known sessions with metadata.
litmus_stepsrun_id, action, projectQuery the steps table for one run.

For per-tool parameter detail and worked examples, see how-to/mcp-integration.md.

Prompts #

Prompts are reusable instruction templates an agent can fetch via the MCP prompts/get protocol method. Registered with @mcp.prompt(name=...) in create_mcp_server().

PromptArgumentsSummary
datasheet-to-testGet the full datasheet-to-test workflow guide.

HTTP API #

For any HTTP client.

Setup #

litmus serve                 # API at http://localhost:8000/api/
litmus serve --reload        # Dev mode with auto-reload

Running litmus serve locally? The interactive OpenAPI explorer at http://localhost:8000/api/docs (Swagger UI) is richer than the table below — full request/response schemas, validation rules, and a "Try it out" button that executes calls from the browser. ReDoc at http://localhost:8000/api/redoc and raw spec at http://localhost:8000/api/openapi.json for codegen.

Every route is mounted under the /api/ prefix. Field shapes for request / response models live in models.md; query parameter detail is in the per-handler source.

Runs #

MethodPathResponse modelSummary
GET/api/runsRunsListResponseList recent test runs.
GET/api/runs/{run_id}RunViewGet a specific test run with steps, instruments, and measurements.
GET/api/runs/{run_id}/measurementsMeasurementsListResponseGet measurements for a test run.
GET/api/runs/{run_id}/stepsStepsListResponseList steps for a run, ordered by step_index.
GET/api/runs/{run_id}/steps/treeStepsTreeResponseHierarchical step tree built from step_path.
GET/api/runs/{run_id}/refMaterialize a measurement-output ref URI to its underlying data.
POST/api/runsRunLaunchResponseStart a new test run.
GET/api/runs/{run_id}/statusRunStatusGet status of a running test.

Active runs #

MethodPathResponse modelSummary
GET/api/activeActiveRunsResponseList currently running tests.

Dialogs #

MethodPathResponse modelSummary
GET/api/dialogsDialogsListResponseList pending dialogs.
POST/api/dialogsDialogCreateResponseCreate a pending dialog (from test subprocess).
GET/api/dialogs/{dialog_id}DialogGet a specific pending dialog.
GET/api/dialogs/{dialog_id}/waitDialogResponseLong-poll waiting for dialog response.
POST/api/dialogs/{dialog_id}/respondDialogRespondAckRespond to a pending dialog.

Events & sessions #

MethodPathResponse modelSummary
GET/api/eventsGenericObjectResponseQuery events from the event store.
GET/api/sessionsGenericObjectResponseList known sessions.
GET/api/sessions/{session_id}GenericObjectResponseGet events for a specific session.

Channels #

MethodPathResponse modelSummary
GET/api/channelsGenericObjectResponseList known channels from the channel registry.
GET/api/channels/_recentGenericObjectResponseChannel registry + recent samples per channel.
GET/api/channels/{channel_id}GenericObjectResponseQuery channel data.

Products #

MethodPathResponse modelSummary
GET/api/productsProductsListResponseList all available product specifications.
GET/api/products/{product_id}ProductGet a product specification by ID.
GET/api/products/{product_id}/requirementsProductRequirementsResponseGet required capabilities for a product.

Stations #

MethodPathResponse modelSummary
GET/api/stationsStationsListResponseList all available test stations.
GET/api/stations/{station_id}StationConfigGet a station configuration by ID.
GET/api/stations/{station_id}/capabilitiesStationCapabilitiesResponseGet capabilities provided by a station.

Capability matching #

MethodPathResponse modelSummary
GET/api/matchMatchSingleResponse | MatchAllResponseMatch product requirements to station capabilities.

Instruments #

MethodPathResponse modelSummary
GET/api/instruments/typesInstrumentTypesResponseList distinct instrument type values present in the catalog.
GET/api/instruments/catalog/{entry_id}InstrumentCatalogEntryGet a catalog entry by type or ID.
GET/api/instruments/assetsInstrumentAssetsResponseList instrument asset files (physical devices you own).
GET/api/instruments/assets/{asset_id}InstrumentAssetFileGet an instrument asset by ID.

Metrics #

MethodPathResponse modelSummary
GET/api/metrics/summaryMetricsResponseYield summary — DuckDB SQL aggregated from parquet rows at request time.
GET/api/metrics/paretoMetricsResponseTop failure modes (DuckDB SQL).
GET/api/metrics/cpkMetricsResponseProcess capability (DuckDB SQL).
GET/api/metrics/trendMetricsResponseYield trend (DuckDB SQL).
GET/api/metrics/retestMetricsResponseRetest rates (DuckDB SQL).
GET/api/metrics/time-lossMetricsResponseTime lost to failures/errors (DuckDB SQL).

MCP-parity tools #

MethodPathResponse modelSummary
GET/api/discoverGenericObjectResponseScan for connected instruments across all protocols.
GET/api/openGenericObjectResponseGet URL to view/edit an entity in the browser UI.
GET/api/schema/{yaml_type}GenericObjectResponseGet JSON Schema for a Litmus YAML file type.
POST/api/save/{entity_type}/{entity_id}GenericObjectResponseCreate or update an entity (station, product, sequence, fixture, etc.).
GET/api/readGenericObjectResponseRead a project file or template.
GET/api/enum/{abbrev}GenericObjectResponseResolve a datasheet abbreviation to its MeasurementFunction enum value(s).
GET/api/enum-referenceGenericObjectResponseGet the full abbreviation-to-enum reference table as markdown.

API discovery #

MethodPathResponse modelSummary
GET/api/openapi.jsondictOpenAPI 3.0 schema for the Litmus HTTP API.
GET/api/docsSwagger UI live API explorer (mounted under /api/ to avoid colliding with NiceGUI's /docs Diátaxis browser).
GET/api/redocReDoc rendering of the OpenAPI schema.

Response format #

All JSON responses use camelCase for envelope fields (runs, events, metrics) and snake_case for record fields (which match the Pydantic model field names — see models.md). Errors follow the FastAPI convention:

{"detail": "Run not found"}

with the HTTP status code carrying the category (404 not found, 422 validation, 500 server error).

Authentication #

No authentication for the local-only litmus serve deployment. If you expose the API beyond localhost, put it behind a reverse proxy that handles auth.

See also #