046 · Databases
Databases the agents can query: PostgreSQL, AlloyDB, SQLite (with sqlite-vec) and BigQuery, served inside Blitz by MCP Toolbox for Databases, read-only unless the user says otherwise (spec_046_databases)
| Status | Done in v0.8.0 (the owner’s request, 2026-10-19): DB-01–DB-18. Since 2026-10-20 databases are the first category of connectors: their kinds are descriptors and Toolbox is a backend. |
| Source | third_party/mcp-toolbox/ (the pruned Toolbox, embed/embed.go, patches/, tools/update_toolbox.sh), pkg/engine/databases/ (the toolbox backend: databases.go, connection.go, session.go), pkg/engine/connectors/builtin/ (the Databases category and its kinds), pkg/engine/connectors.go, pkg/engine/tools/mcp.go (RegisterInProcess, ReadOnlyTools), pkg/engine/extensions.go (applyMCP), pkg/engine/settingswatch.go, pkg/service/server/connectors.go, apps/desktop/web/src/studio/ConnectorsPane.tsx, apps/desktop/web/src/studio/connectorForm.ts |
| Tests | third_party/mcp-toolbox/embed/embed_test.go (TestPostgresReadOnly against a real PostgreSQL when BLITZ_TEST_POSTGRES is set), pkg/engine/databases/*_test.go, pkg/engine/connectors_test.go, pkg/engine/tools/mcpinproc_test.go, pkg/service/server/connectors_test.go, apps/desktop/web/src/studio/connectorForm.test.ts |
| Depends on | spec_047_connectors (the descriptors, the backend interface, trust, the query builder), spec_009_mcp (MCP servers, approvals), spec_039_secrets (passwords), spec_040_studio |
An agent that can read the team’s data answers questions no file in the repository can: how many orders failed last night, which customers churned, what the schema looks like before a migration. MCP Toolbox for Databases (Google, Apache-2.0, written in Go) already turns a database into MCP tools, with connection pooling, parameterised queries and a read-only model. Blitz runs it inside its own process, not as a program to install, and puts a form in front of it, so connecting a database is a few fields in Studio. Reading is the default, enforced by the database itself, so an agent can explore without the risk of changing anything.
- DB-01
third_party/mcp-toolboxis a pruned copy of Toolbox (v1.14.0,VERSION): its core (third_party/mcp-toolbox/internal/server, its sources, tools and utilities), the PostgreSQL, AlloyDB, SQLite and BigQuery sources and their tools, and its config parser (third_party/mcp-toolbox/embed/config.go, from Toolbox’s cmd/internal), under Blitz’s module path so the embed package can import its internal packages. Toolbox’s command line isn’t used: its signal handling, its version check (a call home) and its global OpenTelemetry setup would act on Blitz’s process.tools/update_toolbox.sh [version]refreshes the copy from the release’s module and appliespatches/*.patchin order; thenbazel run //:gazelle. nogo skipsthird_party/mcp-toolbox/internal(upstream code). - DB-02 Blitz’s patches: (01) SQLite through
ncruces/go-sqlite3with sqlite-vec (vec0tables, nearest-neighbour queries; wazero with threads) andreadOnly(the file openedmode=ro); (02) PostgreSQL and AlloyDBreadOnly: every sessiondefault_transaction_read_only=on, andexecute_sqlruns in a read-only transaction rolled back after, so neitherBEGIN READ WRITEnorSET default_transaction_read_only = offgets a write through; (03) no Cloud SQL; (04)${NAME}filled only from the values Blitz gives, never the process’s environment; (05) the stdio server doesn’t panic when its session closes; (06) closing the server closes its sources’ pools and stops BigQuery’s client caches (Toolbox never did, so each restart leaked connections). - DB-02 2026-11-07 (the owner: connecting to a SQLite database crashed the service, in the signed v0.9.4 app; macOS’s report:
SIGKILL (Code Signature Invalid)). wazero compiles SQLite’s WebAssembly to machine code it writes and then makes executable (mprotect, noMAP_JIT), which the hardened runtime forbids, so a signedblitzdwas killed the first time it opened a SQLite file.sign_macos.shsignsblitzdandblitzwithentitlements_go.plist(com.apple.security.cs.allow-unsigned-executable-memory, nothing else); the tray doesn’t open SQLite and keeps none. Reproduced with the embed package’s SQLite tests signed with the hardened runtime: killed (exit 137) without it, passing with it. - DB-03
embed.Load(files, values)reads and merges Toolbox YAML files;embed.Startinitialises the sources (connecting to each: a database that can’t be reached is the error) and serves the tools as MCP over an in-memory pipe (Session, closed once). A custom SQL tool with no annotations whose statement only reads (ReadsOnly: it starts with SELECT, WITH, EXPLAIN, SHOW, PRAGMA, VALUES, DESCRIBE or TABLE and has no word that writes) is markedreadOnlyHint, since Toolbox otherwise takes it for a write and hides it on a read-only source.ReadOnlySourcesandReadOnlyToolsname the sources that can’t write (SQLite, PostgreSQL and AlloyDB withreadOnly, BigQuery withwriteMode: blockedorreadOnly) and the tools on them. - DB-19 2026-11-05 (scan N26-pkg-small-2#18:
SELECT setval(…),SELECT pg_terminate_backend(…)andPRAGMA x = 1counted as reads, and Studio showed them so).ReadsOnlyalso counts as writing a call to a function that writes or acts (setval,nextval,pg_terminate_backend,pg_cancel_backend,pg_reload_conf,lo_*,dblink_exec,set_config, advisory locks, …) and a PRAGMA that sets a value. It’s still a hint: a read-only source is the guard.
- DB-04 A workspace’s database files are the global ones (
~/.blitz/connectors/databases/*.yaml,*.yml) and its own (.agents/connectors/databases/), merged into one MCP server, databases (the category’sserver), run in-process by the toolbox backend (MCPServerConfig.InProcesstoolbox,tools.RegisterInProcess): its tools are nameddb__<tool>and offered to every agent. A user’s own MCP server nameddatabaseswins, with a warning. With no files there’s no server. - DB-05 A
${NAME}in a file is the Blitz secretNAME(the workspace’s own, else the global one; spec_039_secrets), never an environment variable; its value is remembered for every redactor to mask. A workspace file the person hasn’t trusted gets only the workspace’s own (spec_047_connectors CON-09). - DB-05 2026-11-05 (scan N26-engine-sub-1#19). An untrusted file’s
${NAME}s are filled from the workspace’s own secrets even when a trusted or global file served with it names the same secret (spec_047_connectors CON-09). - DB-20 2026-11-05 (scan N26-pkg-small-2#10: the value was put into the file’s text before it was parsed, so a password with
#was cut short, one with:broke the file and one with a newline could add keys). A${NAME}is filled in the parsed YAML’s values, which are then written again (patch 09,parseEnv): a value’s own YAML syntax stays inside it, a placeholder in a comment is left alone, a quoted placeholder stays a string and an unquoted one that’s the whole value reads as its value would (port: ${PORT}a number). Studio writes a secret quoted (password: "${DB_SHOP_PASSWORD}"). - DB-06 The server connects when its tools are first listed, like any MCP server (spec_009_mcp), and gives up after the listing’s timeout; its state (idle, connected, failed with why) is in
/mcpand Studio. Its target readsin-process: <files>. - DB-07 Tools on a read-only source run without asking (
MCPServerConfig.ReadOnlyTools;Lookupreports them as auto-approved): the database refuses any write, whatever the agent sends. Every other database tool asks first, as MCP tools do, and so does every tool of a workspace file the person hasn’t trusted (CON-09). - DB-21 2026-11-13 (the owner, by voice: the recipes database was connected, yet every query asked to run
sqlite3in the shell). SQLite’sexecute_sqlwas marked as writing, so a read-only connection (the default, DB-12) offered onlylist_tables, and the agent read the rows through the shell, asking each time. It’s offered on a read-only file as PostgreSQL’s is (patch 10 marks it read-only there; the file openedmode=rorefuses any write), so it runs unasked (DB-07). A read-only file Studio saved before this (no# tools: chosenline in its header) couldn’t have had it, so it gets it, with nothing to do: the tools its kind marksaddToOlderare added as the file is read, for the agents and in Studio alike, and the file on disk is left as it is until it’s next saved. A file written by hand, one that can write, and one saved since keep the tools they list.execute_sql’s description tells the agent to use it rather than the database’s shell client (sqlite3,psql,bq). - DB-21a 2026-11-21 (security review of the code since v0.9.1, databases#1:
mode=rocovered the main file only, soATTACHof the same file letexecute_sqldelete from it, andVACUUM INTOwrote a copy anywhere). A read-only SQLite source’s connection has no attached databases (LIMIT_ATTACHED0), an authorizer refusingATTACHandDETACH, andquery_onlyon. - DB-21b 2026-11-21 (security review databases#3:
SELECT randomblob(900000000)over a few rows took the service’s memory). A read-only SQLite connection makes no value over 16 MB (LIMIT_LENGTH), and a query keeps rows up to 32 MB in all, the last row saying the rest were left out. - DB-21c 2026-11-21 (security review databases#2:
WITH … REPLACE INTO,SELECT … INTO new_tandPRAGMA user_version(7)passed as reading). Reading only means nointoeither (REPLACE INTO, SELECT INTO), and a PRAGMA’s call form is a write but for those that only read (table_info,index_list,integrity_checkand the like); Studio’s copy (studio/connectorForm.ts) is changed with it, on the same cases. - DB-22 2026-11-14 (the owner’s BigQuery connection on blitz-dev: “Invalid project ID ‘retail-cortex.’” came only when a query ran, and with allowed datasets “Tables” found none). A BigQuery connection is checked as it’s saved: its project must be a Google Cloud project ID (domain-scoped ones too; a
${NAME}is checked where it’s filled), each allowed dataset a dataset’s name (the connection’s project’s) orproject.dataset(another’s). Its tables, with allowed datasets, which Toolbox lists whole asproject.dataset, are read each in its own project, another project’s named in full (bigquery-public-data.thelook_ecommerce.users). A query opened for one statement gets the user agent BigQuery’s client needs, as the served tools do. - DB-08 The settings watch (every 2 s) notices database files added, changed or removed, and restarts the server (
ReloadConnectors, CON-08); so does saving or deleting one in Studio. MCP reloads are applied one at a time (applyMCP,mcpMu).
- DB-09 A connection is one file,
<name>.yaml: one source named<name>with the ready-made tools switched on (<name>_execute_sql,<name>_list_tables…) and the custom queries (<name>_<query>), so tool names never collide between files.databases.Parsereads a file into the form; one with more than the form describes (other sources or tool types, toolsets, unknown settings) is custom, listed and edited as YAML. A connection’s description is kept in a# about:comment (Toolbox’s sources take no description field) and goes into its tools’ descriptions. - DB-10 The kinds (descriptors in
pkg/engine/connectors/builtin/kinds/, spec_047_connectors CON-01; each with every capability, and its schema read as CON-05 says): PostgreSQL (host, port, database, user, password; toolsexecute_sql,list_tables,list_schemas,list_views,list_indexes,database_overview); AlloyDB (project, region, cluster, instance, IP type, database, user and password or IAM; the PostgreSQL tools); SQLite (the file;execute_sqlandlist_tables); BigQuery (project, location, datasets, most bytes billed;execute_sql,list_datasets,list_tables,table_info,dataset_info). Google Cloud kinds sign in with Application Default Credentials. - DB-11 A password is never in the file: saving keeps the value typed as the secret
DB_<NAME>_PASSWORD(the category’ssecretPrefix, CON-07) in the connection’s scope and writes${DB_<NAME>_PASSWORD}. A rename moves the secret; deleting a connection deletes its secrets. A required password with no value kept or typed is a problem. - DB-12 New connections are read-only. Custom queries take parameters (string, integer, float, boolean) and say whether they only read.
- DB-13 The connector RPCs (spec_047_connectors CON-10):
ListConnectors,SaveConnector(CONNECTOR_NOT_FOUNDfor a previous name that isn’t there),DeleteConnector,TestConnector(connects to the form as it is, unsaved, and lists its tools: which run unasked; a problem says why it couldn’t connect, redacted),TryConnectorTool(runs one tool of the form as it is, with JSON arguments),ReadConnectorSchemaandDraftConnectorQuery. - DB-14 Studio › Connectors › Databases (
ConnectorsPane, spec_047_connectors CON-11), after Workflows with Secrets (what the agent reaches; spec_040_studio STU-02): the server’s state, then the connections, this workspace’s and every workspace’s, each with its kind, where it is, read-only or not, its tool count and description. A connection’s form slides in over the list: name and description, the folder it’s kept in (Studio’s are the workspace’s; every workspace’s are changed in Settings › Connectors, CON-18), the kind, its settings (a kept password shown as kept, typed to replace), Read-only with what it means for the kind, the ready-made tools (one that writes is marked as not offered while read-only), and Your queries, each with its SQL, parameters (drafted from$1or@namewhen the SQL is first written) and Try it, and Write a query, the query builder (CON-12). Test the connection lists the tools the agents would get. Delete, Revert, Cancel and Save as in the other kinds; unsaved changes are asked about. - DB-15 The strings are in English, Spanish and French.
- DB-16 The leak checks of the test binaries that link Toolbox ignore opencensus’s stats worker, which its package’s
initstarts for the process. - DB-17 2026-10-20 (the owner’s question: can
./kitchen.dbwork?). A setting its kind marks as a path (type: path: SQLite’sdatabase) is kept in the file as written, so a committed file means the same on every machine, and resolved only when Blitz connects (connectors.ResolvePath;databases/paths.go, throughembed.LoadWith, which gives each file’s text to a rewrite before Toolbox parses it;Serveworks out which settings are paths from the workspace’s catalog, its own kinds too, and hands them to the transport asMCPServerConfig.FileSettings): a relative one against the workspace’s folder for a workspace connection (<workspace>/.agents/connectors/<category>/), the home folder for a global one,~/as the home folder;:memory:, afile:URI and a${NAME}are left as they are. Studio’s Test, Try it and Read the tables resolve it the same way, by the connection’s scope. A path naming no file is the connection’s problem (no file at …), read-only or not: SQLite would otherwise make an empty database where the service runs. Make global (spec_047_connectors CON-19) writes a relative path as the full one it named, so it still names that file. Only the built-in format Studio writes (akind: sourcedocument a source) is resolved; Toolbox’s older nested format is read as it is. - DB-18 2026-10-20 (a leak review). Toolbox closes what it opened when a start fails part-way (patch 07:
InitializeConfigsandNewServerclose the sources open so far on any later error, a source’s, a tool’s or the server’s; BigQuery closes its client and caches on its own early errors), so a failing Test or a reconnect with one database down doesn’t leak the others’ pools, files and goroutines. A SQLite query returns at mostMaxRows(1000) rows, the last saying so (patch 08), rather than loading a whole table. The secret values typed into Studio’s form, unsaved, are masked in what a test or try answers, not remembered for the process’s life. The patches are listed inthird_party/mcp-toolbox/README.md.
- Choosing which agents get a connection (every agent does).
- A guardrail that reads SQL before a write runs; until then a writable database’s tools ask first.
- MySQL, Spanner, Cloud SQL and the other databases Toolbox supports: each is a source and its tools added to the copy (
tools/update_toolbox.sh) and a kind descriptor (CON-15).