Add to Claude

Guides · For agents

Let an AI agent count a Postgres or MySQL table without write access

Tools: sift_count, sift_profile, sift_matchWorks with Claude Code

Put the connection string in an environment variable, turn databases on for Sift, and your agent can ask for counts and totals from a table. Sift opens the database read-only, runs at most one SELECT, and hands back numbers, not rows.

Turn it on

Live databases are off until you turn them on. Add two lines to Sift's entry in your MCP config: the switch, and a variable holding the connection string.

{
  "mcpServers": {
    "sift": {
      "command": "npx",
      "args": ["-y", "@heyife/siftdata@0.8.2"],
      "env": {
        "SIFT_ALLOW_DATABASES": "1",
        "BILLING_DB": "postgres://readonly_user:password@host:5432/billing"
      }
    }
  }
}

For MySQL, use a MySQL connection string and the type mysql. Use a database user that can only read.

Ask your agent

With Sift connected (setup takes three steps), paste this and swap in your own table and variable names.

Use Sift on the Postgres table public.subscriptions, connection env:BILLING_DB. Count the rows where status is active and plan is Pro, and total the mrr column.

What Sift sends back

Active and Pro7 of 20 accounts (35.0%)
Total MRR594.00, average 99.00
Left out of the total1 blank MRR
All active accounts13, MRR 1,378.00

These numbers come from a test copy of the table in a DuckDB database file. Database tables always run on Sift's DuckDB engine, and the same rows saved as a CSV give the same answer.

What Sift refuses

A DELETE, UPDATE or anything but one SELECTRefused: a query must be one SELECT
A connection string typed into the callRefused: it must name an environment variable, as env:NAME
A live database before it is turned onRefused until SIFT_ALLOW_DATABASES is 1

What to do next

Questions

Can the agent change the database through Sift?
No. Sift opens the database read-only and refuses any query that is not a single SELECT. Use a read-only database user as well.
Does the agent see the password?
No. The connection string sits in an environment variable in your MCP config. The agent only names it, as env:BILLING_DB. A connection string typed into the call is refused.
Why is it off by default?
A live database is the one thing Sift reaches over the network, so it stays off until you set SIFT_ALLOW_DATABASES. The first connection also downloads DuckDB's Postgres or MySQL extension.

More guides

Guide COUNTIFS and SUMIFS on a file too big for Excel Guide See what's in a Parquet or JSON file without writing code Guide Why your AI agent should not clean a big CSV by itself