# Mbql

> Mbql is an open-source agent skill for analytics and data. Writes and debugs MBQL query bodies for the mb CLI, with dry-run checks. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Goose
- **Website:** https://github.com/metabase/metabase-cli/tree/main/packages/cli/skill-data/mbql
- **Repository:** https://github.com/metabase/metabase-cli
- **GitHub stars:** 20
- **License:** AGPL-3.0
- **Skill name:** mbql
- **Collection:** https://github.com/metabase/metabase-cli
- **Categories:** [analytics and data](https://ai-powered.com/categories/analytics-and-data)
- **Listing updated:** 2026-12-03

## About

This skill teaches an agent the structured MBQL query format used by the mb command-line tool for Metabase. It covers the query shape, the clause syntax for filters, aggregations, breakouts, ordering, limits, expressions and joins, plus multi-stage pipelines that read saved questions, models, metrics and segments as sources.

The workflow centers on a check loop: the agent validates a body with a dry run that compiles it on the server without executing, inspects the generated SQL or the tables and fields a body touches, and then runs it. The guidance explains how to read validation errors and which failures only surface when the warehouse runs the query.

The skill expects the mb CLI to be installed and configured with a profile, and it refers to the command-line schema and a bundled operator reference for the full list of operators. It also notes where a query body lives in cards, transforms, measures and segments.

## When your agent uses it

> Author and debug MBQL query bodies for the `mb` CLI — the query shape, clauses, filters, aggregation and breakout, order and limit, expressions, joins and FK columns, multi-stage pipelines, saved questions and definitions as sources, output column names, and the schema → dry-run → run loop. Use when writing or fixing any query body — `mb query`, a card's `dataset_query`, a transform's `source.query`, or a segment/measure `definition` — or when `--dry-run` or a run reports errors. Triggers — "write an MBQL query", "the dataset_query is wrong", "aggregate and group by", "join two tables", "month-over-month".

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/metabase/metabase-cli/tree/HEAD/packages/cli/skill-data/mbql)
- [Asks for: Read, Write, Edit, Bash, AskUserQuestion](https://github.com/metabase/metabase-cli/blob/HEAD/packages/cli/skill-data/mbql/SKILL.md)
- [License: AGPL-3.0](https://github.com/metabase/metabase-cli/tree/HEAD/packages/cli/skill-data/mbql)

## Features

- **Query shape and clauses:** Explains the stage structure and the bracketed clause syntax with options, field references and ids.
- **Filters and aggregations:** Covers AND and OR filters, relative and absolute date ranges, breakouts and named aggregations.
- **Joins and foreign keys:** Shows how to reach columns of related tables through foreign keys or explicit joins.
- **Multi-stage pipelines:** Describes filtering on aggregates and month-over-month comparisons using window offsets.
- **Dry-run authoring loop:** Walks through schema lookup, dry-run validation, compiling to SQL and running queries.
- **Saved sources and definitions:** Covers saved questions, models, metrics, segments and measures as query sources.

## Good for

- Write an MBQL query that counts orders by month
- Fix a card's dataset_query that returns the wrong results
- Join two tables through a foreign key and group the results
- Compute month-over-month revenue change with a window offset
- Debug a query that fails a dry run in the mb CLI

## Install

### Claude Code

Copy the skill folder to `~/.claude/skills/mbql` to use it in all your projects:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/metabase/metabase-cli.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/mbql &&
cp -R "$tmp/packages/cli/skill-data/mbql" ~/.claude/skills/mbql &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/mbql` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/mbql` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/metabase/metabase-cli.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/mbql &&
cp -R "$tmp/packages/cli/skill-data/mbql" ~/.agents/skills/mbql &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/mbql` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/mbql` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/metabase/metabase-cli.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/mbql &&
cp -R "$tmp/packages/cli/skill-data/mbql" ~/.cursor/skills/mbql &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/mbql` inside it instead.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/metabase/metabase-cli.git --path packages/cli/skill-data/mbql
```

Or copy the folder to `~/.gemini/skills/mbql` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/mbql`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/metabase/metabase-cli.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/mbql &&
cp -R "$tmp/packages/cli/skill-data/mbql" ~/.copilot/skills/mbql &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/mbql` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/metabase/metabase-cli.git
```

Then copy `metabase-cli/packages/cli/skill-data/mbql` into your agent's skills folder as `mbql`. Agents that support SKILL.md read one folder per skill.

## FAQ

### What does Mbql need to work?

It relies on the mb CLI with a configured profile, and on the ids of databases, tables, fields and cards copied from the mb list commands.

### When does the skill trigger?

When writing or fixing a query body for mb query, a card's dataset_query, a transform's source query, or a segment or measure definition, or when a dry run or run reports errors.

### Does Mbql run queries for me?

The guidance uses dry-run to check and compile a body on the server, and a run executes it. Exit codes distinguish invalid bodies from server or warehouse failures.

### When should native SQL be used instead?

The skill says to write native SQL for window functions beyond offset, CTEs, set operations, engine-specific functions, or when SQL is requested.

### How do I install Mbql in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/mbql to use it in all your projects, or to .claude/skills/mbql in one project.

### Does Mbql run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Mbql?

Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.

### What are the best alternatives to Mbql?

The closest alternatives to Mbql are Native SQL, Metabase CLI, Core, Dashboard and Data workflow.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Native SQL](https://ai-powered.com/skills/native-sql): Native SQL is an open-source agent skill for databases.
- [Metabase CLI](https://ai-powered.com/skills/metabase-cli): Metabase CLI is an open-source agent skill for analytics and data.
- [Core](https://ai-powered.com/skills/core-metabase): Core is an open-source agent skill for analytics and data.
- [Dashboard](https://ai-powered.com/skills/dashboard): Dashboard is an open-source agent skill for analytics and data.
- [Data workflow](https://ai-powered.com/skills/data-workflow): Data workflow is an open-source agent skill for analytics and data.
- [Metadata](https://ai-powered.com/skills/metadata): Metadata is an open-source agent skill for analytics and data.
- [Transform](https://ai-powered.com/skills/transform-metabase): Transform is an open-source agent skill for analytics and data.
- [Document](https://ai-powered.com/skills/document-metabase): Document is an open-source agent skill for files and documents.

---
Source: https://ai-powered.com/skills/mbql
