Skip to main content

MCP server bridge for SQL operations (SQLite, PostgreSQL, MySQL)

Project description

MCP SQL Bridge

Local-SQL-Insight — Give your AI assistant direct, read-only access to your SQL databases over the Model Context Protocol. No APIs, no cloud. Your data stays on your machine.


Why use this?

  • Schema-aware AI — The agent sees table names, columns, and full CREATE TABLE DDL so it can write correct SQL.
  • Business context — Expose a project README.md as a resource so the AI understands your domain and conventions.
  • Read-only by design — Only SELECT is allowed. No accidental writes or schema changes.
  • Stdio transport — Works with Cursor, Claude Desktop, and any MCP host. No ports or network setup.
  • Multi-database (Pro) — Use the same tools against SQLite, PostgreSQL, and MySQL by switching a backend and connection string.

Quick start

git clone <your-repo-url>
cd mcp-sql-bridge
poetry install

Then plug the server into your editor or desktop app (see below).

Run & test: See RUN_AND_TEST.md for how to run the MCP server, the web server, unit tests, and Docker-based integration tests (e.g. poetry run python scripts/run_docker_integration.py).

Web server (optional)

A small FastAPI app provides a landing page, Swagger UI, and documentation (MkDocs):

poetry install --with web
mkdocs build          # build docs (optional; without this, /documentation shows build instructions)
poetry run mcp-sql-bridge-web

Open http://localhost:8000 for the home page, http://localhost:8000/docs for Swagger, http://localhost:8000/redoc for ReDoc, and http://localhost:8000/documentation for the full docs site (after mkdocs build).


How to use with Cursor

  1. Install the server (if not already):

    cd /path/to/mcp-sql-bridge
    poetry install
    
  2. Configure MCP
    Open Cursor Settings → Tools & MCP (or edit the config file directly).
    Add the server using the template in mcp-config.json in this repo:

    • Option A — Global config
      Put the contents of mcp-config.json into:

      • macOS / Linux: ~/.cursor/mcp.json
      • Windows: %APPDATA%\Cursor\mcp.json
    • Option B — Project config
      Copy mcp-config.json into your project as .cursor/mcp.json (and adjust the cwd path to this repo if needed).

  3. Set the path
    In the config, set cwd (or the path in args) to the absolute path of your mcp-sql-bridge project directory so Cursor can run poetry run mcp-sql-bridge from there.

  4. Restart Cursor
    MCP servers load at startup. Restart Cursor after changing the config.

  5. Use it
    In any chat, the AI can call Local-SQL-Insight tools: list_tables, execute_readonly_query, and read the Database README resource.

    • For SQLite, point it at a file path (e.g. ./data/app.db) with backend: "sqlite" or by omitting backend.
    • For PostgreSQL/MySQL (Pro), provide a backend and connection_string URL.

How to use with Claude Desktop

  1. Install the server (if not already):

    cd /path/to/mcp-sql-bridge
    poetry install
    
  2. Locate Claude’s config file

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
  3. Add the MCP server
    Add a mcpServers entry (or merge into existing) like this, using the absolute path to your mcp-sql-bridge directory:

    {
      "mcpServers": {
        "local-sql-insight": {
          "command": "poetry",
          "args": ["run", "mcp-sql-bridge"],
          "cwd": "/absolute/path/to/mcp-sql-bridge"
        }
      }
    }
    

    If Claude Desktop uses a different Python environment, you can instead use the full path to the mcp-sql-bridge executable in the project’s virtualenv, for example:

    {
      "mcpServers": {
        "local-sql-insight": {
          "command": "/absolute/path/to/mcp-sql-bridge/.venv/bin/mcp-sql-bridge",
          "args": []
        }
      }
    }
    
  4. Restart Claude Desktop
    Restart the app so it picks up the new MCP config.

  5. Use it
    Claude can use the list_tables and execute_readonly_query tools and read the Database README resource.

    • For SQLite, use your SQLite file path (e.g. ~/project/data/app.db).
    • For PostgreSQL/MySQL, supply connection URLs when the model asks for database details.

What the server provides

Capability Description
list_tables Lists every table, its columns, and the full CREATE TABLE statement. Supports `backend: "sqlite"
execute_readonly_query Runs a SELECT query and returns results as a formatted text table. Supports all backends via backend and connection_string / db_path.
schema_summary Compact overview of tables and key columns for a quick schema scan.
sample_rows Limited sample rows from a given table to understand data shape and example values.
explain_database High-level explanation of the database based on its schema.
suggest_indexes_for_query Heuristic index suggestions for a given SELECT query (no writes).
Database README (resource) Serves README.md from the server’s current working directory so the AI can read your project’s business context.
Database README template (resource) A markdown template for per-database README files (owners, conventions, key tables, gotchas).

For SQLite, the server validates that paths point to real SQLite files (magic header check) and returns clear errors if a path is wrong or not a database.
For PostgreSQL/MySQL, it validates connections and reports connection/auth errors clearly; use read-only roles in production.

Connection strings (PostgreSQL & MySQL)

Use the connection_string argument with backend: "postgres" or backend: "mysql" when calling list_tables or execute_readonly_query.

PostgreSQL — URL format (password in URL is optional; use env vars in production):

  • postgresql://user:password@localhost:5432/dbname
  • postgresql://user@localhost:5432/dbname (no password)
  • postgresql://localhost:5432/dbname (peer/auth trust)

MySQL — URL format:

  • mysql://user:password@localhost:3306/dbname
  • mariadb://user:password@localhost:3306/dbname

Install optional drivers: poetry install --extras postgres and/or poetry install --extras mysql (or --extras pro for both). Example MCP configs for multi-database setups are in examples/mcp-config-pro.json and examples/README.md.


Documentation

Requirements

  • Python 3.11+
  • Poetry (recommended) or pip for dependencies
  • Optional extras:
    • postgres extra for PostgreSQL (psycopg)
    • mysql extra for MySQL (pymysql)

Feedback and support

  • Bug reports and feature ideas: Open an issue.
  • Questions and discussions: GitHub Discussions.
  • Feedback from users (issues, discussions, or contact) is used to prioritize the roadmap and any future paid offerings.

Support & maintenance

  • Targeted Python: 3.11+
  • MCP: current stable versions at time of release
  • Backwards-compatible changes will be released as minor versions; breaking changes will bump the major or minor version and be noted in CHANGELOG.md.
  • The project is intended to be feature-complete after the 0.2.x line; future work will focus on fixes and compatibility updates only.

License

MIT. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_sql_bridge-1.0.0.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_sql_bridge-1.0.0-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file mcp_sql_bridge-1.0.0.tar.gz.

File metadata

  • Download URL: mcp_sql_bridge-1.0.0.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.3 Darwin/25.3.0

File hashes

Hashes for mcp_sql_bridge-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1d1894873e400433d4ddfefb9061b513001459d7ad43108f83bdd7676334f388
MD5 59b3f637368828273a2874e25600395b
BLAKE2b-256 03cbad24c59369253378a5c82369f078c6fd334e4532b0d0b49a14c88ed36afc

See more details on using hashes here.

File details

Details for the file mcp_sql_bridge-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mcp_sql_bridge-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.3 Darwin/25.3.0

File hashes

Hashes for mcp_sql_bridge-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a83dd6496cd0dcfc29e789df3a6825b28ae5774c8074983b77495662c72fa2c3
MD5 bbfe78035a93cfe6f2c39c6efe2423a4
BLAKE2b-256 ae1347744ceff675653001d066258e6123994768812aa68b8a85cb6bc7b2a6e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page