Project overview

AI-Powered Database Intelligence Agent

An MCP-based agent that connects AI tools to MySQL, enabling secure schema discovery, natural-language queries, and validated SQL execution.

MCP Ai Agent GO MySQL npm
AI-Powered Database Intelligence Agent preview

Overview

Developers often need to write SQL just to answer simple questions about their application's data.

DB Agent makes this easier.

You can ask questions like:

  • Who are our top 5 customers this month?

  • How many orders were refunded last week?

  • Which products have never been sold?

Instead of manually writing SQL, your AI assistant understands the database structure, prepares the query and sends it to DB Agent for validation and execution.

DB Agent acts as a safety layer between your AI assistant and your database.

The Problem

Giving AI access to a database is useful, but it comes with risks.

AI-generated SQL can use incorrect columns, expose sensitive information, retrieve too much data or attempt unwanted database changes.

Traditional solutions can also require additional AI subscriptions or software runtimes.

I wanted to build something simpler that works with the AI tools developers already use.

The Solution

DB Agent runs alongside your application and connects to its MySQL database.

It communicates with AI assistants through Model Context Protocol (MCP).

Here's how it works:

  1. Ask a question in Claude, Cursor or Codex.

  2. The AI uses DB Agent to understand your database and its business rules.

  3. The AI prepares an SQL query.

  4. DB Agent checks the query against its safety rules.

  5. Approved queries run in a read-only database session.

  6. The results are returned to the AI, which explains them in plain English.

Every query attempt is logged, and results are limited by configurable row and execution-time limits.

Key features

Safe SQL execution

Every query is validated before execution. Only supported read-only SELECT queries are allowed. Database writes, system tables, sensitive columns and potentially abusive functions are blocked.

Database schema understanding

DB Agent automatically discovers tables, columns, indexes and relationships, helping AI assistants understand how your database is structured.


Business rules and context

You can define business terms such as revenue and active customers, describe tables and columns, hide sensitive data and specify relationships using a simple rules.yaml file.

Query history and auditing

Allowed, blocked and failed queries are recorded locally, making database activity easier to review.

Works with existing AI tools

Integrates with Claude Code, Claude Desktop, Cursor, Codex and other MCP-compatible clients.

Lightweight installation

Built with Go and distributed as a single native binary. Developers can install it through npm, shell scripts or PowerShell without installing Go on their machines.

Engineering highlights

Some of the key technical decisions behind the project:

  • Used TiDB's MySQL parser to validate SQL instead of relying on regular expressions.

  • Rebuilds approved SQL from its parsed syntax tree before execution.

  • Uses multiple safety layers, including read-only database sessions, execution timeouts and row limits.

  • Keeps database configuration separate from the application's existing .env file.

  • Uses SQLite for local schema snapshots and audit history.

  • Uses live business-rule validation and fails closed when invalid rules could compromise security.

  • Built cross-platform binaries and automated releases through GitHub Actions.

Results so far

The first version is published on npm and GitHub. It has also been tested end to end with Claude Code against a live MySQL database.

Results so far