- LOGIC
- VALIDATION
- FIXES
- HUMAN
Short answer
How do I debug the SQL my AI agent is writing?
Your agent uses the Cube.dev MCP to pull the exact SQL strings it generates for your data requests. You can inspect these queries to find where the logic breaks and run them directly to verify the results. This breakdown shows you how to catch and fix those errors.
Debugging outcomes
Where your debugging happens.
The AI handles the heavy lifting of query construction, but you stay in control of the logic.
LOGIC
Catch broken joins
The AI pulls the raw SQL so you can see if it's joining tables incorrectly or missing a filter. You'll see exactly why a number looks wrong.
VALIDATION
Run and verify
Once you find a query that looks suspicious, you can execute it to see the real data output. This confirms if the AI's logic matches your expectations.
FIXES
Correct the agent
When the AI writes bad SQL, you can point out the specific error in the query. It uses that feedback to rewrite the statement correctly.
HUMAN
Manual oversight
The AI cannot rewrite your Cube.dev data models. You still own the underlying semantic layer and must fix schema issues yourself.
The workflow
What your AI does when a query is requested.
The agent moves from interpreting your question to generating and testing the code.
Extract SQL
The agent looks at your data request and generates the corresponding SQL string for the Cube.dev semantic layer.
get_sqlInspect code
The agent presents the generated SQL to you so you can review the logic before any data is actually pulled.
get_sqlTest execution
If you want to see the actual data, the agent runs the query against your Cube.dev instance.
execute_cube_sqlVerify results
The agent uses the output from the execution to confirm the data matches your original question.
execute_cube_sql
Try it
Copy these to start.
Use these prompts to begin debugging your data queries.
Starting points
Swap out the bracketed text for your actual Cube.dev measures or dimensions.
Cube.dev Connector
You're all set. Choose your MCP client and follow the setup instructions.
https://edge.vinkius.com/vk_preview_umZADPejupUUQHrfZkQT0lvv7MlK4j1JkrhOJOMy/mcpClaude Desktop
Follow the steps below to connect in seconds.
- 1In Claude Desktop, open Settings → Connectors.
- 2Click “Add custom connector” and paste the connector link above as the remote MCP server URL.
- 3Click Add and start a new chat — Cube.dev capabilities are ready to use.
{
"mcpServers": {
"cubedev-mcp": {
"url": "https://edge.vinkius.com/vk_preview_umZADPejupUUQHrfZkQT0lvv7MlK4j1JkrhOJOMy/mcp"
}
}
}Show me the SQL you generated for the [total revenue] measure in Cube.dev.
The SQL for [active users] looks wrong. Can you show me the exact query you're using?
Run this SQL query in Cube.dev and tell me the result for [last month]: [paste sql here]
Why did you join the [orders] table with [users] in that last query? Show me the SQL.
Claude
ChatGPT
Cursor
VS Code
Windsurf
Claude Code
JetBrains
Cline
Start here
Connect Cube.dev once, then ask.
Just provide your credentials once. Your connection is encrypted and stays secure. You can then start debugging queries in any MCP-compatible client.
Connect Cube.dev to your AIFAQ
How the debugging process works.
- 01
Can the AI change my Cube.dev data models?
No. The AI can only read the existing models and generate SQL based on them. You must update your semantic layer manually.
- 02
Does the AI execute queries automatically?
No. The agent only executes queries when you specifically ask it to run or verify the data.
- 03
Can I see the SQL before it runs?
Yes. You can ask the agent to show you the generated SQL before you authorize execution.
- 04
What happens if the SQL is invalid?
The agent will receive an error from Cube.dev and can use that error message to attempt to fix the query.
- 05
Can the AI delete data in my database?
No. This MCP only has tools to retrieve SQL and execute queries. It cannot perform delete or update operations.
More questions about Cube.dev? See everything the Cube.dev Connector can do
Connect Cube.dev to Claude, Cursor, ChatGPT & more
