DEV Community

Hero Tech
Hero Tech

Posted on

How to Safely Connect Claude and Cursor IDE to Production Databases (MS SQL & Postgres)

Hey devs!

If you are using Claude Desktop or Cursor for development, you know how powerful AI is. But the moment you want the AI to query databases or inspect schemas, you hit a security wall. How do you give an LLM access to your database without risking accidental deletions (DROP TABLE) or edits?

I solved this by building a Model Context Protocol (MCP) server in C# .NET 8.

The Safety Architecture:

  1. Read-Only Transaction Rollback: Every SELECT query run by the AI is wrapped in a database transaction and immediately rolled back. Writes are physically impossible.
  2. Security Keywords Scan: Blocks input containing INSERT, UPDATE, DELETE, ALTER, etc.
  3. Auto Top-100 Cap: Prevents query resource exhaustion by forcing top results limits.
  4. Dynamic Schema Discoverer: The AI queries system tables on-the-fly to build perfect SQL joins without configuration.

I have made the pre-compiled trial binary available on GitHub:
🔗 GitHub - C# SQL/Postgres MCP Server Demo

Try it out, connect Claude/Cursor, and let your AI do the data analysis safely!

Top comments (0)