> For the complete documentation index, see [llms.txt](https://docs.espresso.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.espresso.ai/mcp-server/onboarding.md).

# Onboarding

The Espresso MCP server can connect a new Snowflake account to Espresso and set up [dbt Markers](#setting-up-dbt-markers) in your dbt projects. It provides a Snowflake onboarding skill that guides the agent through finding your accounts, creating the setup, and registering each account. The agent loads it automatically when you ask to connect a Snowflake account.

## Example

> Connect my Snowflake account to Espresso.

Before touching Snowflake, the agent asks which accounts to onboard and how they're set up, and offers these choices:

1. **Look it up for me.** The agent checks only your machine and repo, such as a Snowflake MCP server, `snow connection list`, and Terraform, Pulumi, or other Snowflake code, and reports what it finds. Nothing touches Snowflake.
2. **I'll tell you.** You give the account identifiers, whether Espresso was set up there before, and whether a network policy is set. The agent can give you a read-only preflight query to run in Snowsight and paste back.
3. **Type something.** Describe your setup in your own words.

The agent then calls `get_snowflake_setup` and creates the setup using the method that fits your account. Once the setup exists, it calls `register_snowflake_account` and returns the new account slug when every check passes.

## Onboarding a Snowflake account

Onboarding takes two steps: create the Espresso user and its access in Snowflake, then register the account with Espresso.

### 1. Get the setup

`get_snowflake_setup` returns everything Espresso needs in your Snowflake account. It changes nothing.

* `spec`: the user, role, warehouse, grants, and user parameters to create. It includes Espresso's public key and a `comment` that must be set on the user exactly as given.
* `sql`: the spec as a ready-to-run SQL script.
* `preflightSql`: a query that shows what already exists and which role is current. Run it first to avoid conflicts with existing objects.
* `networkPolicyIps`: the IP addresses to allow if your account has a network policy.

### 2. Create the setup in Snowflake

Choose the method that matches how you manage Snowflake:

* **Run the SQL script.** Run `preflightSql`, then `sql`, in a Snowsight worksheet or SnowSQL, using a role that can create users, roles, and warehouses and grant privileges (usually `ACCOUNTADMIN`). This is the fastest method.
* **Infrastructure as code.** If you manage Snowflake with Terraform or a similar tool, ask the agent to write the resources from `spec`, then apply them through your usual review process. Build from `spec` rather than translating `sql`, so every grant and parameter carries over exactly.
* **Let the agent run it.** If your agent also has access to Snowflake, for example through the Snowflake CLI or a Snowflake MCP server, it can run the preflight and setup SQL for you. It uses that connection's role and permissions, not Espresso's.

Whichever method you use, if your account has a network policy, add `networkPolicyIps` to it.

### 3. Register the account

`register_snowflake_account` takes `account`: your account URL or identifier, for example `https://myorg-myaccount.snowflakecomputing.com` or `myorg-myaccount`. It connects to the account as Espresso and runs a set of `checks`. Nothing is registered until every check passes. A failing check returns a `code` and a `fix`; apply the fix and call the tool again. It's safe to call repeatedly, so with infrastructure as code you can call it again once your change is applied.

On success, it returns the account's `customer` slug, which the other tools use, and Espresso follows up with a savings estimate. Calling it on an account that's already registered replaces the stored credentials.

Example prompts:

> Onboard Snowflake account myorg-myaccount. Show me the preflight query and setup SQL, and I'll run them.

> Write Terraform for the Espresso Snowflake setup that matches our modules in `infra/snowflake/`. Once I've applied it, register account myorg-myaccount.

## Setting up dbt Markers

[dbt Markers](https://docs.espresso.ai/snowflake-optimizer/proxy-onboarding/dbt-markers.md) adds a JSON comment to every statement dbt runs, so Espresso can attribute Snowflake queries to dbt runs and models. The Espresso MCP server provides a dbt Markers skill that adds it to the dbt projects in your repo. The agent loads it when you ask to set up dbt Markers or to attribute Snowflake spend to dbt.

> Set up Espresso's dbt Markers in this repo.

The agent calls `get_dbt_markers_setup` for the current package revision, finds each `dbt_project.yml` in the repo, and asks which to set up if there's more than one. For each project, it:

1. Checks that the project uses dbt-core 1.6 or later, from version pins in the repo. If it's older, the agent stops and says to upgrade dbt first.
2. Adds the package to `packages.yml`, keeping your other packages. If an older dbt Markers revision is listed, it updates it.
3. Sets the `query-comment` in `dbt_project.yml`, always with `append: true`, since Snowflake drops comments placed before the statement.
4. Shows the changes and tells you to run `dbt deps`.

The agent doesn't run dbt or connect to Snowflake, and it only commits or opens a pull request if you ask.

### Projects that already have a query comment

dbt allows one `query-comment` per project, and Espresso reads the whole comment as one JSON object. The agent keeps your comment rather than replacing it:

* **Your comment is a JSON object**, for example from a macro that returns `tojson(...)`. The agent merges it into the dbt Markers comment, so both sets of keys end up in one object:

  ```yaml
  query-comment:
    comment: "{{ dbt_markers.query_comment(node, extra=fromjson(my_query_comment(node))) }}"
    append: true
  ```

  Your macro is left unchanged. Keys that dbt Markers already writes keep dbt Markers' value, and keys whose values are objects, lists or empty are dropped. The agent lists them for you. If your comment has a `node_id`, `node_refs` or `raw_code_hash` key, the agent suggests renaming it, since Espresso would read it in place of its own.
* **Your comment is anything else**, such as plain text, or your runs and models are labeled in a Snowflake query tag such as `DBT|PROD|...`. The agent changes nothing in that project and explains why. Contact <support@espresso.ai> to have Espresso read your format.
