npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

db-diagram-tool-mcp

v0.2.0

Published

Model Context Protocol (stdio) server for DB Diagram Tool — lets Claude Code / Codex read (list, schema JSON, DBML, SQL DDL) and, with a write-scoped token, create and update your diagrams from DBML.

Readme

db-diagram-tool-mcp

A Model Context Protocol server (stdio) that lets MCP clients — Claude Code and OpenAI Codexread your DB Diagram Tool diagrams (list them; fetch a schema as JSON, DBML, or SQL DDL) and, with a write-scoped token, create and update them from DBML.

It talks to the DB Diagram Tool backend over its normal REST API, authenticated with a Personal Access Token (PAT). A read PAT can only read; the write tools require a write PAT. Writes merge into the live document like a collaborator typing (concurrent editors are never clobbered), and deletions are never applied without your explicit confirmation (see below).

Tools

Read (a read or write PAT):

| Tool | Args | Returns | |------|------|---------| | list_diagrams | — | The diagrams your token can access (id, name, role, visibility, updated time). | | get_diagram | id | Metadata + the full schema snapshot (tables, columns, relationships) as JSON. | | get_diagram_dbml | id | The diagram rendered as DBML (dbdiagram.io text format). | | get_diagram_sql | id, dialect? (postgres | mysql, default postgres) | Server-generated CREATE TABLE SQL DDL. |

Write (a write PAT):

| Tool | Args | Returns | |------|------|---------| | create_diagram | name, dbml | Creates a new diagram from DBML (you own it); returns the new id + an editor URL. | | update_diagram | id, dbml, confirmDeletions? | Merges the DBML into the live diagram. Additions/changes apply at once; table/column deletions are withheld and returned as pendingDeletions until you re-call with confirmDeletions: true. |

Delete safety (two-call handshake). If your DBML drops a table or column, update_diagram applies nothing destructive and lists what would be deleted. The agent shows you those, and only after you approve does it call again with confirmDeletions: true. A paste that forgets a table can't silently destroy it.

Requirements

  • Node.js ≥ 18 (uses the built-in fetch).
  • A Personal Access Token for your DB Diagram Tool account (create one in the app's Settings → Personal Access Tokens). It looks like ddt_pat_…. Choose the write scope if you want the create/update tools; read is enough (and safer) for read-only use.
  • The backend origin URL (e.g. http://localhost:8090 for local dev, or your hosted instance).

Configuration

The server reads these environment variables (set them in your MCP client's server config, below):

| Variable | Required | Example | Notes | |----------|----------|---------|-------| | DDT_BASE_URL | yes | http://localhost:8090 | Backend origin only — scheme + host[:port], no /api/v1 path. | | DDT_PAT | yes | ddt_pat_abc123… | Your personal access token. Treat it like a password. | | DDT_WS_URL | no | wss://relay.example.com | Relay WS origin for write-back. Defaults to DDT_BASE_URL with http→ws / https→wss — only set it when the realtime relay is on a different host than the REST API. | | DDT_APP_URL | no | https://app.example.com | Web app origin, used for the editor URL create_diagram returns. Defaults to DDT_BASE_URL. |

Build

Not published to npm yet — build it locally and point your client at the compiled entry (dist/index.js):

cd db-diagram-tool-mcp
npm install
npm run build
# entry point: <this dir>/dist/index.js  (use its ABSOLUTE path below)

Install in Claude Code

CLI (adds it for you):

claude mcp add --transport stdio db-diagram-tool \
  --env DDT_BASE_URL=http://localhost:8090 \
  --env DDT_PAT=ddt_pat_your_token_here \
  -- node /ABSOLUTE/PATH/TO/db-diagram-tool-mcp/dist/index.js

--scope defaults to local (this project, private to you); add --scope user to enable it everywhere, or --scope project to write a shared, git-tracked .mcp.json.

Or a project .mcp.json (git-tracked; shared with your team):

{
  "mcpServers": {
    "db-diagram-tool": {
      "command": "node",
      "args": ["/ABSOLUTE/PATH/TO/db-diagram-tool-mcp/dist/index.js"],
      "env": {
        "DDT_BASE_URL": "http://localhost:8090",
        "DDT_PAT": "${DDT_PAT}"
      }
    }
  }
}

Don't commit your token. Claude Code expands ${VAR} (and ${VAR:-default}) in .mcp.json, so use "DDT_PAT": "${DDT_PAT}" and export DDT_PAT in your shell — the raw token stays out of the repo.

Install in Codex

CLI:

codex mcp add db-diagram-tool \
  --env DDT_BASE_URL=http://localhost:8090 \
  --env DDT_PAT=ddt_pat_your_token_here \
  -- node /ABSOLUTE/PATH/TO/db-diagram-tool-mcp/dist/index.js

(The -- before the command is required.)

Or ~/.codex/config.toml (global) — or .codex/config.toml in a project:

[mcp_servers.db-diagram-tool]
command = "node"
args = ["/ABSOLUTE/PATH/TO/db-diagram-tool-mcp/dist/index.js"]

[mcp_servers.db-diagram-tool.env]
DDT_BASE_URL = "http://localhost:8090"
DDT_PAT = "ddt_pat_your_token_here"

Codex TOML does not expand ${VAR} — use literal values, and keep the file private (don't commit a token).

Try it

Once configured, ask your agent things like:

  • "List my DB Diagram Tool diagrams."
  • "Show the DBML for the diagram named Blog."
  • "Give me the Postgres DDL for diagram <id>."
  • "Create a diagram called Orders from this DBML: …" (write PAT)
  • "Add a status column to orders in diagram <id>." (write PAT)

Security

  • Scoped tokens. A read PAT reaches only the four diagram-read endpoints; a write PAT additionally creates/updates diagrams. Neither can read member emails or comments, or manage tokens. Prefer read unless you want write-back.
  • The PAT never touches the relay. For a live write, the server exchanges the write PAT for a short-lived (~120s), single-diagram aud:"ws" token and uses that for the realtime handshake — a leaked handshake token can't act as a REST session or reach another diagram.
  • Deletions need your confirmation. update_diagram never drops a table or column on the first call — it reports pendingDeletions and applies them only when you re-call with confirmDeletions: true.
  • Store your PAT like a password — prefer ${DDT_PAT} env expansion (Claude Code) over inlining, and never commit it.

Notes

  • diagramToDbml.ts is ported verbatim from the web app (db-diagram-tool-fe/src/lib/dbml/diagramToDbml.ts); keep the two in sync.
  • src/core/ vendors the web app's DBML↔diagram + Yjs bridge modules verbatim (only import paths rewritten). A drift-guard test (src/core/vendored.drift.test.ts) fails if they diverge from the FE source — re-vendor and re-run the golden when the FE changes.
  • Built against @modelcontextprotocol/sdk v1.30; write-back builds to REST contract v1.7.0 (/pats/ws-token, write-scoped PATs).