Agent Quickstart

Use this path when an LLM agent, MCP client, or internal app needs to query governed metrics without jumping straight to SQL. The core loop is discover, plan, execute: execute validates and compiles the query before it runs it.

1. Choose a transport
Surface Use it for Start command or URL
Hosted MCP demo Public evaluation against synthetic Jaffle Shop data https://semantic-rails.com/mcp
Local MCP stdio Desktop agents and local MCP clients against your package PACKAGE_PATH="$(pwd)/my_package"; semantic-rails mcp setup --path "$PACKAGE_PATH"
Local MCP HTTP HTTP-capable MCP clients during development via /mcp PACKAGE_PATH="$(pwd)/my_package"; semantic-rails serve --path "$PACKAGE_PATH" --host 127.0.0.1 --port 8091
Local HTTP API Apps that call stable /api/v1/* routes directly PACKAGE_PATH="$(pwd)/my_package"; semantic-rails serve --path "$PACKAGE_PATH" --port 8081
The hosted MCP endpoint is anonymous, rate-limited, and fixed to synthetic data. It cannot load your local package. Use local MCP or your own deployment for real warehouse data, proprietary prompts, secrets, or customer credentials.

Local profiles under ~/.semantic_rails are developer CLI defaults only. Agent and hosted configs should pass explicit package paths and keep secrets in their own config/vault boundary.

semantic-rails serve runs one foreground server for the HTTP API and stateless Streamable HTTP at /mcp. Run it in a separate terminal and stop it with Ctrl-C. For stdio, let the MCP client launch the server from generated config. See the HTTP API and MCP setup for request headers, API-key authentication, and trusted caller context.

To connect a client to your own package, run these from the directory that holds my_package. MCP clients may start in another directory, so pass an absolute path.

Claude Code
claude mcp add semantic-rails -- uvx semantic-rails mcp stdio --path "$PWD/my_package"
Codex CLI
codex mcp add semantic-rails -- uvx semantic-rails mcp stdio --path "$PWD/my_package"
Claude Desktop (install the command first)
uv tool install semantic-rails
"$(uv tool dir --bin)/semantic-rails" mcp setup --path "$PWD/my_package" --client claude --mcp query --install --yes

uv tool dir --bin finds the command even when uv's tool directory isn't on your PATH yet. These client commands are for macOS and Linux shells; Windows isn't covered by our checks yet. For Cursor, install the command and print the two absolute paths the config needs, then add the server to .cursor/mcp.json.

Cursor (from the directory that holds my_package)
uv tool install semantic-rails
echo "$(uv tool dir --bin)/semantic-rails"
echo "$PWD/my_package"
.cursor/mcp.json
{
  "mcpServers": {
    "semantic-rails": {
      "command": "/absolute/path/to/semantic-rails",
      "args": ["mcp", "stdio", "--path", "/absolute/path/to/my_package"]
    }
  }
}
hosted demo (no install)
claude mcp add --transport http semantic-rails-demo https://semantic-rails.com/mcp
codex mcp add semantic-rails-demo --url https://semantic-rails.com/mcp

Run mcp setup without --install --yes to preview a change. --mcp both adds the Architect MCP, which can edit package files. Don't run mcp setup --install through uvx: the config would point into uv's cache, which uv cache clean deletes.

2. Follow the supported loop

Over MCP, execute takes mode="validate" or mode="sql" for the validate and compile dry runs below, and build-options is HTTP and CLI only.

text
discover -> plan -> execute
  • discover maps business terms to governed semantic objects.
  • inspect (optional) opens an object card with usage, provenance, comparison metadata, and starter patches.
  • plan returns the best query call draft for natural-language intents, with a status that says whether to run it. Use detail="full" only when you need alternatives or blocked drafts.
  • build-options returns legal next query choices for guided builders.
  • valid-values searches categorical values for selected dimensions.
  • execute is the MCP tool name (HTTP path /api/v1/query, CLI verb semantic-rails query). It validates and compiles the request, then executes it in the local or customer-operated runtime. An invalid query fails with a structured error and, where possible, recovery hints instead of running. On MCP it returns at most max_rows rows (default 200); a capped result sets truncated and warns EXECUTE_ROWS_TRUNCATED. A window (last, this, start and/or end) without a time.grain returns one total over the window, with no time column, and says so in assumptions; set time.grain for one row per period. A time with neither a grain nor a window is refused. Pass now beside the call (HTTP options.now) to pin relative windows (now). Every MCP tool and mode fits one 32,000-character response budget. Optional plans and metadata are trimmed first (omitted_fields names them); required data that still cannot fit is refused with RESULT_TOO_LARGE. Compact responses omit compiler plans.
  • validate (optional dry run) returns diagnostics, repair hints, output columns, and risk metadata without executing.
  • compile (optional dry run) returns SQL and plan metadata without executing. At compact or full verbosity, its response also includes an explain payload with the semantic and physical plan plus a chosen_paths map keyed by target entity ID — each entry carries selected (the chosen relationship path), candidates (every considered path), and contracts (the relationship contracts along the selected path). The CLI defaults to compact; on MCP, execute with mode: "sql" defaults to minimal, which leaves explain out, so pass verbosity: "compact" to review join paths and safety before execution.
3. Smoke the hosted MCP demo
initialize.sh
curl https://semantic-rails.com/mcp \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json, text/event-stream' \
  -H 'MCP-Protocol-Version: 2025-11-25' \
  --data '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"curl","version":"1"}}}'

From an MCP client, list tools and begin with discover; empty terms list every id in the package. Keep the default minimal verbosity unless debugging requires full planner details.

4. Smoke the local HTTP API
terminal
uvx semantic-rails serve --package jaffle_shop --port 8081
discover.sh
curl -s -X POST http://127.0.0.1:8081/api/v1/discover \
  -H 'Content-Type: application/json' \
  -d '{"terms":"revenue by store","limit":5}'
plan.sh
curl -s -X POST http://127.0.0.1:8081/api/v1/plan \
  -H 'Content-Type: application/json' \
  -d '{"intent":"new customer orders over time","detail":"best"}'
compile.sh
curl -s -X POST http://127.0.0.1:8081/api/v1/compile \
  -H 'Content-Type: application/json' \
  -d '{
    "query": {
      "select": ["measure.jaffle.revenue_usd"],
      "group_by": ["dimension.jaffle_store_name"],
      "time": { "temporal_role": "temporal_role.jaffle_order_time", "grain": "month" },
      "limit": 5
    }
  }'
5. Keep response size intentional
  • MCP tools default to minimal verbosity, and plan to detail="query".
  • HTTP defaults to compact.
  • Use summary or minimal for tight loops.
  • Use full only for debugging, alternatives, chosen paths, and relationship contracts.
6. Know what is supported
Tier Positioning
Supported core DuckDB local runtime, Snowflake execution (when a package connection is configured), CLI, MCP stdio, MCP HTTP, stable /api/v1/*, package authoring, checks, validation, compile, explain, and local/customer-side execution.
Supported with guardrails Mixed-grain rewrites, historical slicing, contextual/entity-only predicates, supported event-count conversions, and the other optional connectors.
Experimental or out of scope In the open-source engine: hosted real-data execution-on-behalf, managed acceleration, billing, tenant administration, arbitrary SQL pipelines, managed materialization, and fully general nested predicate planning. SR Cloud, the separate hosted service, covers hosted execution and tenant administration.

DuckDB runs in every CI run. The other warehouse connectors, Snowflake included, have dialect-level test coverage; live runs need credentials and happen on demand, not in every CI run.

When a request falls outside the supported surface, agents should surface the structured error and recovery hints instead of inventing raw SQL.
7. Know the MCP tools

Since engine 0.3.2 the query MCP has one interface, v2, which initialize reports as serverInfo.version. Setting SEMANTIC_RAILS_MCP_INTERFACE=v1 fails, and calling a v1 tool returns UNKNOWN_MCP_TOOL.

ToolWhat it does
discoverRanks objects against business terms; empty terms list the catalog's ids.
inspectOne object's card.
valid-valuesA dimension's governed values.
planDrafts a query call from a natural-language question. detail defaults to query; detail="best" adds intent_ir, best.trace and next.
executeValidates, compiles and runs a query call (HTTP /api/v1/query). mode="validate" or mode="sql" stops before running it. Returns at most max_rows rows: 200 by default, up to 100,000.
segmentaction="validate", "explain" or "preview" for a package-authored segment. Listed only when the package defines segments.

To move a v1 client to v2:

  • validate becomes execute with mode: "validate", and compile becomes execute with mode: "sql".
  • segment-validate, segment-explain and segment-preview become segment with action validate, explain or preview; pass verbosity: "full" for the whole response.
  • catalog becomes discover with empty terms.
  • capabilities and build-options have no MCP tool: draft the call with plan. The HTTP API keeps both, and the CLI keeps build-options.
  • Defaults are smaller: discover and inspect return slim cards (verbosity: "compact" for v1's), and plan returns detail: "query" (detail: "best" for v1's).

Continue to Agent Actions for the staged public query path, or Hosted MCP for public endpoint details.