USQL MCP Server
Enables AI assistants to execute SQL queries against any database supported by the usql CLI tool. Provides seamless database interaction through MCP by forwarding queries directly to usql and returning results in JSON or CSV format.
README
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:
npx usql-mcp
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):
npx github:jvm/usql-mcp
Getting Started
git clone https://github.com/yourusername/usql-mcp.git
cd usql-mcp
npm install
npm run build
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:
export USQL_POSTGRES="postgres://user:password@localhost:5432/mydb"
export USQL_SQLITE="sqlite:///$(pwd)/data/app.db"
export USQL_ORACLE1="oracle://user:secret@host1:1521/service"
export USQL_ORACLE2="oracle://user:secret@host2:1521/service"
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.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
Add the following configuration to your claude_desktop_config.json:
{
"mcpServers": {
"usql": {
"command": "npx",
"args": ["usql-mcp"],
"env": {
"USQL_POSTGRES": "postgres://user:password@localhost:5432/mydb",
"USQL_SQLITE": "sqlite:///path/to/database.db",
"USQL_DEFAULT_CONNECTION": "postgres",
"USQL_QUERY_TIMEOUT_MS": "30000"
}
}
}
}
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:
{
"mcpServers": {
"usql": {
"command": "npx",
"args": ["-y", "usql-mcp"],
"env": {
"USQL_POSTGRES": "postgres://user:password@localhost:5432/mydb",
"USQL_DEFAULT_CONNECTION": "postgres"
}
}
}
}
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):
{
"mcp": {
"servers": {
"usql": {
"command": "npx",
"args": ["-y", "usql-mcp"],
"env": {
"USQL_POSTGRES": "postgres://user:password@localhost:5432/mydb",
"USQL_MYSQL": "mysql://user:password@localhost:3306/mydb"
}
}
}
}
}
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)"
- macOS:
-
Add the MCP server configuration:
{
"github.copilot.chat.mcp.servers": {
"usql": {
"command": "npx",
"args": ["-y", "usql-mcp"],
"env": {
"USQL_POSTGRES": "postgres://user:password@localhost:5432/mydb",
"USQL_SQLITE": "sqlite:///absolute/path/to/database.db",
"USQL_DEFAULT_CONNECTION": "postgres"
}
}
}
}
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:
# In ~/.bashrc, ~/.zshrc, or equivalent
export USQL_POSTGRES="postgres://user:password@localhost:5432/mydb"
export USQL_SQLITE="sqlite:///path/to/database.db"
export USQL_DEFAULT_CONNECTION="postgres"
Then use a simpler client configuration:
{
"mcpServers": {
"usql": {
"command": "npx",
"args": ["-y", "usql-mcp"]
}
}
}
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 |
|---|---|---|
execute_query |
Run an arbitrary SQL statement | connection_string, query, optional output_format (json|csv), timeout_ms |
execute_script |
Execute a multi-statement script | connection_string, script, optional output_format, timeout_ms |
list_databases |
List databases available on the server | connection_string, optional output_format, timeout_ms |
list_tables |
List tables in the current database | connection_string, optional output_format, timeout_ms |
describe_table |
Inspect table metadata via \d |
connection_string, table, optional output_format, timeout_ms |
Successful calls return the exact stdout produced by usql, paired with the format indicator:
{
"format": "json", // or "csv"
"content": "[{\"id\":1}]"
}
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 AGENTS.md for contributor guidelines. Open an issue before large changes so we can keep the tooling
lean and aligned with the MCP ecosystem.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。