跳转到内容

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.

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.

  1. The agent calls run_sqlWith a connection id and SQL; apply is false unless the agent sets it.
  2. The project is trusted?In safe mode every tool that names a connection is refused before connecting.If not: Refused: safe mode.
  3. 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.
  4. 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.
  5. Preview or runReading runs at once in a read-only session. Anything else is returned as a preview until the call says apply: true.
  6. 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.
The same checks apply to every database tool, not only run_sql.

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.toml in your settings folder (~/.config/ferris-idea/ unless FERRIS_IDEA_CONFIG_DIR or XDG_CONFIG_HOME says 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.

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.

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.

  • Files outside the project. A SQLite or DuckDB file must lie inside the workspace (links resolved), unless the grant names exactly that target. SQLite ATTACH is allowed only for an existing file inside the workspace, VACUUM INTO is 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 ssh right. A connection with an SSH tunnel also needs the workspace right ssh.
  • Passwords. No tool returns a password. save_connection takes none; you type it in the window.

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.

  • “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 ai line 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_connections shows usable: false: the project is in safe mode. Trust it first.

  • add_idea_data_sourcechangesdry run by defaultwriteAdd a data source from the reference IDE's .idea/dataSources.xml (as idea_project lists it) as a workspace connection, picked by name.
  • browse_storereadsdatabase-permissiontrusted-projectBrowse 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_sqlchangessshdatabase-permissiontrusted-projectCancel the run_sql call that is running on a connection: PostgreSQL's cancel request, MySQL/MariaDB KILL QUERY, SQLite interrupt.
  • change_column_typechangesdry run by defaultsshdatabase-permissiontrusted-projectChange 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_schemasreadssshdatabase-permissiontrusted-projectCompare 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_sqlreadssshdatabase-permissiontrusted-projectComplete SQL at a cursor position using the connection's schema: tables after FROM/JOIN, after JOIN also ready join clauses (kind join) built from foreign keys to the tables already in the statement, columns of referenced tables or aliases, keywords (needs the read-schema permission).
  • copy_tablechangesdry run by defaultsshdatabase-permissiontrusted-projectCopy 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_reportreadsBuild 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_tablereadssshdatabase-permissiontrusted-projectDescribe 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_datachangesdry run by defaultsshdatabase-permissiontrusted-projectEdit rows of a table: update cells, insert and delete rows.
  • er_diagramchangessshwritedatabase-permissiontrusted-projectEntity-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_sqlchangessshdatabase-permissiontrusted-projectShow 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_connectionreadsA 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_connectorreadsThe 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_datareadssshdatabase-permissiontrusted-projectExport 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_resultchangeswritedatabase-permissiontrusted-projectExport 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_ddlreadssshdatabase-permissiontrusted-projectGenerate 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_connectorchangesdry run by defaulthttpsettingsImport a database system definition from text, a file path or an https url into the user's connectors folder.
  • inspect_sqlreadssshdatabase-permissiontrusted-projectInspect 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_connectionsreadsList the workspace's database connections (.ferris-idea/connections.toml) with URLs; passwords are never included.
  • list_connectorsreadsList 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_schemasreadssshdatabase-permissiontrusted-projectList the non-system schemas of a connection's database, the current one marked (needs the read-schema permission).
  • list_storesreadsList 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: ai is what the user granted for this workspace, store and target (nothing by default), requested the most the project file allows, target what the store reaches, usable false in safe mode.
  • list_tablesreadssshdatabase-permissiontrusted-projectList the tables and views of a connection's current schema, or of another schema from list_schemas.
  • object_definitionreadssshdatabase-permissiontrusted-projectThe 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_docreadssshdatabase-permissiontrusted-projectQuick 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_datareadssshdatabase-permissiontrusted-projectRead one page of a table like the table data editor: optional where and order_by clause bodies (refused when they contain ; or a comment), page (0-based, 500 rows).
  • remove_connectionchangeswriteRemove a database connection of the workspace and its password in the system keychain, as Delete in the Database tool window does.
  • rename_sql_objectchangesdry run by defaultsshwritedatabase-permissiontrusted-projectRename 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_sqlchangesdry run by defaultsshdatabase-permissiontrusted-projectRun SQL on a workspace connection.
  • run_store_commandchangesdry run by defaultdatabase-permissiontrusted-projectRun a console command on a MongoDB or Redis store.
  • save_connectionchangesdry run by defaultwriteAdd 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_storechangesdry run by defaultwriteAdd or change a non-relational store (MongoDB or Redis) from a name and a URL (mongodb://, mongodb+srv://, redis://, rediss://).
  • schema_objectsreadssshdatabase-permissiontrusted-projectThe 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_statementsreadsSplit an SQL script into statements with byte ranges, using the lexical rules of the dialect.
  • sql_consolechangessshwritedatabase-permissiontrusted-projectCreate 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_sourcechangeswritetrusted-projectReport 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_historyreadssshdatabase-permissiontrusted-projectThe 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_atreadssshdatabase-permissiontrusted-projectWhat the SQL editor's refactorings find at a caret: object is the table or column named there ({table, column}) as ⇧F6 would rename it, or object_error with the reason (unknown, an alias, a column of several tables); expand_wildcard is the edit and the resulting SQL of "Expand column list" when the caret is on a * of a select list, else null; inline is {name, edits, sql} of Inline on the WITH query named at the caret, else inline_error says why (recursive, column list, MATERIALIZED, written to, unused, no WITH query) or both are null on no name.
  • table_ddlreadssshdatabase-permissiontrusted-projectThe 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_connectionreadssshdatabase-permissiontrusted-projectTest a workspace database connection: connect with its stored password and run SELECT 1 read-only.
  • validate_connectorreadsCheck 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.