DistillQL

Connect an AI app

This page needs the MCP extra: pip install 'distillql[mcp]'. Without an AI app, the command line and Python API need only pip install distillql.

Here DistillQL calls no model and needs no API key. Your AI app starts DistillQL as an MCP server, calls its tools, and runs its own model under your plan or key. To use a model with no AI app, such as one in Ollama or LM Studio, see use any LLM.

distillql init crawls your database and adds DistillQL to Claude Code for you, and prints the setup for the apps below. To do it by hand, crawl first, so the tools have a context to read:

distillql crawl distillql.yaml --out .distillql/context.yaml

An AI app starts DistillQL with nobody there to type a password, so keep the password in the keychain, an environment variable set in the app's settings, or a command.

The six tools

Tool What it does
glossary The company's terms on one page. With a question, the terms it names come first and in full. The server also sends the page as its instructions, which the app keeps in its system prompt, so an agent calls glossary only for a term the page cuts or lacks.
search_context The tables, metrics and reviewed queries that fit a question. It also names the question's words that no table, column, value, comment or term uses, such as tickets in a database with no support data, so the agent can say the data does not answer the question instead of answering from a stand-in.
query Runs SQL as the user. Returns a handle, a 3-row sample and notes, never every row; profile with op="explain" gives the explain record. Pass expect_columns, the columns the question asks for, and a note names any the result lacks or adds. A filter on a text value the column does not hold, such as status = 'complete' where the values are completed and open, gets a note with the column's values and the closest; the crawl's value list is checked on every query, and an empty result without one gets a small lookup.
profile Describes, filters, aggregates or charts a handle without moving its rows, or gives its explain record.
write Saves a handle to a local table, or to a file inside write_dir.
verify Proposes an answer's SQL as a reviewed query. It stays a proposal until a person accepts it.

Results reach the agent as compact JSON text, without indentation. Claude Code keeps a server's instructions up to 4,096 characters, so the page sent there is cut to about 4,000 and says when it was cut.

Apps that start the server themselves

These apps start distillql mcp as a program and talk to it over its input and output. Use full paths: an app may start from a folder other than yours, and may not have distillql on its path. which distillql prints where it is.

Claude Code:

claude mcp add distillql -- distillql mcp /path/to/distillql.yaml --context /path/to/.distillql/context.yaml

Claude Desktop, in claude_desktop_config.json (Settings, Developer, Edit config):

{"mcpServers": {"distillql": {
  "command": "/full/path/to/distillql",
  "args": ["mcp", "/path/to/distillql.yaml", "--context", "/path/to/.distillql/context.yaml"]}}}

OpenAI Codex CLI, in ~/.codex/config.toml:

[mcp_servers.distillql]
command = "/full/path/to/distillql"
args = ["mcp", "/path/to/distillql.yaml", "--context", "/path/to/.distillql/context.yaml"]

Cursor, in ~/.cursor/mcp.json: the same shape as Claude Desktop's.

We test with Claude Code. Claude Desktop, Codex and Cursor use the same MCP standard, but we have not run them yet.

Apps that connect by URL

ChatGPT (in developer mode) and Claude on the web run in the cloud. They can only reach a server at a public HTTPS address, and they sign in with OAuth. distillql mcp --http serves on your machine behind that sign-in, and a tunnel gives it a public address.

  1. Start a tunnel to a local port. With Cloudflare's free tunnel:

cloudflared tunnel --url http://127.0.0.1:8000

It prints an address such as https://words-words.trycloudflare.com.

  1. Start DistillQL with that address:

distillql mcp distillql.yaml --context .distillql/context.yaml --http --public-url https://words-words.trycloudflare.com

It prints the address to add. Each time an app asks for approval, it prints a pairing code for that request, such as XU8P-WXHU-XKWA, beside the site the approval sends you back to.

  1. In your app, add a connector with the address and /mcp on the end: https://words-words.trycloudflare.com/mcp. In ChatGPT, turn on developer mode in its settings, then add a connector. In Claude, go to Settings, then Connectors, and add a custom connector. Both apps have moved these menus before, so check their help pages if you can't find them.

  2. The app opens an approval page that names the site it sends you back to. Check that the terminal shows the same site, then enter that request's code.

Anyone with the address and a code can query as you, so keep codes to yourself. The page shows the app's name as the app chose it; trust the site name. Five wrong codes end that request only; start again from the app. Approvals end when the server stops. The server listens only on 127.0.0.1. It refuses a public address that is not HTTPS.

We have tested the sign-in with our own client, but not yet with ChatGPT or Claude on the web.

Without MCP

The same tools are Python functions, for an agent you build yourself:

import distillql
from distillql.context.model import ContextModel

con = distillql.connect("distillql.yaml")
tools = distillql.Tools(con, ContextModel.from_yaml(".distillql/context.yaml"))
print(tools.glossary("revenue by region last month"))
answer = tools.query("select ...")

The Python API lists each one.