<?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: Mohamed amine Atil</title>
    <description>The latest articles on DEV Community by Mohamed amine Atil (@mohamed_amineatil_ff8da8).</description>
    <link>https://dev.to/mohamed_amineatil_ff8da8</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%2F3964793%2F5ad2ac9f-59d2-4219-8cda-5b2631cafe70.jpg</url>
      <title>DEV Community: Mohamed amine Atil</title>
      <link>https://dev.to/mohamed_amineatil_ff8da8</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mohamed_amineatil_ff8da8"/>
    <language>en</language>
    <item>
      <title>I built a read-only Postgres MCP server so I could point Claude at prod without fear</title>
      <dc:creator>Mohamed amine Atil</dc:creator>
      <pubDate>Tue, 02 Jun 2026 14:21:05 +0000</pubDate>
      <link>https://dev.to/mohamed_amineatil_ff8da8/i-built-a-read-only-postgres-mcp-server-so-i-could-point-claude-at-prod-without-fear-jkd</link>
      <guid>https://dev.to/mohamed_amineatil_ff8da8/i-built-a-read-only-postgres-mcp-server-so-i-could-point-claude-at-prod-without-fear-jkd</guid>
      <description>&lt;p&gt;The Model Context Protocol (MCP) lets AI assistants like Claude and Cursor connect to real systems — including your database. The problem: most setups hand the AI a connection string with full write access, and rely on the model choosing not to run a DELETE without a WHERE.&lt;/p&gt;

&lt;p&gt;That's the part I wanted to remove. Not "the AI probably won't write" — "the AI can't write." So I built &lt;a href="https://boltschema.com" rel="noopener noreferrer"&gt;BoltSchema&lt;/a&gt;: a Postgres MCP server that's read-only by default and structurally can't modify your database. Here's how it works under the hood.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdmokpe3cundob9g2wgdj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdmokpe3cundob9g2wgdj.png" alt=" " width="800" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The threat model
&lt;/h2&gt;

&lt;p&gt;The scary part of AI + database access isn't the AI being malicious. It's:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A hallucinated UPDATE that "fixes" a row.&lt;/li&gt;
&lt;li&gt;A DROP TABLE suggested confidently during a "cleanup."&lt;/li&gt;
&lt;li&gt;SQL injection through a tool call you didn't sanitize.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Read-only credentials are the obvious answer — and everyone means to set them up. But read-only-by-discipline breaks the one time you forget, or grab the wrong connection string. I wanted read-only to be the default, enforced at multiple layers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Defense in depth
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Layer 1 — Read-only transaction on every query.
&lt;/h3&gt;

&lt;p&gt;Every single query runs inside:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;BEGIN READ ONLY;&lt;br&gt;
-- your query&lt;br&gt;
COMMIT;&lt;/code&gt;&lt;br&gt;
Even if someone hands the server a superuser connection string, Postgres itself refuses any write inside a READ ONLY transaction. The database is the last line of defense, and it doesn't trust my code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Layer 2 — A SQL guard that isn't fooled by string literals.
&lt;/h3&gt;

&lt;p&gt;A naive keyword blocklist is trivially bypassed — SELECT 'DROP TABLE users' would trip a dumb filter, and '; DROP TABLE-- would slip past one. So the guard:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Strips comments and string literals (single-quoted, double-quoted, and dollar-quoted) first,&lt;/li&gt;
&lt;li&gt;Then keyword-matches against a banlist (DROP, DELETE, INSERT, UPDATE, ALTER, TRUNCATE, GRANT, …),&lt;/li&gt;
&lt;li&gt;Rejects multi-statement payloads outright.&lt;/li&gt;
&lt;li&gt;So you can't smuggle a forbidden keyword inside a literal, and you can't chain a second statement.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Layer 3 — Encryption at rest.
&lt;/h3&gt;

&lt;p&gt;Connection strings are encrypted with AES-256-GCM (random IV + auth tag per record). Token comparison uses timingSafeEqual to avoid timing attacks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Layer 4 — Result limits.
&lt;/h3&gt;

&lt;p&gt;Queries are wrapped in a LIMIT (default 100, hard cap 1000) so a SELECT * on a huge table doesn't blow up the context window or the connection.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it exposes to the AI
&lt;/h2&gt;

&lt;p&gt;Two MCP tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;get_database_schema&lt;/code&gt; — lists tables + columns from information_schema (system schemas excluded).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;execute_read_only_query&lt;/code&gt; — runs SQL through the guard + read-only transaction.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The transport
&lt;/h2&gt;

&lt;p&gt;It speaks MCP Streamable HTTP (the modern SSE-based transport that supersedes the deprecated SSEServerTransport), built on the official @modelcontextprotocol/sdk. Native streamable-HTTP clients point at the URL directly; stdio-only clients (like Claude Desktop) use the mcp-remote bridge.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it without connecting your own DB
&lt;/h2&gt;

&lt;p&gt;There's a zero-trust sandbox: one click seeds a realistic e-commerce Postgres database (customers, products, orders, …) and hands you a public token you can paste straight into Claude Desktop. No signup, same read-only guard as production.&lt;/p&gt;

&lt;p&gt;🔗 Built by me — try BoltSchema here: &lt;a href="https://boltschema.com" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;br&gt;
🐦 Questions or feedback? I'm on X: &lt;a href="https://x.com/atilmohamine" rel="noopener noreferrer"&gt;@atilmohamine&lt;/a&gt;&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>postgres</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
