<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Baqqa</title>
    <description>The latest articles on DEV Community by Baqqa (@baqqa).</description>
    <link>https://dev.to/baqqa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3842886%2F3265957c-3675-41e0-8d9a-f826e60186d1.png</url>
      <title>DEV Community: Baqqa</title>
      <link>https://dev.to/baqqa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/baqqa"/>
    <language>en</language>
    <item>
      <title>I was tired of manual SQL introspection, so I built Legacy Lens (MCP Server)</title>
      <dc:creator>Baqqa</dc:creator>
      <pubDate>Sat, 28 Mar 2026 17:35:08 +0000</pubDate>
      <link>https://dev.to/baqqa/i-was-tired-of-manual-sql-introspection-so-i-built-legacy-lens-mcp-server-2nm9</link>
      <guid>https://dev.to/baqqa/i-was-tired-of-manual-sql-introspection-so-i-built-legacy-lens-mcp-server-2nm9</guid>
      <description>&lt;p&gt;We’ve all been there. You’re staring at a legacy database. 400 tables. Cryptic column names like &lt;code&gt;FLG_Z_99&lt;/code&gt;. No documentation. You try to explain it to an AI agent like Claude or Cursor, and it starts hallucinating JOINs that don’t exist.&lt;/p&gt;

&lt;p&gt;I was tired of copy-pasting DDL exports and manually explaining schemas. So, I built &lt;strong&gt;Legacy Lens&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem: The "Context Gap"
&lt;/h2&gt;

&lt;p&gt;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 &lt;strong&gt;semantic map&lt;/strong&gt; of the data. &lt;/p&gt;

&lt;p&gt;In a world of "AI Wrappers," we often forget that the bottleneck isn't the AI's intelligence—it's the &lt;strong&gt;precision of the context&lt;/strong&gt; we provide.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution: Model Context Protocol (MCP)
&lt;/h2&gt;

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

&lt;h3&gt;
  
  
  What Legacy Lens does:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Deep Introspection:&lt;/strong&gt; It doesn't just list tables. It maps foreign keys, schemas, and constraints across &lt;strong&gt;PostgreSQL, MySQL, SQLite, and MS SQL Server&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Smart Sampling:&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security First:&lt;/strong&gt; I implemented a "Least Privilege" approach. The server defaults to &lt;code&gt;READ ONLY&lt;/code&gt; transactions and provides SQL snippets to help users create restricted database roles.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Architecture: Why I split the logic
&lt;/h2&gt;

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

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;&lt;code&gt;@legacy-lens/db-introspect&lt;/code&gt;&lt;/strong&gt;: 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.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;&lt;code&gt;@legacy-lens/mcp-server&lt;/code&gt;&lt;/strong&gt;: The bridge. It uses the introspection layer to expose tools (&lt;code&gt;list_tables&lt;/code&gt;, &lt;code&gt;describe_table&lt;/code&gt;, &lt;code&gt;sample_rows&lt;/code&gt;) to any MCP-compliant client like Cursor, Claude Desktop, or custom agents.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Try it out
&lt;/h2&gt;

&lt;p&gt;If you're dealing with a database that makes you want to quit your job, give this a spin:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx @legacy-lens/mcp-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


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

&lt;p&gt;Check out the project on GitHub:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/baqqa" rel="noopener noreferrer"&gt;
        baqqa
      &lt;/a&gt; / &lt;a href="https://github.com/baqqa/LegacyLens" rel="noopener noreferrer"&gt;
        LegacyLens
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      An MCP that allows to search you're db with you're AI
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Legacy Lens&lt;/h1&gt;
&lt;/div&gt;

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

&lt;p&gt;&lt;strong&gt;Supported databases:&lt;/strong&gt; PostgreSQL, MySQL / MariaDB, SQLite, Microsoft SQL Server. Oracle is not supported.&lt;/p&gt;




&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Install (npm)&lt;/h2&gt;
&lt;/div&gt;

&lt;p&gt;You need &lt;strong&gt;Node.js 20+&lt;/strong&gt;.&lt;/p&gt;

&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;npm install -g @legacy-lens/mcp-server&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;After install, the &lt;strong&gt;&lt;code&gt;legacy-lens-mcp&lt;/code&gt;&lt;/strong&gt; command is available. The MCP host must run it &lt;strong&gt;with no arguments&lt;/strong&gt; (stdio mode). Subcommands are only for setup from a…&lt;/p&gt;
&lt;/div&gt;


&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/baqqa/LegacyLens" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


</description>
      <category>mcp</category>
      <category>database</category>
      <category>ai</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
