Let an agent use a database
An agent connected over MCP uses the same connections, consoles and schema tools as you do, but only with the permissions you grant it for each connection. Nothing is granted by default, reading included, and nothing in the project can grant it. Per-connection permissions for agents: Works.
How to connect an agent at all is in Get started and How an agent’s call is checked; this page is about databases.
The four permissions
Section titled “The four permissions”| Permission | Allows | Statements |
|---|---|---|
read-schema |
reading the structure | the schema tools, completion, inspections, DDL, plans without Analyze |
read-data |
reading rows | SELECT, VALUES, TABLE, SHOW, EXPLAIN, DESCRIBE, WITH without changes, and transaction control |
modify-data |
changing rows | INSERT, UPDATE, DELETE, MERGE, REPLACE, COPY, CALL, EXEC, DO, LOCK, EXPLAIN ANALYZE, WITH that changes rows |
modify-schema |
changing structure | CREATE, ALTER, DROP, TRUNCATE, RENAME, GRANT, REVOKE, COMMENT, VACUUM, ATTACH, PRAGMA … =, and anything not recognized |
Every statement of a script is classified on its own, and the call needs the permission of each.
For agents the rules are stricter than for you: INTO anywhere outside a string, and functions that
write or reach out (setval, nextval, set_config, pg_read_file, dblink, load_extension
and others) count as modify-schema. A statement that cannot be read counts as modify-schema too.
- The agent calls run_sqlWith a connection id and SQL; apply is false unless the agent sets it.
- The project is trusted?In safe mode every tool that names a connection is refused before connecting.If not: Refused: safe mode.
- The project file allows it?The connection’s ai line in .ferris-idea/connections.toml is a ceiling; without it, reading only. Read-only connections never modify.If not: Refused without asking: the project file or read-only.
- You granted it?Each statement’s permission must be in your agent-permissions.toml for this exact connection target.If not: Over HTTP with the window open you are asked: Deny, Allow Once, Always for This Connection. Otherwise refused with the entry to add.
- Preview or runReading runs at once in a read-only session. Anything else is returned as a preview until the call says apply: true.
- One log lineEvery call that uses a connection writes one line to .ferris-idea/agent-log.jsonl.The line holds the permissions, the result and lengths, never the SQL, a value or the host.
Grant a permission
Section titled “Grant a permission”There are two ways, both yours:
-
Answer the window. When an agent calls over HTTP while the Ferris IDEA window is open, the window asks with Deny (the default), Allow Once and Always for This Connection. The question waits two minutes; no answer is a refusal. Deny refuses that agent’s later calls of the session without asking again.
-
Edit the grant file. Add an entry to
agent-permissions.tomlin your settings folder (~/.config/ferris-idea/unlessFERRIS_IDEA_CONFIG_DIRorXDG_CONFIG_HOMEsays otherwise). A refused call names the exact entry to add, for example:[[connection]]workspace = "~/Projects/corner-shop"connection = "shop"target = "sqlite:shop.db#9fef824b5cac0e97"allow = ["read-schema", "read-data"]
target is the connection’s URL without a password, followed by a fingerprint of everything that
decides where the connection goes: system, host, port, database, user, file, TLS mode and files,
keychain entry, SSH tunnel and startup script. Change any of them and the grant stops applying, so
a grant for your local test database never carries over to a server the project file was pointed
at later.
The grant file is read on every call. An unknown permission name makes the whole file grant nothing, a grant file inside a project is ignored, and no MCP tool writes it. To take a grant back, delete its entry; there is no dialog for it yet.
Set a ceiling in the project
Section titled “Set a ceiling in the project”The project may limit, never extend, what agents get. A connection’s ai line in
.ferris-idea/connections.toml names the most an agent can be granted:
[[connection]]id = "shop"# …ai = ["read-schema", "read-data", "modify-data"]Without an ai line the ceiling is read-schema and read-data. Read-only on a connection
takes both modify permissions away. A call beyond the ceiling is refused without asking you, and
the message says that only you can change the line.
See what would run before it runs
Section titled “See what would run before it runs”A script that only reads runs at once, in a read-only session, with at most 100 rows back by
default (max_rows up to 10,000). Any script with a statement that could change something connects
to nothing until the call says apply: true: the answer lists each statement with its position,
the permission it needs and what it changes, and applied: false.
The same rule holds for edit_table_data, copy_table, rename_sql_object,
change_column_type and run_store_command. explain_sql runs the statement only with
analyze: true, and then needs the statement’s own permission. An UPDATE or DELETE without
WHERE is refused unless the call also says confirm_unsafe.
Where agents cannot reach
Section titled “Where agents cannot reach”- Files outside the project. A SQLite or DuckDB file must lie inside the workspace (links
resolved), unless the grant names exactly that target. SQLite
ATTACHis allowed only for an existing file inside the workspace,VACUUM INTOis refused, and DuckDB sessions of agents open with external access off. - Other keychain entries. The project file may only name Ferris IDEA’s own entry for the
connection (
ferris-idea/connection:<id>); anything else is refused. - Tunnels without the
sshright. A connection with an SSH tunnel also needs the workspace rightssh. - Passwords. No tool returns a password.
save_connectiontakes none; you type it in the window.
Read the log
Section titled “Read the log”Every call that uses a connection writes one line to .ferris-idea/agent-log.jsonl in the project,
refused calls and previews included:
{"time":1794642664,"tool":"run_sql","call":true,"changes":["database"],"dry_run":false,"rights":[],"database":[{"connection":"shop","permissions":["modify-data"],"dry_run":false,"ok":false,"refused":"project-file","chars":73,"kinds":["modify-data"]}],"targets":{"connection":"shop","apply":true},"lengths":{"sql":73},"result":"refused"}refused says why: not-granted, denied, safe-mode, project-file, read-only or
keychain. The line never contains the SQL text, a value or the connection’s address. If the log
cannot be written, the call is refused.
When it does not work
Section titled “When it does not work”- “not granted: nothing was run”: the permission is not in your grant file for this target. Add the entry the message shows, or call over HTTP with the window open to be asked.
- “the project file … allows agents at most …”: the
ailine is the ceiling. Change it yourself if you want to allow more, then grant the permission. - A grant that worked yesterday is refused: something in the connection changed (host, user, file, tunnel), so the fingerprint no longer matches. Grant it again for the new target.
list_connectionsshowsusable: false: the project is in safe mode. Trust it first.
For agents
Section titled “For agents”add_idea_data_sourceAdd a data source from the reference IDE's.idea/dataSources.xml(as idea_project lists it) as a workspace connection, picked byname.browse_storeBrowse a MongoDB or Redis store like the Database tool window: path [] lists databases; MongoDB [db] collections and views with estimated counts, [db, coll] the groups indexes and fields, [db, coll, "indexes"] indexes, [db, coll, "fields"] field paths sampled from up to 100 documents with their types; Redis [db] keys grouped by:and [db, "prefix:"] the keys under a group, with type and TTL, read with SCAN pages of 500 (never KEYS): a non-zero cursor means more, pass it back.cancel_sqlCancel the run_sql call that is running on a connection: PostgreSQL's cancel request, MySQL/MariaDB KILL QUERY, SQLite interrupt.change_column_typeChange a column's type: the statement in the connection's dialect, keeping NOT NULL and the default where the dialect restates the column (MySQL, MariaDB, SQL Server); refused for views and SQLite.compare_schemasCompare the schemas of two connections of one dialect, or two schemas of one connection (source_schema/target_schema; PostgreSQL, DuckDB, MySQL, MariaDB): differences in tables, columns, keys, indexes, foreign keys and views, and the statements that turn the target into the source in dependency order.complete_sqlComplete SQL at a cursor position using the connection's schema: tables after FROM/JOIN, after JOIN also ready join clauses (kindjoin) built from foreign keys to the tables already in the statement, columns of referenced tables or aliases, keywords (needs the read-schema permission).copy_tableCopy a table to another schema or name, keeping primary key, unique constraints, NOT NULL, defaults and CHECK constraints by default (foreign keys only with foreign_keys=true), and its rows.database_problem_reportBuild the text of a problem report about a database system for the user to review: Ferris IDEA version, system, status, family, the failing step and error message, with passwords, user names and (unless include_hosts) host, port, database and IP addresses replaced by placeholders.describe_tableDescribe a table or view: columns (type, nullable, default), primary key, foreign keys and indexes, in the current schema or one from list_schemas.edit_table_dataEdit rows of a table: update cells, insert and delete rows.er_diagramEntity-relationship diagram of a connection's tables and views: columns with PK/FK/UK marks, foreign keys with cardinality, what views use, and foreign keys leaving the selection.explain_sqlShow the execution plan of one statement as a tree (operation, table/index, conditions, estimated rows and cost; with analyze=true also actual rows, time and loops) plus hints such as full scans of big tables and misestimates.export_connectionA workspace connection as a .idcsources file to share: no keychain reference, no agent permissions, no absolute file path, the user name only with include_user; lists what was left out.export_connectorThe definition of a database system to share as a .idcconnector text in the exchange layout of ADR-0021: a file already in it unchanged; others with the [ferris-idea] envelope and without status and tested, so a shared copy never claims to be tested.export_dataExport all rows of one reading statement as csv (NULL = empty field, empty string = ""), tsv (NULL = \N), psv, json, markdown (numeric columns right-aligned), html, xml, sql-insert or sql-update (need table; sql-update uses key, default the first column) or where-clause.export_store_resultExport a MongoDB find/aggregate result (all pages) or Redis keys (names one per line; values read by type and bounded) as JSON, JSON Lines or CSV into a workspace file.generate_ddlGenerate the CREATE script (tables, primary keys, indexes, foreign keys) of a connection's schema or of selected tables; nothing is run (needs the read-schema permission).import_connectorImport a database system definition fromtext, a filepathor an httpsurlinto the user's connectors folder.inspect_sqlInspect SQL against the connection's schema: unknown tables and columns, UPDATE/DELETE without WHERE, MySQL column-level REFERENCES that create no foreign key (needs the read-schema permission).list_connectionsList the workspace's database connections (.ferris-idea/connections.toml) with URLs; passwords are never included.list_connectorsList every database system Ferris IDEA can connect to: id, name, family, category, status, note, URL schemes, default port and origin; plus unusable connector files with their problems.list_schemasList the non-system schemas of a connection's database, the current one marked (needs the read-schema permission).list_storesList the workspace's non-relational stores (MongoDB, Redis; .ferris-idea/stores.toml, SPEC-0310): id, name, system, family, URL without password, read_only, whether a keychain password is set, and the agent rights as for list_connections:aiis what the user granted for this workspace, store and target (nothing by default),requestedthe most the project file allows,targetwhat the store reaches,usablefalse in safe mode.list_tablesList the tables and views of a connection's current schema, or of another schema from list_schemas.object_definitionThe definition of a function, procedure, aggregate, trigger or type as the database states it: PostgreSQL pg_get_functiondef and pg_get_triggerdef, aggregates and types (enum, domain, range, composite) written from the catalogue; MySQL and MariaDB SHOW CREATE FUNCTION/PROCEDURE/TRIGGER; SQLite the stored CREATE TRIGGER.object_docQuick documentation of a table, view or column, as F1 / Ctrl+J in the Database tool window shows it: the kind and place, the columns with types, keys, NOT NULL and defaults, foreign keys, the tables that reference it and indexes; for a column its type, default, keys and indexes.read_table_dataRead one page of a table like the table data editor: optionalwhereandorder_byclause bodies (refused when they contain;or a comment),page(0-based, 500 rows).remove_connectionRemove a database connection of the workspace and its password in the system keychain, as Delete in the Database tool window does.rename_sql_objectRename a table, view, column, index, routine, sequence or constraint: returns the statement in the connection's dialect and edits for every SQL reference in the given text or the project's .sql files.run_sqlRun SQL on a workspace connection.run_store_commandRun a console command on a MongoDB or Redis store.save_connectionAdd or change a workspace database connection as the connection dialog does: server or SQLite/DuckDB file, user, SSL (new default verify-full), read-only, SSH tunnel (strict host keys, local end on 127.0.0.1), TLS files and options; omitted fields of a changed connection are kept.save_storeAdd or change a non-relational store (MongoDB or Redis) from a name and a URL (mongodb://, mongodb+srv://, redis://, rediss://).schema_objectsThe kinds of objects a schema of a connection can hold, each with its count, and its objects besides tables and views: sequences, functions, procedures and aggregates (PostgreSQL with their arguments, so overloads differ), triggers with their table and when they fire, and types (enum, domain, range, composite) — PostgreSQL; functions, procedures and triggers on MySQL, also sequences on MariaDB; triggers on SQLite; sequences on DuckDB, Oracle and SQL Server.split_sql_statementsSplit an SQL script into statements with byte ranges, using the lexical rules of the dialect.sql_consoleCreate a new SQL console for a connection (a file under .ferris-idea/consoles/<connection id>/ bound to it, starting in the data source's default schema); returns its path and schema (needs the read-schema permission).sql_file_data_sourceReport or set the connection a .sql file runs against: consoles belong to their connection, other files can be bound (kept in .ferris-idea/sql-files.toml).sql_historyThe query history of a connection: the statements its consoles in the window ran, newest first, with time (seconds since 1970) and whether they succeeded.sql_refactorings_atWhat the SQL editor's refactorings find at a caret:objectis the table or column named there ({table, column}) as ⇧F6 would rename it, orobject_errorwith the reason (unknown, an alias, a column of several tables);expand_wildcardis the edit and the resulting SQL of "Expand column list" when the caret is on a*of a select list, else null;inlineis {name, edits, sql} of Inline on the WITH query named at the caret, elseinline_errorsays why (recursive, column list, MATERIALIZED, written to, unused, no WITH query) or both are null on no name.table_ddlThe definition of one table or view as SQL, as the Database tool window's Show DDL tab has it: CREATE TABLE with columns, types, NOT NULL, defaults, primary key and foreign keys, then its indexes; for a view CREATE VIEW with its stored query.test_connectionTest a workspace database connection: connect with its stored password and run SELECT 1 read-only.validate_connectorCheck a database system definition (SPEC-0300 format, TOML) without storing it: every problem with its key path, the parsed summary and every SQL text it would run.
No tool matches. Try fewer words, or .