# SQL MCP Server

> SQL MCP Server is an open-source MCP server for databases. Governed SQL gateway for untrusted AI agents on PostgreSQL, MySQL and OceanBase. It runs locally on your machine and is started by your AI client.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** Self-hosted, CLI, Linux, macOS
- **Repository:** https://github.com/nethinwei/sql-mcp-server
- **MCP Registry name:** io.github.nethinwei/sql-mcp-server
- **Categories:** [databases](https://ai-powered.com/categories/databases), [security](https://ai-powered.com/categories/security)
- **Listing updated:** 2026-11-23

## About

Rather than hand an agent a database connection, this Go gateway makes it work through explicit entities, a relational-algebra intermediate form and parameterised code generation. The governed path accepts no arbitrary SQL and offers no DDL. Documentation is mainly in Chinese.

Controls include RBAC, field ACLs, row policies and masking, EXPLAIN pre-screening, result caps, timeouts and session or tenant budgets, and the design fails closed when a safety capability cannot be proven. Configuration hot-reloads, audits are asynchronous and OpenTelemetry hooks are available. A separate trusted-operator escape tool, execute_sql, is off by default, visible only to users granted sql:execute for a data source, and bound by hard limits and fail-on-audit-write rules.

A five-minute Docker Compose quickstart demonstrates tenant isolation, masking and denials. It ships as a container image and stdio server, with a web admin console, and is MIT licensed at version 0.1.21.

## Features

- **No arbitrary SQL:** Agents compose only controlled tools and allow-listed IR.
- **Field and row governance:** RBAC, field ACLs, row policies and masks are enforced together.
- **Cost limits:** EXPLAIN screening, result caps, timeouts and budgets.
- **Fail closed:** Denies when a safety capability cannot be proven.
- **Audit trail:** Asynchronous audit with OpenTelemetry hooks.
- **Trusted escape hatch:** execute_sql is off by default and separately audited.

## Good for

- Give an AI agent read access to tenant data without raw SQL
- Mask sensitive columns in agent queries
- Cap query cost per session or tenant
- Audit every agent data access

## Install

### Claude Code: Add with the CLI (Terminal)

```sh
claude mcp add sql-mcp-server --env DATABASE_DSN='<DATABASE_DSN>' -- docker run -i --rm -e DATABASE_DSN ghcr.io/nethinwei/sql-mcp-server:0.1.21
```

Add --scope user to use it in every project, or --scope project to share it in .mcp.json.

### Claude Code: Or share it with your project (.mcp.json)

```json
{
  "mcpServers": {
    "sql-mcp-server": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_DSN",
        "ghcr.io/nethinwei/sql-mcp-server:0.1.21"
      ],
      "env": {
        "DATABASE_DSN": "<DATABASE_DSN>"
      }
    }
  }
}
```

### Claude Desktop (claude_desktop_config.json)

```json
{
  "mcpServers": {
    "sql-mcp-server": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_DSN",
        "ghcr.io/nethinwei/sql-mcp-server:0.1.21"
      ],
      "env": {
        "DATABASE_DSN": "<DATABASE_DSN>"
      }
    }
  }
}
```

Settings → Developer → Edit Config, then quit and reopen Claude Desktop.

### Cursor (~/.cursor/mcp.json)

```json
{
  "mcpServers": {
    "sql-mcp-server": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_DSN",
        "ghcr.io/nethinwei/sql-mcp-server:0.1.21"
      ],
      "env": {
        "DATABASE_DSN": "<DATABASE_DSN>"
      }
    }
  }
}
```

Use .cursor/mcp.json in a project to share it with the project.

### VS Code (~/.copilot/mcp-config.json)

```json
{
  "mcpServers": {
    "sql-mcp-server": {
      "type": "stdio",
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_DSN",
        "ghcr.io/nethinwei/sql-mcp-server:0.1.21"
      ],
      "env": {
        "DATABASE_DSN": "<DATABASE_DSN>"
      }
    }
  }
}
```

Or put the same entry in .mcp.json at your workspace root to share it.

### Codex: Add with the CLI (Terminal)

```sh
codex mcp add sql-mcp-server --env DATABASE_DSN='<DATABASE_DSN>' -- docker run -i --rm -e DATABASE_DSN ghcr.io/nethinwei/sql-mcp-server:0.1.21
```

### Codex: Or add to config.toml (~/.codex/config.toml)

```toml
[mcp_servers.sql-mcp-server]
command = "docker"
args = ["run", "-i", "--rm", "-e", "DATABASE_DSN", "ghcr.io/nethinwei/sql-mcp-server:0.1.21"]
env = { DATABASE_DSN = "<DATABASE_DSN>" }
```

### Gemini CLI and Antigravity: Gemini CLI (~/.gemini/settings.json)

```json
{
  "mcpServers": {
    "sql-mcp-server": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_DSN",
        "ghcr.io/nethinwei/sql-mcp-server:0.1.21"
      ],
      "env": {
        "DATABASE_DSN": "<DATABASE_DSN>"
      }
    }
  }
}
```

Or run: gemini mcp add -s user -e DATABASE_DSN='<DATABASE_DSN>' sql-mcp-server docker -- run -i --rm -e DATABASE_DSN ghcr.io/nethinwei/sql-mcp-server:0.1.21

### Gemini CLI and Antigravity: Antigravity (~/.gemini/config/mcp_config.json)

```json
{
  "mcpServers": {
    "sql-mcp-server": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_DSN",
        "ghcr.io/nethinwei/sql-mcp-server:0.1.21"
      ],
      "env": {
        "DATABASE_DSN": "<DATABASE_DSN>"
      }
    }
  }
}
```

Use .agents/mcp_config.json to add it to one workspace only.

### Devin Desktop (~/.config/devin/mcp_config.json)

```json
{
  "mcpServers": {
    "sql-mcp-server": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_DSN",
        "ghcr.io/nethinwei/sql-mcp-server:0.1.21"
      ],
      "env": {
        "DATABASE_DSN": "<DATABASE_DSN>"
      }
    }
  }
}
```

On Windows the file is %APPDATA%\\devin\\mcp_config.json. Use .devin/mcp_config.json to share it with a project.

### Cline (cline_mcp_settings.json)

```json
{
  "mcpServers": {
    "sql-mcp-server": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_DSN",
        "ghcr.io/nethinwei/sql-mcp-server:0.1.21"
      ],
      "env": {
        "DATABASE_DSN": "<DATABASE_DSN>"
      }
    }
  }
}
```

Open it from the MCP Servers icon → Configure → Configure MCP Servers.

### Zed (Zed settings.json)

```json
{
  "context_servers": {
    "sql-mcp-server": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_DSN",
        "ghcr.io/nethinwei/sql-mcp-server:0.1.21"
      ],
      "env": {
        "DATABASE_DSN": "<DATABASE_DSN>"
      }
    }
  }
}
```

Open it with zed: open settings file. Merge context_servers into the settings you already have.

### JetBrains AI Assistant and Junie: AI Assistant (Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add)

```json
{
  "mcpServers": {
    "sql-mcp-server": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_DSN",
        "ghcr.io/nethinwei/sql-mcp-server:0.1.21"
      ],
      "env": {
        "DATABASE_DSN": "<DATABASE_DSN>"
      }
    }
  }
}
```

The AI Assistant docs only show command and args. If the env block is ignored, use Junie for this server.

### JetBrains AI Assistant and Junie: Junie (~/.junie/mcp/mcp.json)

```json
{
  "mcpServers": {
    "sql-mcp-server": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_DSN",
        "ghcr.io/nethinwei/sql-mcp-server:0.1.21"
      ],
      "env": {
        "DATABASE_DSN": "<DATABASE_DSN>"
      }
    }
  }
}
```

Use .junie/mcp/mcp.json to share it with a project.

### Kiro (~/.kiro/settings/mcp.json)

```json
{
  "mcpServers": {
    "sql-mcp-server": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_DSN",
        "ghcr.io/nethinwei/sql-mcp-server:0.1.21"
      ],
      "env": {
        "DATABASE_DSN": "<DATABASE_DSN>"
      }
    }
  }
}
```

Use .kiro/settings/mcp.json to add it to one workspace only.

### Other clients (your client's MCP settings (most use this shape))

```json
{
  "mcpServers": {
    "sql-mcp-server": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DATABASE_DSN",
        "ghcr.io/nethinwei/sql-mcp-server:0.1.21"
      ],
      "env": {
        "DATABASE_DSN": "<DATABASE_DSN>"
      }
    }
  }
}
```

## Tools

From the tool list in its README, going by the names, 1 of 1 tool changes data. From the server's own tool labels and tool names; not verified by us.

- `execute_sql` (name suggests: changes): Trusted-operator SQL escape tool, disabled by default

## FAQ

### Which databases?

PostgreSQL, MySQL and OceanBase.

### Can agents run raw SQL?

Not on the governed path; execute_sql is a separate, default-off tool for trusted operators.

### How do I try SQL MCP Server?

Run the Docker Compose quickstart with Docker only.

### What licence?

MIT.

### Is SQL MCP Server free?

Yes. SQL MCP Server is open source, so you can use and self-host it for free.

### How do I add SQL MCP Server to Claude Code?

Run this command in your terminal: claude mcp add sql-mcp-server --env DATABASE_DSN='<DATABASE_DSN>' -- docker run -i --rm -e DATABASE_DSN ghcr.io/nethinwei/sql-mcp-server:0.1.21

### What are the best alternatives to SQL MCP Server?

The closest alternatives to SQL MCP Server are REA, AiSOC, x64dbg-mcp-server, redamon and Treasure Map.

## Where this comes from

- Description: written from the project's README.
- Install steps: from the official MCP Registry entry.

## Alternatives

- [REA](https://ai-powered.com/mcp/rea): REA is an open-source MCP server for developer tools.
- [AiSOC](https://ai-powered.com/mcp/aisoc): AiSOC is an open-source MCP server for ai models and llm tooling.
- [x64dbg-mcp-server](https://ai-powered.com/mcp/x64dbg-mcp-server): x64dbg-mcp-server is an open-source MCP server for ai models and llm tooling.
- [redamon](https://ai-powered.com/mcp/redamon): redamon is an open-source MCP server for ai models and llm tooling.
- [Treasure Map](https://ai-powered.com/mcp/treasure-map): Treasure Map is an open-source MCP server for security.
- [Agent Roast](https://ai-powered.com/mcp/agent-roast): Agent Roast is an open-source MCP server for developer tools.
- [NostrPulse](https://ai-powered.com/mcp/nostrpulse): NostrPulse is an open-source MCP server for finance and payments.
- [Runeward](https://ai-powered.com/mcp/runeward): Runeward is an open-source MCP server for developer tools.

---
Source: https://ai-powered.com/mcp/sql-mcp-server
