Enable the Cube SQL API in your cube.js or cube.yaml configuration and note the Postgres-compatible connection host and port provided by Cube Cloud or your self-hosted deployment
Connect the AI agent or LLM tool to the SQL API endpoint using a standard Postgres wire-protocol client or driver
Provide the AI agent with a schema description listing available cube names, measure names, and dimension names obtained from /v1/meta so it can construct valid queries
Instruct the agent to write SELECT queries using the MEASURE(cube_name.measure_name) syntax alongside GROUP BY clauses for dimensions rather than writing raw aggregate SQL against source tables
Every query routed through the SQL API passes through Cube's access policy enforcement and pre-aggregation matching, ensuring governed, cached metric results regardless of how the AI constructs the query
Known gotchas
The MEASURE() function is a Cube-specific SQL extension; standard Postgres clients can parse and forward it, but the function only executes correctly through the Cube SQL API endpoint — running the same SQL against the source warehouse directly will fail
LLMs must be given accurate cube and measure names from /v1/meta; hallucinated names will produce SQL errors rather than approximate results, so grounding the prompt with the actual schema is essential
Access policies defined in the Cube data model are applied based on the security context passed with the SQL API connection; ensure the AI agent's connection includes the correct user context token to apply the intended row and column restrictions
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp