
mcp
io.github.stoolap/mcp
Query, manage and search a Stoolap embedded SQL database (Rust): SQL, transactions, vector search.
Documentation
stoolap-mcp
An MCP (Model Context Protocol) server for Stoolap, an embedded SQL database written in Rust. It lets an AI assistant inspect a schema, run queries, write data inside transactions, read query plans and check the health of a database file.
It works with any MCP client that speaks stdio: Claude Desktop, Claude Code, Cursor, Windsurf, Cline and others.
Version 0.5 of this server targets the Stoolap 0.5 engine through @stoolap/node 0.5.
Quick start
Claude Code
claude mcp add stoolap -- npx -y @stoolap/mcp --path ./mydata
Claude Desktop and other JSON-configured clients
On macOS the Claude Desktop file is ~/Library/Application Support/Claude/claude_desktop_config.json.
{
"mcpServers": {
"stoolap": {
"command": "npx",
"args": ["-y", "@stoolap/mcp", "--path", "./mydata"]
}
}
}
Leave out --path for an in-memory database that disappears when the server stops. Add "--read-only" to the arguments to let the assistant read but never write.
The first npx run compiles the small native addon of @stoolap/node. A client with a short startup timeout may report a failed connection on that first run; retry once the install has finished, or install the package globally first (npm install -g @stoolap/mcp).
Docker
docker build -t stoolap-mcp .
docker run -i --rm -v "$PWD/data:/data" stoolap-mcp --path /data/mydb
The server talks over stdio, so the container must run with -i.
Options
| Flag | Default | Description |
|---|---|---|
--path <path> | :memory: | Database path or DSN. Engine options go in the query string, e.g. ./mydata?sync_mode=full&checkpoint_interval=30. |
--read-only | off | Refuse every statement that writes data, schema or engine settings. Reads and read-only transactions still work. |
--max-rows <n> | 1000 | The most rows one call returns. Longer results come back cut, with truncated: true. A call can ask for fewer with max_rows, never for more. 0 removes the limit. |
--query-timeout <ms> | 30000 | Stop any statement that runs longer, with the error query cancelled. 0 turns it off. Without the flag, a query_timeout in the DSN is used instead of the default. |
--version | Print the server version and exit. |
Tools (14)
Every tool carries MCP annotations (readOnlyHint, destructiveHint), so a client can approve the read-only ones automatically.
SQL
| Tool | What it does |
|---|---|
query | Runs one read-only statement: SELECT, WITH ... SELECT, SHOW, DESCRIBE, EXPLAIN. |
execute | Runs one statement that writes: INSERT, UPDATE, DELETE, COPY, CREATE, ALTER, DROP, TRUNCATE, ANALYZE, VACUUM, SET. Returns {"affected_rows": n}, or rows when the statement has RETURNING. |
execute_batch | Runs one INSERT, UPDATE or DELETE once per parameter set, all or nothing: when one set fails, none of them stays applied, inside a transaction too. |
explain | Prints the plan of a statement (given without EXPLAIN), one step per line. With analyze: true it runs the statement and shows actual time, rows and the paths taken; this is refused for anything but reads. |
query and RETURNING return rows in one shape:
{"columns": ["id", "name"], "rows": [[1, "alice"], [2, "bob"]], "row_count": 2, "truncated": false}
Columns keep their order and duplicate names (SELECT a.id, b.id), and an empty result still lists its columns. VECTOR values are arrays of numbers, and the FLOAT values NaN, Infinity and -Infinity are the strings "NaN", "Infinity" and "-Infinity", because JSON has no way to write them.
Parameters are an array for $1, $2 or ? placeholders, or an object for :name placeholders. JSON and VECTOR values are passed as text.
Two limits come from the Node.js driver, and the instructions tell the assistant about both:
- INTEGER values travel as JavaScript numbers, which are exact only up to 2^53. A larger parameter is refused with a hint to pass it as a string, which the engine converts exactly; read large values with
CAST(x AS TEXT). - TIMESTAMP values come back as ISO 8601 strings to the millisecond.
CAST(ts AS TEXT)gives all nine digits.
Transactions
| Tool | What it does |
|---|---|
begin_transaction | Opens a transaction, read_committed (default) or snapshot. |
commit_transaction | Commits it. |
rollback_transaction | Rolls it back. |
savepoint | create, rollback_to or release a named savepoint. |
While a transaction is open, query, execute and execute_batch run inside it and see its uncommitted rows. There is one transaction at a time, on the server's single connection.
Schema
| Tool | What it does |
|---|---|
list_tables | The names of all tables and views. |
get_schema | CREATE TABLE for every table (or the one table or view named) with constraints and foreign keys, a line per secondary index, and CREATE VIEW for every view. |
Both leave out the _sys_table_stats and _sys_column_stats tables in which ANALYZE keeps optimizer statistics.
Engine
| Tool | What it does |
|---|---|
pragma | Reads or changes an engine setting, reads a report, or runs a maintenance action (see below). |
verify | Reads every column volume of a file database, checks each block's checksum, and reports each segment as ok, damaged, unreadable or failed. It changes nothing. |
list_functions | Every built-in SQL function with its signature and semantics, by category. |
version | Engine and server versions, the read-only flag, row limit and query timeout in effect, and the isolation level of the open transaction (null when none is open). |
pragma accepts these names:
- Settings (integer; omit the value to read):
checkpoint_interval,compact_threshold,target_volume_rows,keep_snapshots,hot_max_rows,hot_max_bytes,group_cache_mb,index_cache_mb,index_build_mb,query_timeout(milliseconds, this connection only). - Reports:
sync_mode,wal_flush_trigger,volume_stats,memory_stats,group_cache_stats,index_stats,index_read_stats.PRAGMA VERIFYis theverifytool. - Actions:
checkpoint,snapshot,vacuum,index_backfill(value: the most volumes to build),restore(value: a snapshot timestamp such as20260315-120000.000, the latest when omitted; it replaces all data).
Instructions, resources and prompt
The server sends MCP instructions when a client connects: which tool to use for what, the result shape, the SQL rules most likely to surprise (comparison of TEXT with numbers, overflow errors, strict name resolution, DDL in transactions) and what Stoolap does not support.
| URI or name | Content |
|---|---|
stoolap://schema | The live schema, as returned by get_schema. |
stoolap://sql-reference | The live schema plus the complete Stoolap 0.5 SQL reference and every function. |
sql-assistant (prompt) | The same content as stoolap://sql-reference, for clients that take prompts rather than resources. |
Safety
- Read-only mode. The Stoolap engine has no read-only open mode, so the server enforces it: in
--read-onlyevery statement that writes is refused before it reaches the engine, including COPY, DDL, SET, ANALYZE, VACUUM, EXPLAIN ANALYZE of anything but a read, and every pragma action and setting,query_timeoutincluded. - SQL is read the way the engine reads it. The checks tokenize SQL like the engine lexer: string escapes, quoted identifiers,
--,#and/* */comments, and every Unicode whitespace character. They judge the statement that is actually sent, after EXPLAIN [ANALYZE], and find the main verb of a WITH at its own depth. A NUL character or a byte order mark is refused. - One statement per call. The engine runs every statement of a multi-statement string and reports only the last, so a second statement is refused.
- Tool routing.
querytakes only reads andexecuteonly writes. Transaction control statements (BEGIN, COMMIT, ROLLBACK, SAVEPOINT, RELEASE) are refused in SQL and run only through the transaction tools, so the server always knows whether a transaction is open. - DDL inside a transaction. The engine rolls back a plain CREATE TABLE made in a transaction, but CREATE TABLE ... AS SELECT, ALTER TABLE, CREATE INDEX and CREATE VIEW persist after ROLLBACK, and DROP TABLE and TRUNCATE lose rows. The server refuses all of those but the plain CREATE TABLE while a transaction is open.
- Isolation.
begin_transactionalways names its level, so aSET isolation_levelrun earlier cannot change what it opens. - Limits. The row limit keeps one call from returning millions of rows, and the query timeout keeps it from running forever. A cancelled statement changes nothing and the connection stays usable. The driver has no raw cursor yet, so the server still reads the whole result before cutting it; the timeout bounds that work.
- One call at a time. Clients may send requests concurrently; the server runs them one after another, so statements of one transaction never interleave.
- COPY ... FROM reads files on the host with the server process's permissions, so an assistant can load any file the process can read. Run with
--read-onlywhen that is not acceptable. - Names and values. Table names are quoted, savepoint names must be plain identifiers, and pragma names and values are checked before they reach SQL.
- When the client disconnects or the process gets SIGINT, SIGTERM or SIGHUP, an open transaction is rolled back and the database is closed cleanly.
Upgrading from 0.4
- The 30 tools became 14.
transaction_query,transaction_executeandtransaction_execute_batchare gone:query,executeandexecute_batchrun inside the open transaction.create_table,create_index,create_view,alter_table,drop,analyze_tableandvacuumare statements forexecute.list_viewsis part oflist_tables;describe_table,show_create_table,show_create_viewandshow_indexesare covered byget_schemaand byquerywith SHOW and DESCRIBE.savepoint,rollback_to_savepointandrelease_savepointare onesavepointtool with anaction. - Rows come back as
{columns, rows, row_count, truncated}instead of an array of objects, and writes as{"affected_rows": n}. explaintakes the statement without the EXPLAIN keyword.--read-onlywas not airtight in 0.4: a#line comment could hide a second statement from the check. Upgrade if you rely on it.- Results stop at 1,000 rows and statements at 30 seconds by default.
stoolap://schemais DDL text instead of JSON.- Stoolap 0.5 opens a 0.4 database without a manual step and moves its format forward as it runs; 0.4 cannot open it afterwards. Back up the directory first; the engine's migration guide lists every answer that changed.
Requirements
- Node.js 20 or later.
@stoolap/node0.5, installed automatically, with prebuilt engine libraries for Linux (x64, arm64), macOS (x64, arm64) and Windows (x64). Its small N-API addon needs a C compiler at install time.
Development
git clone https://github.com/stoolap/stoolap-mcp.git
cd stoolap-mcp
npm install
npm test # builds, then runs the unit tests and the end-to-end tests against the built server
node build/index.js --path ./mydata
The source is split by concern: src/cli.ts (arguments), src/sql.ts (statement checks), src/session.ts (the connection, transaction state and result conversion), src/server.ts (tools, resources and prompt) and src/reference.ts (the texts sent to the assistant).
Releases are published to npm from the v* tag workflow with npm trusted publishing. server.json is the MCP Registry manifest for io.github.stoolap/mcp; its versions and the mcpName in package.json move with the npm package.
License
Apache-2.0
@stoolap/mcpnpm install @stoolap/mcp