All posts
July 11, 2026·2 min read

Connecting a Database to AI Through MCP — Ask Questions Without SQL

How to give an AI model access to a database through MCP and ask questions about your data in plain language instead of writing SQL by hand. Explained using the Doka desktop agent.

Working with a database usually goes like this: recall the schema, write SQL, fix it, write it again. There's another way — connect the database to an agent through MCP and just ask: "how many orders were there last month, and from which customers." The agent handles the rest. Here's how to set it up.

What this gets you

  • Questions in plain language. The agent figures out the schema and builds the query itself — you don't have to remember table and column names.
  • Data exploration. "Show me what's even in this database" — and the agent describes the structure.
  • Reports. Pull the data, merge it, and put it straight into a file — in one pass.

What you'll need

  1. An MCP server for your database engine. Ready-made open servers exist for popular databases — PostgreSQL and SQLite, for instance. The launch command is in the server's README.
  2. A connection string to the database (host, port, database name, user) — the server usually accepts this through an environment variable.
  3. Doka with the "MCP Servers" tab.

To start, connect the database in read-only mode, with a dedicated user that has minimal permissions. That way the agent can answer questions but won't accidentally change anything. Widen the permissions later, once you've confirmed everything works the way it should.

Connecting it, step by step

  1. Pick an MCP server for your database engine and check its README — grab the launch command and the environment variable name for the connection string.
  2. In Doka, open the right panel → "MCP Servers""+ Add server."
  3. Fill in a name (like "Postgres — analytics"), the launch command, and its arguments.
  4. Under environment variables, enter the connection string as KEY=VALUE — take the variable name from the server's documentation.
  5. Flip the toggle and save.

On the next task, the agent will see the database tools and be able to query it. Start with a safe question like "describe this database's schema" to confirm the connection works.

Privacy

The MCP server runs locally, and if your database is local or on an internal network too, the data never leaves at all. That matters for analytics on sensitive data: paired with a local model, the whole loop stays on your side. The general pattern for connecting servers is in the article on useful MCP servers.

The bottom line

A database through MCP removes the extra step between a question and an answer: you ask in words, the agent builds the query itself. All you need is a server for your database engine and a connection string. Download Doka for free.