erdlens

erdlens

MCP server that reads your database schema from SQL DDL, Prisma, Drizzle, TypeORM, or SQLAlchemy, generates a Mermaid ER diagram, and writes it into your documentation, with drift detection to keep diagrams up-to-date.

Category
Visit Server

README

<p align="center"> <img src="assets/logo.svg" alt="erdlens" width="96" height="96" /> </p>

<h1 align="center">erdlens</h1>

<p align="center"><b>Your schema becomes an ER diagram, straight into your docs. And it tells you when the diagram goes stale.</b></p>

<p align="center"> ๐Ÿ‡บ๐Ÿ‡ธ English ยท <a href="README.id.md">๐Ÿ‡ฎ๐Ÿ‡ฉ Bahasa Indonesia</a> ยท <a href="README.zh-CN.md">๐Ÿ‡จ๐Ÿ‡ณ ็ฎ€ไฝ“ไธญๆ–‡</a> </p>

<p align="center"> <img alt="license" src="https://img.shields.io/badge/license-MIT-6C8EEF" /> <img alt="runtime deps" src="https://img.shields.io/badge/runtime%20deps-0-6C8EEF" /> <img alt="tests" src="https://img.shields.io/badge/tests-57%20passing-6C8EEF" /> <img alt="mcp" src="https://img.shields.io/badge/MCP-server-6C8EEF" /> <img alt="typescript" src="https://img.shields.io/badge/TypeScript-MVVM-6C8EEF" /> </p>

<p align="center"> <img src="assets/showcase.gif" alt="erdlens turning a schema into an ER diagram, a workflow into a flowchart, and catching drift after a migration" width="720" /> </p>


You ask Claude Code to document your database. It writes the doc, you generate an ER diagram in some other tool, then you copy-paste the diagram back in. Two tools, double work, and the moment someone runs a migration the diagram in the doc is quietly wrong.

erdlens is an MCP server that closes that loop. Claude Code reads your schema, turns it into a Mermaid ER diagram, and writes it into the document in one pass. No second tool, no copy-paste. And it can check later whether that diagram still matches the schema.

Why it's different

The existing diagram MCP servers render Mermaid you already wrote. erdlens starts a step earlier: it reads the schema for you, and a step later: it watches for drift.

render your Mermaid read the schema write into the doc drift-check
mermaid-preview MCPs โœ… โŒ partial โŒ
mermerd (CLI, not MCP) โŒ โœ… (DB only) โŒ โŒ
erdlens โœ… โœ… (5 sources) โœ… โœ…

Schema sources: SQL DDL, Prisma, Drizzle, TypeORM, SQLAlchemy โ€” file or text, auto-detected.

Install (Claude Code)

claude mcp add erdlens -- npx -y github:ryanda9910/erdlens

Or point at a local clone:

git clone https://github.com/ryanda9910/erdlens
claude mcp add erdlens -- node /abs/path/to/erdlens/bin/erdlens.js

Then just ask Claude Code: "document the database and put an ER diagram in docs/schema.md". It calls render_erd and the diagram lands in the file.

Tools

tool what it does
schema_to_erd schema (path or text) โ†’ Mermaid erDiagram + a ```mermaid fenced block to paste anywhere
render_erd writes the ERD to disk: .mmd source, an embeddable .md, and a self-contained .html preview โ€” so it goes straight into a doc, no copy-paste
drift_check compares an ERD already in a .mmd/.md against the current schema, and reports every table, column, and relation added or removed since. Run it in CI so a stale diagram fails the build
workflow_to_diagram a workflow spec (a tiny text DSL or JSON steps) โ†’ Mermaid flowchart + fenced block. Document a process, pipeline, or state machine next to the ERD
render_workflow same as render_erd, for workflows โ€” writes the flowchart to disk, embeddable

The drift check

This is the part that keeps docs honest. After a migration:

$ erdlens drift docs/schema.md db/schema.sql
Diagram is stale. It drifted from the current schema:
  + tables added since: audit_logs
  ~ posts: +published +slug
  + relations added: posts->users
Regenerate with render_erd to fix.

Exit code is non-zero when stale, so it drops into a CI step or a pre-commit hook.

Workflows too

Not just data. Give it a workflow and it draws the flowchart โ€” same "into your docs" path.

# publish.flow
start -> draft
draft -> review
review -> publish : approved
review -> draft : changes
publish -> done
erdlens flow publish.flow
flowchart TD
  start(["start"])
  ...
  review -->|approved| publish
  review -->|changes| draft

Ask Claude Code "put the publish workflow in docs/flow.md" and it calls render_workflow.

Also a CLI

Without an MCP client:

erdlens erd db/schema.sql            # print the Mermaid ERD
erdlens erd prisma/schema.prisma     # auto-detects Prisma
erdlens flow pipeline.flow           # print a Mermaid flowchart
erdlens drift docs/erd.mmd db/schema.sql   # exit 1 if drifted
erdlens tune                         # run the self-check loop (below)

Self-improving loop

erdlens tune is a maker โ†’ checker โ†’ reflect loop: it runs every parser on a fixture plus a drift scenario (maker), an independent grader flags anything that passed before and fails now (checker), and it persists per-source pass state to ~/.erdlens/memory.json (reflect). It's how the parsers stay honest as new schema dialects get added โ€” a regression surfaces instead of slipping through.

Tests

npm test    # builds, then 57 assertions: 24 schema engine + 14 workflow + 19 MCP stdio

There's also an end-to-end script that drives the whole thing through a real Claude Code run (bash test/e2e.sh, needs the claude CLI logged in).

How it's built

TypeScript, laid out MVVM:

  • Model (src/model/) โ€” pure logic: schema parsers, workflow parser, drift diff, types.
  • ViewModel (src/viewmodel/) โ€” orchestration: the tool operations and the self-improving loop.
  • View (src/view/) โ€” surfaces: the JSON-RPC MCP server, the CLI, and Mermaid/HTML rendering.

Zero runtime dependencies. The MCP server is a from-scratch JSON-RPC stdio implementation; the HTML preview loads Mermaid from a CDN only when you open it in a browser.

License

MIT

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured