The USQL MCP Server bridges the Model Context Protocol with the usql CLI, enabling AI assistants to execute SQL queries and database operations across multiple database systems.
Capabilities:
Execute SQL Queries - Run arbitrary SQL statements (SELECT, INSERT, UPDATE, DELETE) with optional prepared statement parameters
Execute Multi-Statement Scripts - Run complete SQL scripts with multiple statements in sequence
List Databases - Discover all databases available on a database server
List Tables - View all tables within a specific database
Describe Table Schema - Get detailed schema information including columns, data types, and constraints
Flexible Connection Management - Connect using full database URLs (e.g., postgres://user:pass@host/db) or pre-configured connection names via environment variables/config.json, with support for default connections
Multiple Output Formats - Return results in JSON (default) or CSV format
Timeout Control - Configure query execution timeouts globally or per-request, with support for unlimited execution time
Multi-Database Support - Works with any database supported by usql (PostgreSQL, MySQL, Oracle, SQLite, SQL Server, and many others)
Raw CLI Output - Returns authentic usql output exactly as it appears on the command line
Easy Integration - Configurable for use with MCP clients such as Claude Desktop, Claude Code, Codex CLI, and GitHub Copilot
Enables execution of SQL queries and database operations against SQLite databases through the usql CLI, including query execution, table listing, and schema inspection.
USQL MCP Server
usql-mcp bridges the Model Context Protocol with the
usql CLI so assistants and other MCP clients can run queries against any
database usql supports. The server forwards tool requests directly to usql and streams the raw CLI
output back to the caller (JSON by default, CSV on request), keeping behaviour identical to what you would
see on the command line.
Requirements
Node.js 16 or newer
npmusqlinstalled and available onPATH
Quick Launch with npx
Run the server directly via npx:
This downloads the package and executes the CLI entry point, which runs the MCP server on stdio.
You can also run it directly from the repository using npm's Git support (the prepare script compiles
the TypeScript automatically):
Getting Started
The compiled files live in dist/. They are intentionally not committed—run npm run build whenever you
need fresh output.
Configuring Connections
Define connection strings via environment variables (USQL_*) or a config.json file mirroring
config.example.json. Each USQL_<NAME>=... entry becomes a reusable connection whose name is the
lower-cased <name> portion (USQL_ORACLE1 → oracle1). Reserved keys that aren’t treated as
connections are:
USQL_CONFIG_PATHUSQL_QUERY_TIMEOUT_MSUSQL_DEFAULT_CONNECTIONUSQL_BINARY_PATH
Examples:
You can also supply a full URI directly in tool requests. USQL_QUERY_TIMEOUT_MS controls the default
query timeout; leave it unset (or set defaults.queryTimeout to null) for unlimited execution and
override it when you need a guard. Individual tool calls can pass timeout_ms to override (set to
null for unlimited on that call). Set USQL_DEFAULT_CONNECTION (or defaults.defaultConnection in
config.json) to name the connection that should be used automatically when a tool call omits the
connection_string field.
If usql is not on your PATH, set USQL_BINARY_PATH to the absolute path of the executable (for
example, /usr/local/bin/usql). When unset, the MCP server assumes usql is discoverable via the
environment PATH.
Client Configuration
This section explains how to configure the usql-mcp server in different MCP clients.
Claude Desktop
Claude Desktop uses a configuration file to register MCP servers. The location depends on your operating system:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json
Add the following configuration to your claude_desktop_config.json:
After editing the configuration file, restart Claude Desktop for changes to take effect.
Claude Code
Claude Code (CLI) supports MCP servers through its configuration file located at:
All platforms:
~/.claudercor~/.config/claude/config.json
Add the MCP server to your Claude Code configuration:
The server will be available in your Claude Code sessions automatically.
Codex CLI
Codex CLI configuration varies by implementation, but typically uses a similar JSON configuration approach. Create or edit your Codex configuration file (usually ~/.codexrc or as specified in your Codex documentation):
Refer to your specific Codex CLI documentation for the exact configuration file location and format.
GitHub Copilot (VS Code)
GitHub Copilot in VS Code can use MCP servers through the Copilot Chat extension settings. Configuration is done through VS Code's settings.json:
Open VS Code Settings (JSON) via:
macOS:
Cmd + Shift + P→ "Preferences: Open User Settings (JSON)"Windows/Linux:
Ctrl + Shift + P→ "Preferences: Open User Settings (JSON)"
Add the MCP server configuration:
After saving the settings, reload VS Code or restart the Copilot extension for changes to take effect.
Environment Variables vs. Configuration
For all clients, you can choose between:
Inline environment variables (shown above) - Connection strings in the config file
System environment variables - Set
USQL_*variables in your shell profile
System environment approach:
Then use a simpler client configuration:
Security Best Practices
Avoid hardcoding credentials: Use environment variables or secure credential stores
File permissions: Ensure configuration files with credentials are not world-readable (chmod 600)
Read-only access: Create database users with minimal required permissions for AI queries
Network security: Use SSL/TLS connections for remote databases
Audit logging: Enable database audit logs to track AI-generated queries
Tool Catalogue
Tool | Purpose | Notable Inputs |
| Run an arbitrary SQL statement |
,
, optional
(
|
),
|
| Execute a multi-statement script |
,
, optional
,
|
| List databases available on the server |
, optional
,
|
| List tables in the current database |
, optional
,
|
| Inspect table metadata via
|
,
, optional
,
|
Successful calls return the exact stdout produced by usql, paired with the format indicator:
If usql exits with a non-zero code the handler forwards the message through the MCP error shape, keeping
details like the sanitized connection string and original stderr.
Development
npm run dev– TypeScript compile in watch modenpm run build– emit ESM output todist/npm run lint– ESLint/Prettier rulesnpm run test– Jest unit tests (no external services required)npm run type-check– stricttsc --noEmit
Debug logging follows the namespace in DEBUG=usql-mcp:*.
Contributing
See CONTRIBUTING.md for contributor guidelines and AGENTS.md for coding agents guidelines. Open an issue before large changes so we can keep the tooling
lean and aligned with the MCP ecosystem.