Skip to main content

dsh-db-mcp: hand the database to the agent, not just a SQL wrench

· 11 min read
halcyon666
Full Stack Developer

Nearly every "database MCP" looks the same: connect to the database, then hand the model five tools — list, describe, sample, explain, run SQL. That works, but it leaves the hard part exactly where it was: the schema has forty tables, so the model guesses which one holds orders, guesses how order_item joins product, and guesses which column that SO-1001 from two calls ago actually lives in. When it guesses wrong, nobody corrects it — the next turn guesses again.

dsh-db-mcp starts somewhere else. Instead of handing the model a SQL wrench, it writes down what this database looks like and how a value flows between its tables.

The left half is what you do in the panel; the right half is what happens in the conversation once a source exists. That path is the whole argument of this plugin.

From a DBeaver connection to an answer in the conversation

1. The setup you no longer do​

The first design decision in this plugin has nothing to do with agents. It has to do with being lazy.

No retyping connections. The importer reads DBeaver's workspace data-sources.json and decrypts credentials-config.json with DBeaver's own key — host, port, database, user, and the saved password come across in one step. Tick, import, done. Addresses already registered are marked, so the same connection is never added twice.

No DSH configuration. The bundle inserts a single Loader record; the plugin starts its own Python MCP server and registers its own tools. No hand-edited JSON, no exported environment variables.

No hand-built Python environment. The panel finds an interpreter, creates .venv, and installs the drivers (mcp, psycopg[binary], py-opengauss, PyMySQL, oracledb, cryptography). Failures are laid out on the page instead of buried in a log.

No starting over every time. The panel reopens on the tab you left, with the search box, the trace inputs, and a half-filled new-source form still there — plus the relation graph and the trace you last ran. Position and drafts live in the browser; passwords never do. Result rows stay in memory only: close the page and they are gone, never written to disk as a cache.

dsh plugin --profile desktop add dsh-db-mcp # desktop
dsh plugin --profile web add dsh-db-mcp # web

Here is what a source list looks like: a health summary at the top, sources grouped the way you arranged them, each with its engine badge and the identifier tool calls use, and an unreachable source spilling its full error in place.

source list

All of that saves startup cost — and startup cost is what decides whether you actually use a tool.

2. One set of sources, every agent​

The registry lives in ~/.dsh/db-mcp/, outside any profile: datasources.json holds connections, secrets.json holds passwords, mode 0600. Desktop and web read the same files, so one import is visible everywhere. Several DSH windows at once are fine too: each starts its own Python server, the first takes the HTTP port and the rest move to the next free one.

The more useful part: the same server is exposed over streamable HTTP for other clients. The Connect another client tab shows the address and writes the config for you:

ClientWhat gets written
VS Code / Insidersan HTTP entry in mcp.json
Cursor~/.cursor/mcp.json
Claude Code~/.claude.json
Claude Desktopa stdio entry in claude_desktop_config.json
Codex CLI[mcp_servers.dsh-db-mcp] in ~/.codex/config.toml

JetBrains Air and any other MCP client work by pasting http://127.0.0.1:8765/dsh-db-mcp. Sources, read-only flags, DDL switches and the audit log are shared; per-session restrictions ("which sources this conversation may touch") only exist inside DSH, because they are DSH's own sessions.

A machine without DSH still works: npm i -g dsh-db-mcp, then setup (finds Python, builds the venv) and client-config cursor. Passwords are typed in the panel, never passed as command-line arguments.

3. The relation graph is grown, not drawn​

In real databases, a foreign key is usually in one of three states: never declared, declared but invisible to your login, or wrong. So "what joins what" should not be one sentence from the catalog — it should be a graph you can correct. Four feeds pour into the same graph:

  • discover_relations imports the declared foreign keys;
  • mine_relations mines joins out of statements already in the audit log;
  • scan_code_relations reads joins a Spring Boot project already wrote down — mapper XML, @Select/@Insert annotations, MyBatis-Plus .apply(...) / .inSql(...) fragments; <include refid> is expanded, <choose> takes only its first <when>, and <association>/<collection> are resolved in two passes by namespace.id;
  • propose_relation records one the catalog never knew about.

Every edge carries a state: pending (a suggestion), confirmed (you said so), trusted (confirmed enough times in a row and cheap enough to walk, so it stops asking), stale (walked, came back wrong), rejected (tried, known wrong, don't offer it again). A guess never quietly becomes a fact — traces only walk confirmed and trusted edges; everything else sits on the graph waiting for a human.

One detail I like: trust is not "clicked three times". It means the last three confirmations in a row, with no rejection after them, plus measured step timings that hold up. If an edge starts to get slow — the table grew, the index was dropped — trust is withdrawn and it goes back to asking each time.

4. Trace by value: start from one value​

This is the part that least resembles a normal database tool. Other tools make you write a query; here you can hand over one value:

Which table holds SO-1001, and what does it pull in from there?

trace_by_key probes the candidate columns first (primary keys, columns other joins point at, indexed key-shaped columns), then walks outward along confirmed joins. Each level reports the table, how many rows matched, how long it took, a few key cells, and which two columns the edge that carried it compared. Broken chains, truncations and warned steps are marked separately. Every step can be judged "ok / too many (with a reason) / missing / irrelevant", and the verdict is written back to the edge underneath it — so the next trace is better.

The panel draws that walk as a graph: one depth per lane, left to right; one box per table visited, one line per join walked, labelled with the columns it compared. Each lane is ordered by its parents' rows in the lane to the left, so lines never cross; a table already read is not drawn again, because its data came from upstream and a second box would just be a repeat. When the value turns up in several places, the starting points become chips you pick from.

Scenes narrow a trace to one business process: save a named set of tables, and joins that leave the set stop walking — the tables they would have reached are listed as "outside the scene" with one button to pull them in and re-run. A scene can also say what its tables are called in business (流水号 is order_no here and order_id there) and match loosely where no join exists at all (same day, within N minutes). A loose match is only ever shown, never walked as a step; before saving, the editor's Try it runs the business keys against the live catalog, so a key that finds nothing is visible before it is saved.

Expensive steps ask first. A join whose target column has no index and whose table is big is not walked on its own: every step held back is listed together, one checkbox each, the smallest table pre-ticked, and only the ticked ones run. An approved full scan that hits the statement timeout is marked "did not finish" instead of quietly counting as zero rows.

Neither page accepts SQL. Statements are assembled by the server from the graph, with bound parameters, for the panel, the agent and the HTTP endpoint alike — the panel manages connections, it is not a SQL console.

5. Safety and audit: read-only by default, always on the record​

  • Three independent gates: the global write switch, the per-source flag, and a separate DDL switch. All three open before a write is allowed; create/alter/drop/truncate/rename/grant/revoke are refused until the DDL switch is on.
  • Passwords stay on the machine, encrypted. Each source is an AES-256-GCM envelope in secrets.json, keyed by secret.key beside it (0600); no HTTP route returns it, and the Python child gets a short allow-listed environment rather than the whole DSH one.
  • Every tool call is audited, appended to logs/audit.jsonl: tool, source, elapsed time, row count, SQL (string literals are replaced with ? first). Result rows are never recorded.
  • The gate lives in the Python server, not the panel — so Cursor or Claude Code calling the same server gets exactly the same rules.

One deliberate asymmetry: widening permissions in the panel needs a typed word, and only the path where a human is sitting in front of the panel may skip a connection retry cooldown. An agent calling the same tool cannot take that shortcut. It can do the job, but it cannot open the gate for you.

6. What changes before you upgrade​

Coming from 1.x, these change what you — or your scripts — see:

  1. 2.0: no default source any more. With several configured, a call that names none is refused and the agent is told to ask which one; it may only be omitted when exactly one source exists. An old registry's isDefault flag is ignored rather than honoured.
  2. 2.0: list_relations and describe_table.foreignKeys are gone. Relations have one home now — list_edges, with state, counts and cost — instead of two sources of truth.
  3. 2.0: confirm_slow is a list, not a boolean. A bare true used to approve the whole walk; now only the edges you name are approved.
  4. 3.0: the command line is down to five commands. add, list, edit, remove, test, import, allow-write, read-only, allow-ddl and audit are gone — those things happen in the panel, so there is one copy of the rules. An old script gets unknown command: <word>, exit 2, and no file is written.
  5. 3.0: a table name in several schemas is now a question, not a guess. The four structure readers resolve "named schema → the source's pinned schema → the one schema that has it"; when two hold the name the call is refused and lists them.

All of it is in the CHANGELOG, with the 2.0 items collected under Behavior changes — one read before upgrading is enough. Status: npm currently publishes 2.0.1; the 3.0 changes described here are on main.

7. Is it worth using?​

If all you want is an occasional select * from t limit 10, a plain database MCP is enough. Don't install this.

But if you have hit any of these, the time it saves is real:

  • every new conversation starts by re-explaining that the orders table is sales_order and its key is id, not order_id;
  • the model writes a three-table join, gets zero rows, and you can't tell whether the condition was wrong or it guessed the wrong column;
  • someone let an agent "just" update one row on production, and you only found out by scrolling back through the chat;
  • five clients need the same database and the config was retyped five times.

The premise is simple: write the environment facts down once — connections, relations, permissions, audit — so every conversation starts from somewhere it already knows. It is not a smarter model; it just stops making the model feel around in the dark.