DEV Community

Cover image for I was tired of manual SQL introspection, so I built Legacy Lens (MCP Server)
Baqqa
Baqqa

Posted on

I was tired of manual SQL introspection, so I built Legacy Lens (MCP Server)

We’ve all been there. You’re staring at a legacy database. 400 tables. Cryptic column names like FLG_Z_99. No documentation. You try to explain it to an AI agent like Claude or Cursor, and it starts hallucinating JOINs that don’t exist.

I was tired of copy-pasting DDL exports and manually explaining schemas. So, I built Legacy Lens.

The Problem: The "Context Gap"

AI models are smart, but they are "blind" to your local infrastructure. To make an LLM actually useful for database engineering, it needs more than just a connection string; it needs a semantic map of the data.

In a world of "AI Wrappers," we often forget that the bottleneck isn't the AI's intelligence—it's the precision of the context we provide.

The Solution: Model Context Protocol (MCP)

I decided to leverage the Model Context Protocol. Instead of a simple wrapper, I built a dedicated introspection engine that acts as the AI's "eyes" inside the database.

What Legacy Lens does:

  • Deep Introspection: It doesn't just list tables. It maps foreign keys, schemas, and constraints across PostgreSQL, MySQL, SQLite, and MS SQL Server.
  • Smart Sampling: It provides 5-10 sample rows per call. This gives the AI the "vibe" of the data (date formats, nullability, categorical values) without blowing up the context window.
  • Security First: I implemented a "Least Privilege" approach. The server defaults to READ ONLY transactions and provides SQL snippets to help users create restricted database roles.

Architecture: Why I split the logic

I care about modularity and reusability. I didn't just build one monolithic script. I split the project into two scoped NPM packages:

  1. @legacy-lens/db-introspect: A standalone, dialect-agnostic library. You can use it for migrations, custom dashboards, or any tool that needs to "understand" a DB structure without the AI part.
  2. @legacy-lens/mcp-server: The bridge. It uses the introspection layer to expose tools (list_tables, describe_table, sample_rows) to any MCP-compliant client like Cursor, Claude Desktop, or custom agents.

Try it out

If you're dealing with a database that makes you want to quit your job, give this a spin:

npx @legacy-lens/mcp-server
Enter fullscreen mode Exit fullscreen mode

I’m currently looking for feedback on which engine to support next. Oracle? (Only if I'm feeling particularly brave).

Check out the project on GitHub:

GitHub logo baqqa / LegacyLens

An MCP that allows to search you're db with you're AI

Legacy Lens

Legacy Lens is an MCP (Model Context Protocol) server that lets AI assistants in Cursor and other hosts inspect legacy SQL databases safely. It answers questions about structure and sample data: schemas, tables, columns, foreign keys, and a small number of sample rows per request (default 5, maximum 10). It is meant for understanding old systems before you change them—not for arbitrary read/write SQL from the model.

Supported databases: PostgreSQL, MySQL / MariaDB, SQLite, Microsoft SQL Server. Oracle is not supported.


Install (npm)

You need Node.js 20+.

npm install -g @legacy-lens/mcp-server
Enter fullscreen mode Exit fullscreen mode

If the package is not yet on the public registry, install from your team’s tarball, GitHub Packages, or private registry the same way you install other scoped packages.

After install, the legacy-lens-mcp command is available. The MCP host must run it with no arguments (stdio mode). Subcommands are only for setup from a…




Top comments (0)