# How to connect Cloudflare D1 to AI agents?

Connect Cloudflare D1 to Sequel and ask your serverless SQLite database questions in natural language, from the app or any MCP client.

Connect Cloudflare D1 to Sequel and query it in plain English, from the Sequel app or any AI tool wired up to the [MCP server](/docs/install). D1 is Cloudflare's serverless SQLite database, and Sequel reaches it over Cloudflare's D1 API, so there is nothing to install and no tunnel or IP allowlist to configure.

The interesting part is usually not D1 on its own. D1 holds your product data, while the rest of the answer lives in billing, CRM, and analytics. Once D1 is connected you can ask one question that spans all of them and let Sequel work out which source answers which part.

## What you'll need

- A **Cloudflare account** with at least one **D1 database**.
- Permission to authorize applications on that account. If your account administrator has turned off third-party OAuth access under **Manage Account → Members → Settings**, you will need them to re-enable it.

<Callout type="note" title="One connection, one database">
A Sequel connection is pinned to exactly one D1 database, chosen when you connect. Sequel has no way to list or query any other database on your account through that connection. To query a second database, add a second connection.
</Callout>

## Connect it

<Steps>
<Step title="Open a new connection">
In the Sequel dashboard, go to **Connections → New connection** and choose **Cloudflare D1**.
</Step>

<Step title="Sign in with Cloudflare">
You'll be sent to Cloudflare's consent screen. Approve the connection to give Sequel read access to your D1 databases. There is no API token to create, paste, or rotate, and you can revoke access at any time.
</Step>

<Step title="Pick a database">
Sequel lists the D1 databases you just authorized, grouped by account. Choose the one this connection should use.

Sequel stores the account and database you picked, so subsequent queries always go to that database and nowhere else.
</Step>

<Step title="Test and save">
Sequel reads your table and column definitions from `sqlite_master` and `PRAGMA table_info`, then writes a short summary of what the database contains. A green check means it's live.
</Step>
</Steps>

## Try it

Once connected, ask things like:

- "How many rows are in each table?"
- "Show me the 20 most recently created users."
- "Plot daily order volume for the last 30 days."
- "What's the conversion rate from signup to first purchase, by month?"
- "Which customers in D1 also have an active Stripe subscription?"

Because D1 is SQLite, joins, CTEs, window functions, and JSON1 queries all work the way you'd expect.

## How Sequel reads your schema

Sequel introspects the database once at connect time, and again when you refresh the schema:

- Tables come from `sqlite_master`, excluding SQLite's own `sqlite_*` tables and D1's internal `_cf_*` bookkeeping tables.
- Columns come from `PRAGMA table_info`, which supplies the type, `NOT NULL` status, default value, and primary-key flag for each one.

That schema is summarized and stored with the connection, so the agent knows your real column names before it writes any SQL.

## What Sequel can and can't do

Sequel requests four read-only scopes and nothing else:

| Scope | What it's for |
| --- | --- |
| `d1.read` | Read your D1 databases and run `SELECT` queries |
| `memberships.read` | List which Cloudflare accounts you belong to |
| `account-settings.read` | Resolve those accounts for the database picker |
| `user-details.read` | Identify the signed-in user |

Read-only is enforced by Cloudflare, not just by convention on our side. Because Sequel holds only `d1.read`, a write that somehow reached the D1 API would be rejected by Cloudflare itself. Sequel requests no Workers, DNS, or zone access at all.

You can revoke the grant at any time from your Cloudflare profile under Access Management.

## Troubleshooting

| Symptom | Likely fix |
| --- | --- |
| No databases in the picker | The authorized account has no D1 databases yet, or you approved a different account than you expected. Create a database, or reconnect and pick the right account. |
| "Cloudflare has revoked access for this connection" | The grant was revoked, or an administrator disabled third-party OAuth for the account. Reconnect from Sequel once access is restored. |
| Consent screen won't let you approve | Your account administrator has blocked public OAuth app access under **Manage Account → Members → Settings**. |
| "no such table" | The table may have been created after you connected. Refresh the schema from the connection settings. |
| A table is missing from the schema | Tables named `sqlite_*` or `_cf_*` are filtered out deliberately. Anything else should appear after a schema refresh. |
| A write query fails | Expected. Sequel holds only the `d1.read` scope, so Cloudflare rejects writes. |

## Related

- [Connecting your first data source](/docs/connecting-your-first-data-source)
- [Chatting with your data](/docs/chatting-with-your-data)
- [Browse all integrations](/docs/integrations)
