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 |
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 mcp add semantic-rails -- uvx semantic-rails mcp stdio --path "$PWD/my_package"
codex mcp add semantic-rails -- uvx semantic-rails mcp stdio --path "$PWD/my_package"
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.
uv tool install semantic-rails echo "$(uv tool dir --bin)/semantic-rails" echo "$PWD/my_package"
{
"mcpServers": {
"semantic-rails": {
"command": "/absolute/path/to/semantic-rails",
"args": ["mcp", "stdio", "--path", "/absolute/path/to/my_package"]
}
}
}
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.
discover -> plan -> execute
discovermaps business terms to governed semantic objects.inspect(optional) opens an object card with usage, provenance, comparison metadata, and starter patches.planreturns the best query call draft for natural-language intents, with astatusthat says whether to run it. Usedetail="full"only when you need alternatives or blocked drafts.build-optionsreturns legal next query choices for guided builders.valid-valuessearches categorical values for selected dimensions.executeis the MCP tool name (HTTP path/api/v1/query, CLI verbsemantic-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 mostmax_rowsrows (default 200); a capped result setstruncatedand warnsEXECUTE_ROWS_TRUNCATED. A window (last,this,startand/orend) without atime.grainreturns one total over the window, with no time column, and says so inassumptions; settime.grainfor one row per period. Atimewith neither a grain nor a window is refused. Passnowbeside the call (HTTPoptions.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_fieldsnames them); required data that still cannot fit is refused withRESULT_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. Atcompactorfullverbosity, its response also includes anexplainpayload with the semantic and physical plan plus achosen_pathsmap keyed by target entity ID — each entry carriesselected(the chosen relationship path),candidates(every considered path), andcontracts(the relationship contracts along the selected path). The CLI defaults tocompact; on MCP,executewithmode: "sql"defaults tominimal, which leavesexplainout, so passverbosity: "compact"to review join paths and safety before execution.
3. Smoke the hosted MCP demo
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
uvx semantic-rails serve --package jaffle_shop --port 8081
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}'
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"}'
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
minimalverbosity, andplantodetail="query". - HTTP defaults to
compact. - Use
summaryorminimalfor tight loops. - Use
fullonly 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.
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.
| Tool | What it does |
|---|---|
discover | Ranks objects against business terms; empty terms list the catalog's ids. |
inspect | One object's card. |
valid-values | A dimension's governed values. |
plan | Drafts a query call from a natural-language question. detail defaults to query; detail="best" adds intent_ir, best.trace and next. |
execute | Validates, 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. |
segment | action="validate", "explain" or "preview" for a package-authored segment. Listed only when the package defines segments. |
To move a v1 client to v2:
validatebecomesexecutewithmode: "validate", andcompilebecomesexecutewithmode: "sql".segment-validate,segment-explainandsegment-previewbecomesegmentwithactionvalidate,explainorpreview; passverbosity: "full"for the whole response.catalogbecomesdiscoverwith emptyterms.capabilitiesandbuild-optionshave no MCP tool: draft the call withplan. The HTTP API keeps both, and the CLI keepsbuild-options.- Defaults are smaller:
discoverandinspectreturn slim cards (verbosity: "compact"for v1's), andplanreturnsdetail: "query"(detail: "best"for v1's).
Continue to Agent Actions for the staged public query path, or Hosted MCP for public endpoint details.