Skip to main content
skill CX Codex

metabase-database-metadata — Claude Code skill: read Metabase schema

This skill teaches the agent the Metabase Database Metadata Format, so it can read your schema from a YAML tree: columns, types, foreign keys. Handy before writing queries.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add metabase/agent-skills --skill metabase-database-metadata -a claude-code
Open on GitHub

What metabase-database-metadata does

The skill covers the Metabase Database Metadata Format — a YAML tree of databases, tables and fields synced from a Metabase instance. Everything lives under .metadata/databases/, and the agent reads those files instead of guessing table shapes. The files are diff-friendly: numeric IDs are dropped, and foreign keys use natural-key tuples such as ["Sample Database", "PUBLIC", "ORDERS"].

Next to the tree sits .metadata/table_metadata.json, the raw export from Metabase. It can run into gigabytes, so the skill forbids opening it, grepping it or passing it to tools — it exists only as input to the extractor. That is also why .metadata/ belongs in .gitignore; committing it would bloat the repo. The skill asks for confirmation before touching .gitignore.

A first export needs the instance URL and an API key, for example through METABASE_URL and METABASE_API_KEY. Metadata comes from POST /api/ee/serialization/metadata/export with the with-databases, with-tables and with-fields parameters — all false by default, so you have to opt sections in. Then npx @metabase/database-metadata extract-table-metadata turns the JSON into the YAML tree. At session start the skill fetches nothing: if the tree is already on disk, it just uses it. Refreshing happens only when the user asks. The format spec ships alongside as spec.md.

What it helps with

  • understand a table's columns before writing a query
  • trace foreign keys between tables without parsing raw JSON
  • export Metabase metadata into a readable YAML tree
  • tell the agent which columns and types a project has
  • refresh a stale schema after database changes

Example prompts for the agent

  • Look in .metadata/databases/ and list the tables in the ORDERS database
  • Write a query against ORDERS using the schema from the Metabase metadata
  • Refresh the metadata from Metabase and show what changed in the schema

How to install metabase-database-metadata

1Skills CLI (Vercel)

npx skills add metabase/agent-skills --skill metabase-database-metadata -a claude-code

2Manually: put the files in place

~/.claude/skills/metabase-database-metadata/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/metabase-database-metadata/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about metabase-database-metadata

How do I install metabase-database-metadata in Claude?

Run npx skills add metabase/agent-skills --skill metabase-database-metadata -a claude-code. The skill lands at ~/.claude/skills/metabase-database-metadata/SKILL.md.

What does metabase-database-metadata do?

It teaches the agent to read the Metabase metadata YAML tree: databases, tables, fields, types and foreign-key relationships. The agent pulls the schema from .metadata/databases/ rather than guessing.

What do I need to export the metadata?

A Metabase instance URL and an API key — the skill expects them via METABASE_URL and METABASE_API_KEY. Without credentials it asks for them before running the export call.

Source text

SKILL.md · MIT
---
name: metabase-database-metadata
description: Understands the Metabase Database Metadata Format — a YAML-based on-disk representation of databases, tables, and fields synced from a Metabase instance. Use when the user needs to read, edit, or understand metadata files produced by `@metabase/database-metadata`, or when reasoning about a project's schema (columns, types, FK relationships) through the `.metadata/databases` folder.
model: opus
allowed-tools: Read, Edit, Glob, Grep, Bash, AskUserQuestion
---

## Metabase Database Metadata Format

Metabase represents database metadata — synced databases, their tables, and their fields — as a tree of YAML files. Files are **diff-friendly**: numeric IDs are omitted entirely, and foreign keys use natural-key tuples like `["Sample Database", "PUBLIC", "ORDERS"]` instead of database identifiers.

The format is defined by a specification bundled alongside this file as `spec.md` (upstream source: [metabase/database-metadata](https://github.com/metabase/database-metadata)). The same project ships a CLI (`@metabase/database-metadata` on npm) that converts the raw JSON exported from a Metabase instance into the YAML tree described by the spec.

## Canonical layout

All metadata for a project lives under a top-level `.metadata/` directory:

- **`.metadata/databases/`** — the YAML tree. **This is the canonical source for the agent.** Read these files to understand the schema, columns, types, and FK relationships.
- **`.metadata/table_metadata.json`** — the raw JSON exported from the Metabase instance. Potentially multi-megabyte (or multi-gigabyte) JSON with flat `databases` / `tables` / `fields` arrays. **Never open, grep, or pass it to tools.** It exists only as input to the extractor.

The `.metadata/` directory should be gitignored. On large warehouses the extracted metadata can reach gigabytes — committing it would make the repo painful or unusable.

## First-time setup

Do not run any of the steps below proactively at session start. Only run them when the user **explicitly asks** to fetch metadata, set up the workflow, or requests something that plainly requires knowledge of the database schema (e.g. "write a query against ORDERS", "describe what tables exist").

When setup is triggered:

### 1. Ensure `.metadata/` is gitignored

Read the repo's `.gitignore` and confirm `.metadata/` is listed. If it isn't, **ask the user before modifying `.gitignore`** — e.g.:

> `.metadata/` is not in `.gitignore`. Committing it would bloat the repo (metadata can be gigabytes). Shall I add it?

Only edit `.gitignore` after the user confirms.

### 2. Export the metadata from Metabase

Fetch `table_metadata.json` by calling `POST /api/ee/serialization/metadata/export` on the Metabase instance and writing the response to `.metadata/table_metadata.json`. The endpoint accepts three boolean query parameters that opt sections in or out — they all default to `false`, so requests must explicitly set the sections they want:

- `with-databases` — include the `databases` array.
- `with-tables` — include the `tables` array.
- `with-fields` — include the `fields` array.

A typical full export sets all three to `true`. The user supplies the base URL and an API key (e.g. via `METABASE_URL` and `METABASE_API_KEY` env vars):

```sh
mkdir -p .metadata
curl -sf -X POST "$METABASE_URL/api/ee/serialization/metadata/export?with-databases=true&with-tables=true&with-fields=true" \
  -H "X-API-Key: $METABASE_API_KEY" \
  -o .metadata/table_metadata.json
```

If the user has not provided credentials, ask for them before running the call.

### 3. Extract

Once `.metadata/table_metadata.json` is in place:

```sh
rm -rf .metadata/databases
npx @metabase/database-metadata extract-table-metadata .metadata/table_metadata.json .metadata/databases
```

Then read the YAML tree under `.metadata/databases/` to answer the user's question.

## Session start behaviour

At the start of a session, do not run any fetch commands. Just observe what's on disk:

- If `.metadata/table_metadata.json` **and** `.metadata/databases/` both exist, **assume the tree is sufficiently up to date** and use it directly. Do not refetch.
- If the tree is missing or only partial, do nothing until the user asks for something that needs it — then fall into the first-time-setup flow above.

If something in the tree looks stale or inconsistent while you're using it, mention it to the user and let them decide whether to refetch. Never refresh silently.

## Refreshing (user-initiated only)

If the user explicitly asks to refresh metadata, re-run the export call to overwrite `.metadata/table_metadata.json`, then re-run the extract step. Always remove `.metadata/databases` before re-extracting so stale files are not left behind.

## Entities

Three entity types, two file types:

| Entity | File | Description |
|--------|------|-------------|
| **Database** | `.metadata/databases/{db}/{db}.yaml` | A connected data source (Postgres, MySQL, BigQuery, etc.). Identified by name. |
| **Table** | `.metadata/databases/{db}/schemas/{schema}/tables/{table}.yaml` (or `.../tables/{table}.yaml` for schemaless DBs) | A physical table or view. Contains a `fields` array with all its columns nested inline. |
| **Field** | (nested inside a Table YAML, no separate file) | A column. Includes `base_type`, `database_type`, and optionally `effective_type`, `semantic_type`, `coercion_strategy`, `parent_id`, `fk_target_field_id`. |

## Foreign keys

Foreign keys use natural-key tuples, not numeric IDs:

- **Database FK**: the database name (string) — e.g. `"Sample Database"`
- **Table FK**: `[database, schema_or_null, table]` — e.g. `["Sample Database", "PUBLIC", "ORDERS"]`
- **Field FK**: `[database, schema_or_null, table, field, ...nested_field_names]` — e.g. `["Sample Database", "PUBLIC", "EVENTS", "DATA", "user", "name"]` for a JSON-unfolded column `DATA.user.name`

Field-level FKs show up as `parent_id` (nested field parent) and `fk_target_field_id` (referenced PK for FK columns).

## Type attributes on fields

- **`database_type`** — the raw native type string from the driver (`BIGINT`, `VARCHAR`, `JSONB`, etc.). Database-specific.
- **`base_type`** — the Metabase type matching the native type (`type/BigInteger`, `type/Text`, `type/Structured`, etc.).
- **`effective_type`** — the type Metabase treats the column as at query time. Only emitted when it differs from `base_type` (i.e. coercion is configured).
- **`coercion_strategy`** — the rule producing `effective_type` from `base_type` (e.g. `Coercion/ISO8601->DateTime`, `Coercion/UNIXMilliSeconds->DateTime`).
- **`semantic_type`** — business-domain label (`type/PK`, `type/FK`, `type/Email`, `type/Category`, `type/Latitude`, etc.). Drives UI and some analytical behavior.

See the bundled spec for the full type hierarchy and available coercion strategies.

## Reading the spec

This skill ships with a local snapshot of the spec as `spec.md`, alongside `SKILL.md`.

**Read it on demand, not eagerly.** Open `spec.md` only when you actually need detail beyond what `SKILL.md` summarizes — e.g. the full base-type / semantic-type hierarchy, the complete list of coercion strategies, or the exact folder-path rules. Do not open it at session start, and do not open it for tasks unrelated to the metadata tree.

If the bundled copy looks out of date with the upstream package, the skill's own `README.md` documents how to refresh it with `extract-spec`.

© metabase · MIT · metabase/agent-skills

Similar skills

All skills for Data and databases →

From the same set8

metabase-cli Controls a Metabase instance through the mb CLI: runs card queries, manages dashboards, traverses collections, and triggers schema syncs from the terminal. CX Codex +1 778installs metabase-representation-format A skill that explains Metabase's YAML serialization format: collections, cards, dashboards, segments, measures, transforms and data apps. Useful when an agent edits or validates those files. CX Codex +1 529installs metabase-semantic-checker Runs the Metabase semantic checker over a tree of Representation Format YAML files and verifies that entity and column references resolve. Useful when you suspect a broken reference. CX Codex +1 429installs metabase-embedding-sso-implementation A skill that walks the agent through adding JWT SSO to your Metabase embedding: signing endpoint, frontend auth layer, group mappings. CX Codex +1 363installs metabase-react-sdk-setup A skill that walks the agent through first-time setup of the Metabase React SDK: instance detection, API key, dashboard discovery, JWT auth and package install. CX Codex +1 362installs metabase-static-embedding-to-guest-embedding-upgrade Moves a project from signed Metabase iframes to guest embeds built on web components and embed.js. Useful when /embed/ iframes need to become <metabase-dashboard> and <metabase-question>. CX Codex +1 355installs metabase-learning Runs you through a 9-session Metabase curriculum with spaced-repetition reviews. Useful when you want a fixed path instead of scattered docs. CX Codex +1 324installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor