SQLx

An MCP server in Rust providing database management tools via SQLx for PostgreSQL, MySQL, and SQLite.
  • rust

0

GitHub Stars

rust

Language

6 months ago

First Indexed

3 months ago

Catalog Refreshed

Documentation & install

Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.

Installation

Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "lihongjie0209-sqlx-mcp": {
      "command": "npx",
      "args": [
        "@sqlx-mcp/sqlx-mcp",
        "--database-url",
        "postgresql://user:pass@localhost/mydb"
      ],
      "env": {
        "DATABASE_URL": "postgresql://user:pass@localhost/mydb"
      }
    }
  }
}

You are using a Model Context Protocol (MCP) server implemented in Rust that provides robust database management tools via SQLx. It supports PostgreSQL, MySQL, and SQLite, and lets you inspect, export, and safely query your databases through MCP clients with automatic configuration handling and secure credential masking.

How to use

You connect to the server using an MCP client and take advantage of its six tools to inspect and manage your databases. The server can auto-detect your database configuration, notify clients about the current setup, and support flexible usage patterns. If you run the server in a pre-configured mode (via an environment variable or command line), you can omit passing the database URL in tool calls. When you need to target a different database for a specific tool call, you can provide a per-tool database_url.

How to install

Prerequisites depend on how you want to run the server.

Option 1. Install via NPM (recommended) and run with npx or as a global binary.

Install globally via npm

npm install -g @sqlx-mcp/sqlx-mcp

Run directly with npx using a database URL

npx @sqlx-mcp/sqlx-mcp --database-url "postgresql://user:pass@localhost/mydb"

Set the database URL via an environment variable and run with npx (no installation needed)

export DATABASE_URL="postgresql://user:pass@localhost/mydb"
npx @sqlx-mcp/sqlx-mcp

Option 2. Build from Source

Prerequisites: Rust 1.70 or later and Git.

Clone the repository, build in release mode, and run the binary.

git clone https://github.com/lihongjie0209/sqlx-mcp.git
cd sqlx-mcp
cargo build --release

Run with a pre-configured database (examples)

You can start the server with a pre-configured database to simplify tool usage. Use the environment variable approach or provide the database URL at startup.

# Environment variable method
export DATABASE_URL="postgresql://user:pass@localhost/mydb"
npx @sqlx-mcp/sqlx-mcp

# Command line method
./target/release/sqlx-mcp --database-url "postgresql://user:pass@localhost/mydb"

Integrate with Claude Desktop (example configurations)

Configure Claude Desktop to automatically notify about the current database configuration. You can provide the MCP server as a tool that Claude can start and monitor.

{
  "mcpServers": {
    "sqlx-mcp": {
      "command": "npx",
      "args": ["@sqlx-mcp/sqlx-mcp"],
      "env": {
        "DATABASE_URL": "postgresql://user:pass@localhost/mydb"
      }
    }
  }
}

Notes on usage patterns

Pre-configured servers allow you to call tools without repeating the database_url parameter. If you ever need to target a different database for a single operation, you can pass a per-tool database_url in that tool call.

Security and safety considerations

The server enforces safe, read-only access for query evaluation when appropriate and uses parameterized queries where possible to reduce SQL injection risks. Database passwords are masked in logs and client notifications to protect credentials.

Additional notes

The server auto-detects database configuration at startup and informs clients about whether a database is pre-configured, how it was configured, and how to proceed with tool calls.

Available tools

get_database_info

Retrieves basic information about the connected database, such as product name, version, and connection status.

list_tables

Lists all tables with metadata, including comments and row counts.

get_table_structure

Provides detailed structure information for a specified table, including column definitions and constraints.

get_table_ddl

Exports the CREATE TABLE statements for a given table.

execute_readonly_query

Executes safe read-only SQL queries, supporting common read-only operations like SELECT, WITH (CTE), SHOW, DESCRIBE, and EXPLAIN.

execute_write_query

Executes write SQL operations such as INSERT, UPDATE, DELETE using controlled access.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational