Spanish Total.js
English
Documentation For AI agents
Contents

Connect an AI

TotalSQL has an MCP server, so an assistant on your computer can look at the database that you have in view and, if you allow it, propose changes that you confirm.

.md GitHub
On this page

Turn it on

  1. Press AI.
  2. Turn on Let AI clients connect.
  3. Copy what your client needs. The dialog has it ready for Claude Code, for Claude Desktop, and for Cursor and other MCP clients.

The address is http://127.0.0.1:7240/mcp. If that port is in use, TotalSQL takes the next free one, up to 7249, and the dialog has the right address.

The server is off until you turn it on. It listens only on this computer, and only while TotalSQL is open. It asks for a token, which is kept in the secure store of your system. With New token…, the clients that have the old one stop working until you give them the new one.

Whoever has the token can read the database that you have in view. Give it only to your AI clients.

What it can see

The assistant works with the connection in view, and follows you when you go to another. It sees no other connection, and never your passwords. When you are in the list of connections, it has no database.

What it reads goes to the assistant, and to the company behind it if it does not run on your computer.

The tools

ToolWhat it does
Database_infoThe kind, the version, the environment and the care level
Tables_listThe tables and views, with their estimated rows
Table_describeThe structure of a table
Table_rowsUp to 200 rows of a table, with filters
Objects_listFunctions, sequences, triggers and the rest
Object_definitionThe SQL that makes one of them
Query_runRuns SQL, and gives up to 200 rows for each statement

Changes

At first, only statements that read run. To let the assistant propose others, turn on Let it propose changes. Then each request that changes data or structure opens An AI assistant wants to run this, with its statements. Press Run or Do not run. Closing the dialog is a no, and so is leaving it for three minutes.

It asks with any care level, and a read-only connection still refuses. A SELECT that changes data by a function it calls counts as a change too. In PostgreSQL, MySQL, MariaDB and SQLite the database itself refuses it until you say yes. In MySQL and MariaDB, while you have a transaction open or tables locked in the connection, the assistant cannot read: end it, or free them, first.

What assistants did has the last calls since you opened TotalSQL. The statements also go to the History of the connection.

Code mode

For work of several steps, the assistant can write one script instead of calling the tools one by one, and only its result goes back to the model. Download the client, which needs Node.js 18 or newer:

curl -H 'Authorization: Bearer YOUR_TOKEN' 'http://127.0.0.1:7240/mcp/client.js' -o totalsql.js

It has a function for each tool:

const api = require('./totalsql.js')('YOUR_TOKEN');

(async function() {
    const tables = await api.Tables_list();
    const result = await api.Query_run({ sql: 'SELECT count(*) FROM orders' });
    console.log(tables.schemas.length, result.statements[0].rows);
})();

A function that fails throws an error with the message of TotalSQL. The dialog has this code with your address and your token.

Made in Europe