Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ show_title_breadcrumb: true
category: Ai
title: Agent-driven development
source_url: >-
https://github.com/metabase/metabase/blob/master/docs/ai/file-based-development.md
https://github.com/metabase/metabase/blob/master/docs/ai/agent-driven-development.md
layout: new-docs
summary: >-
Use a coding agent and the Metabase CLI to create Metabase content, then
version that content as YAML files with Remote Sync.
redirect_from:
- /docs/latest/ai/file-based-development
latest: true
---

Expand Down Expand Up @@ -57,7 +59,7 @@ Once you have these set up, you can step through the example workflow.

1. Set up a Metabase instance to check your work before pushing changes to production. This Metabase should connect to the same data warehouse(s) your production Metabase connects to. A [config file](../configuring-metabase/config-file) will come in handy here.

2. Create an [API key](../people-and-groups/api-keys#create-an-api-key) in this development Metabase and assign it to the Admin group, so the agent can create content and work with Remote Sync.
2. Make sure the agent can log in as an admin, so it can create content and work with Remote Sync. The CLI can sign in through your browser with an admin account. If you'll run the CLI from a script, create an [API key](../people-and-groups/api-keys#create-an-api-key) in this development Metabase and assign it to the Admin group.

3. We also recommend turning off the sample content and usage analytics, so they don't pollute the data model. If you're using a [docker compose file](../installation-and-operation/running-metabase-on-docker), add these [environment variables](../configuring-metabase/environment-variables):

Expand All @@ -84,11 +86,17 @@ Then authenticate it against your development Metabase:
mb auth login --url your-metabase-url-here
```

Authenticate with the API key you created in your Metabase instance.
The CLI offers to open your Metabase in a browser so you can sign in and approve the CLI. On Metabase versions before 63, or if you pick **With an API key** at the prompt, paste the API key you created in your development Metabase. Check out [Authenticate the CLI](../installation-and-operation/metabase-cli#authenticate-the-cli) for details.

### Add the agent skill

Add the [`/metabase-cli` skill](https://github.com/metabase/agent-skills/tree/main/skills/metabase-cli) to your agent so it knows how to use the CLI to create content directly in your Metabase.
Add the [`/metabase-cli` skill](https://github.com/metabase/agent-skills/tree/main/skills/metabase-cli) to your agent so it knows how to use the CLI to create content directly in your Metabase:

```
npx skills add metabase/agent-skills --skill metabase-cli -a claude-code
```

For other ways to install the skill, check out [The metabase-cli skill](../installation-and-operation/metabase-cli#the-metabase-cli-skill).

## Example prompts

Expand Down Expand Up @@ -153,4 +161,4 @@ Since the agent uses the CLI to create content directly in Metabase, to undo cha
- [Metabase CLI](../installation-and-operation/metabase-cli)
- [Metabase Representation Format](https://github.com/metabase/representations)
- [Agent skills](https://github.com/metabase/agent-skills)
- [MCP server](./mcp): for agents that need live metadata lookups outside the file-based workflow.
- [MCP server](./mcp): for agents that need live metadata lookups outside the agent-driven workflow.
4 changes: 2 additions & 2 deletions _docs/latest/ai/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ See [Available tools](#available-tools) for the list of functionality supported

You can use the MCP server to help you create Metabase content as serialized YAML files that you can import into your Metabase. Point your agent at the MCP server to give it access to your Metabase's database metadata (table names, fields, and sample values) so it can write questions and dashboards that point at real columns.

See [Agent-driven development](./file-based-development).
See [Agent-driven development](./agent-driven-development).

## Connecting to a local MCP server

Expand All @@ -214,6 +214,6 @@ If the site URL doesn't match an address your MCP client can reach, like if you'
## Further reading

- [Agent API](./agent-api)
- [File-based development](./file-based-development)
- [Agent-driven development](./agent-driven-development)
- [Metabase API docs](../api)
- [Model Context Protocol specification](https://modelcontextprotocol.io/)
4 changes: 2 additions & 2 deletions _docs/latest/ai/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Here are the different ways to use AI with Metabase:

- [Metabot](#metabot)
- [MCP server](#mcp-server)
- [Agent-driven file-based development workflow](#agent-driven-development-workflow)
- [Agent-driven development workflow](#agent-driven-development-workflow)

## Metabot

Expand Down Expand Up @@ -66,4 +66,4 @@ Use a coding agent like Claude Code with the Metabase CLI to create Metabase con

**Plans**: Agent-driven workflows require a Pro/Enterprise plan.

See [full docs for agent-driven workflow](./file-based-development)
See [full docs for agent-driven workflow](./agent-driven-development)
73 changes: 59 additions & 14 deletions _docs/latest/installation-and-operation/metabase-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,101 @@ latest: true

# Metabase CLI

The Metabase CLI (`mb`) is a command-line client for Metabase. `mb` authenticates against a Metabase instance with an API key and lets you or an AI agent read and write content like questions, dashboards, collections, and transforms over the Metabase API.
The Metabase CLI (`mb`) is a command-line client for Metabase. `mb` logs in to a Metabase instance and lets you or an AI agent read and write content over the Metabase API: questions, dashboards, collections, transforms, and more.

> Looking for the commands built into the Metabase JAR, like `migrate` or `load-from-h2`? Check out [Metabase JAR commands](./commands).

## Requirements

- Node.js, to install the CLI from npm.
- A Metabase instance on version 58 or later.
- An [API key](../people-and-groups/api-keys#create-an-api-key) to authenticate the CLI against your instance.
- Node.js 20.6 or later, to install the CLI from npm.
- A Metabase instance on version 58 or later. Some command groups need a newer Metabase (for example, browser login needs version 63). The CLI tells you when that's the case.
- A Pro or Enterprise plan for some command groups. For example, `git-sync` needs the premium [Remote sync](./remote-sync) feature.

## Install the CLI

```
```sh
npm install -g @metabase/cli
```

The binary is `mb`.

For commands, run:

```
```sh
mb --help
```

To update to the latest version later, run `mb upgrade`.

## Authenticate the CLI

Log in once per Metabase instance.
Log in once per Metabase instance:

```
```sh
mb auth login --url https://metabase.example.com
```

The CLI prompts for an API key, or reads it from the `METABASE_API_KEY` environment variable or stdin. To create a key, see [API keys](../people-and-groups/api-keys#create-an-api-key).
The CLI offers to open Metabase in your browser. Sign in with your password or SSO and approve the CLI. The CLI stores a token that refreshes itself, so you never paste a secret. If you'd rather use an API key, pick **With an API key** at the prompt. If the `MB_API_KEY` environment variable is set, the CLI uses that key and skips the browser. This `MB_API_KEY` is read from the machine running the CLI. It's unrelated to the [`MB_API_KEY` environment variable](../configuring-metabase/environment-variables#mb_api_key) you can set on your Metabase server, which only guards the `/api/notify` endpoints.

Credentials are stored per profile, so you can manage more than one Metabase (like dev and prod Metabases):
On Metabase versions before 63, the CLI skips the browser and asks for an [API key](../people-and-groups/api-keys#create-an-api-key).

### Log in without a prompt

To log in from a script or CI, give the CLI an API key without putting the key on the command line. There are two ways to do that.

**Set the `MB_API_KEY` environment variable** (for example, from your CI provider's secret store) and run:

```sh
mb auth login --url https://metabase.example.com --profile default
```

**Or pipe the key on stdin** from a file or a secrets manager:

```sh
mb auth login --url https://metabase.example.com --profile default < api-key.txt
```

In both cases, include `--profile` (or set `MB_PROFILE`), naming the profile whatever you like. Without it, the CLI still asks for a profile name when run from a terminal, even though it already has the key.

The key must be a Metabase [API key](../people-and-groups/api-keys#create-an-api-key). If stdin isn't a terminal and no key arrives from the flag, stdin, or the environment variable, the CLI stops with "interactive login requires a TTY" rather than prompting.

### Check your login status or log out

To see whether you're logged in, which login method you used, and which Metabase version you're talking to, run:

```sh
mb auth status
```

To remove stored credentials, run `mb auth logout`.

### Manage more than one Metabase with profiles

Credentials are stored per profile, so you can manage more than one Metabase (like dev and prod Metabases):

```sh
mb auth login --profile prod --url https://prod.example.com
mb auth list
```

Add `--profile <name>` to any command to run it against that instance.
Add `--profile <name>` (or `-p <name>`) to any command to run it against that instance.

The CLI stores secrets in your operating system's keychain when it can. Otherwise it warns you and stores them in a plaintext `profiles.json` file.

## Use the CLI with an AI agent

The CLI is built to be driven by an AI coding agent like Claude Code. Instead of running commands yourself, you install a skill and describe what you want in plain language; the agent works out the commands.

### The metabase-cli skill

The [metabase-cli skill](https://github.com/metabase/agent-skills/tree/main/skills/metabase-cli) teaches your agent the CLI's conventions. Once installed, you can run:
The CLI ships with its own agent skills, so the instructions your agent reads always match the version of the CLI it's running. The [metabase-cli skill](https://github.com/metabase/agent-skills/tree/main/skills/metabase-cli) you install tells the agent to load those bundled skills with `mb skills get`.

You can install the skill:

- **From the Metabase agent skills repo**: `npx skills add metabase/agent-skills --skill metabase-cli -a claude-code`
- **As a Claude Code plugin**: `/plugin marketplace add metabase/mb-cli`, then `/plugin install metabase-cli@metabase`

Once installed, you can run:

```
/metabase-cli Create a dashboard summarizing this month's signups by plan.
Expand All @@ -77,12 +121,13 @@ And your agent will go to work, creating content directly in your Metabase via t

## Use the CLI for agent-driven development

Pair the CLI with version control to build content with an agent in a development Metabase, commit the changes, and pull the changes into your production Metabase. Check out [Agent-driven development](../ai/file-based-development).
Pair the CLI with version control to build content with an agent in a development Metabase, commit the changes, and pull the changes into your production Metabase. Check out [Agent-driven development](../ai/agent-driven-development).

## Further reading

- [Metabase CLI command reference](https://github.com/metabase/metabase-cli#readme)
- [@metabase/cli on npm](https://www.npmjs.com/package/@metabase/cli)
- [Agent-driven development](../ai/file-based-development)
- [Agent-driven development](../ai/agent-driven-development)
- [Agent skills](https://github.com/metabase/agent-skills)
- [Remote sync](./remote-sync)
- [Serialization](./serialization)
Expand Down
2 changes: 1 addition & 1 deletion _docs/latest/installation-and-operation/remote-sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ To version your data transformation logic, you can sync your [Transforms](../dat

## Local file repositories

Remote Sync can point at a bare git repo on the same filesystem as your Metabase process, via a `file://` URL. Local repos come in handy for local development, especially alongside the [file-based agent workflow](../ai/file-based-development).
Remote Sync can point at a bare git repo on the same filesystem as your Metabase process, via a `file://` URL. Local repos come in handy for local development, especially alongside the [agent-driven development workflow](../ai/agent-driven-development).

Create a bare git repo on the same filesystem as your Metabase process:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ show_category_breadcrumb: true
show_title_breadcrumb: true
category: Ai
title: 'Agent-driven development'
source_url: 'https://github.com/metabase/metabase/blob/master/docs/ai/file-based-development.md'
source_url: 'https://github.com/metabase/metabase/blob/master/docs/ai/agent-driven-development.md'
layout: new-docs
summary: 'Use a coding agent and the Metabase CLI to create Metabase content, then version that content as YAML files with Remote Sync.'
redirect_from:
- /docs/v0.63/ai/file-based-development
---

# Agent-driven development
Expand Down Expand Up @@ -53,7 +55,7 @@ Once you have these set up, you can step through the example workflow.

1. Set up a Metabase instance to check your work before pushing changes to production. This Metabase should connect to the same data warehouse(s) your production Metabase connects to. A [config file](../configuring-metabase/config-file) will come in handy here.

2. Create an [API key](../people-and-groups/api-keys#create-an-api-key) in this development Metabase and assign it to the Admin group, so the agent can create content and work with Remote Sync.
2. Make sure the agent can log in as an admin, so it can create content and work with Remote Sync. The CLI can sign in through your browser with an admin account. If you'll run the CLI from a script, create an [API key](../people-and-groups/api-keys#create-an-api-key) in this development Metabase and assign it to the Admin group.

3. We also recommend turning off the sample content and usage analytics, so they don't pollute the data model. If you're using a [docker compose file](../installation-and-operation/running-metabase-on-docker), add these [environment variables](../configuring-metabase/environment-variables):

Expand All @@ -80,11 +82,17 @@ Then authenticate it against your development Metabase:
mb auth login --url your-metabase-url-here
```

Authenticate with the API key you created in your Metabase instance.
The CLI offers to open your Metabase in a browser so you can sign in and approve the CLI. On Metabase versions before 63, or if you pick **With an API key** at the prompt, paste the API key you created in your development Metabase. Check out [Authenticate the CLI](../installation-and-operation/metabase-cli#authenticate-the-cli) for details.

### Add the agent skill

Add the [`/metabase-cli` skill](https://github.com/metabase/agent-skills/tree/main/skills/metabase-cli) to your agent so it knows how to use the CLI to create content directly in your Metabase.
Add the [`/metabase-cli` skill](https://github.com/metabase/agent-skills/tree/main/skills/metabase-cli) to your agent so it knows how to use the CLI to create content directly in your Metabase:

```
npx skills add metabase/agent-skills --skill metabase-cli -a claude-code
```

For other ways to install the skill, check out [The metabase-cli skill](../installation-and-operation/metabase-cli#the-metabase-cli-skill).

## Example prompts

Expand Down Expand Up @@ -149,4 +157,4 @@ Since the agent uses the CLI to create content directly in Metabase, to undo cha
- [Metabase CLI](../installation-and-operation/metabase-cli)
- [Metabase Representation Format](https://github.com/metabase/representations)
- [Agent skills](https://github.com/metabase/agent-skills)
- [MCP server](./mcp): for agents that need live metadata lookups outside the file-based workflow.
- [MCP server](./mcp): for agents that need live metadata lookups outside the agent-driven workflow.
4 changes: 2 additions & 2 deletions _docs/v0.63/ai/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ See [Available tools](#available-tools) for the list of functionality supported

You can use the MCP server to help you create Metabase content as serialized YAML files that you can import into your Metabase. Point your agent at the MCP server to give it access to your Metabase's database metadata (table names, fields, and sample values) so it can write questions and dashboards that point at real columns.

See [Agent-driven development](./file-based-development).
See [Agent-driven development](./agent-driven-development).

## Connecting to a local MCP server

Expand All @@ -211,6 +211,6 @@ If the site URL doesn't match an address your MCP client can reach, like if you'
## Further reading

- [Agent API](./agent-api)
- [File-based development](./file-based-development)
- [Agent-driven development](./agent-driven-development)
- [Metabase API docs](../api)
- [Model Context Protocol specification](https://modelcontextprotocol.io/)
4 changes: 2 additions & 2 deletions _docs/v0.63/ai/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Here are the different ways to use AI with Metabase:

- [Metabot](#metabot)
- [MCP server](#mcp-server)
- [Agent-driven file-based development workflow](#agent-driven-development-workflow)
- [Agent-driven development workflow](#agent-driven-development-workflow)

## Metabot

Expand Down Expand Up @@ -65,4 +65,4 @@ Use a coding agent like Claude Code with the Metabase CLI to create Metabase con

**Plans**: Agent-driven workflows require a Pro/Enterprise plan.

See [full docs for agent-driven workflow](./file-based-development)
See [full docs for agent-driven workflow](./agent-driven-development)
Loading