Skip to main content

SQLsaber - Open-source agentic SQL assistant

Project description

SQLsaber

SQLsaber is an open-source agentic SQL assistant. Think Claude Code but for SQL.

demo

Stop fighting your database.

Ask your questions in natural language and sqlsaber will gather the right context automatically and answer your query by writing SQL and analyzing the results.

Table of Contents

Features

  • 🔍 Automatic database schema introspection
  • 🛡️ Safe query execution (read-only by default)
  • 🧠 Memory management
  • 💬 Interactive REPL mode
  • 🧵 Conversation threads (store, display, and resume conversations)
  • 🗄️ Support for PostgreSQL, SQLite, and MySQL
  • 🔌 MCP (Model Context Protocol) server support
  • 🎨 Beautiful formatted output

Installation

uv

uv tool install sqlsaber

pipx

pipx install sqlsaber

brew

brew install uv
uv tool install sqlsaber

Configuration

Database Connection

Set your database connection URL:

saber db add DB_NAME

This will ask you some questions about your database connection

AI Model Configuration

SQLSaber uses Sonnet-4 by default. You can change it using:

saber models set

# for more model settings run:
saber models --help

Memory Management

You can add specific context about your database to the model using the memory feature. This is similar to how you add memory/context in Claude Code.

saber memory add 'always convert dates to string for easier formating'

View all memories

saber memory list

You can also add memories in an interactive query session by starting with the # sign

Usage

Interactive Mode

Start an interactive session:

saber

You can also add memories in an interactive session by starting your message with the # sign

Single Query

Execute a single natural language query:

saber "show me all users created this month"

You can also pipe queries from stdin:

echo "show me all users created this month" | saber
cat query.txt | saber

Resume Past Conversation

Continue a previous conversation thread:

saber threads resume THREAD_ID

Database Selection

Use a specific database connection:

# Interactive mode with specific database
saber -d mydb

# Single query with specific database
saber -d mydb "count all orders"

# You can also pass a connection string
saber -d "postgresql://user:password@localhost:5432/mydb" "count all orders"

Examples

# Start interactive mode
saber

# Non-interactive mode
saber "show me orders with customer details for this week"

saber "which products had the highest sales growth last quarter?"

MCP Server Integration

SQLSaber includes an MCP (Model Context Protocol) server that allows AI agents like Claude Code to directly leverage tools available in SQLSaber.

Starting the MCP Server

Run the MCP server using uvx:

uvx --from sqlsaber saber-mcp

Configuring MCP Clients

Claude Code

Add SQLSaber as an MCP server in Claude Code:

claude mcp add sqlsaber -- uvx --from sqlsaber saber-mcp

Other MCP Clients

For other MCP clients, configure them to run the command: uvx --from sqlsaber saber-mcp

Available MCP Tools

Once connected, the MCP client will have access to these tools:

  • get_databases() - Lists all configured databases
  • list_tables(database) - Get all tables in a database with row counts
  • introspect_schema(database, table_pattern?) - Get detailed schema information
  • execute_sql(database, query, limit?) - Execute SQL queries (read-only)

The MCP server uses your existing SQLSaber database configurations, so make sure to set up your databases using saber db add first.

How It Works

SQLsaber uses a multi-step agentic process to gather the right context and execute SQL queries to answer your questions:

🔍 Discovery Phase

  1. List Tables Tool: Quickly discovers available tables with row counts
  2. Pattern Matching: Identifies relevant tables based on your query

📋 Schema Analysis

  1. Smart Schema Introspection: Analyzes only the specific table structures needed for your query

⚡ Execution Phase

  1. SQL Generation: Creates optimized SQL queries based on natural language input
  2. Safe Execution: Runs read-only queries with built-in protections against destructive operations
  3. Result Formatting: Presents results with explanations in tables

Contributing

If you like the project, starring the repo is a great way to show your support!

Other contributions are welcome! Please feel free to open an issue to discuss your ideas or report bugs.

License

This project is licensed under Apache-2.0 License - see the LICENSE file for details.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

sqlsaber-0.20.0.tar.gz (4.1 MB view details)

Uploaded Source

Built Distribution

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

sqlsaber-0.20.0-py3-none-any.whl (75.3 kB view details)

Uploaded Python 3

File details

Details for the file sqlsaber-0.20.0.tar.gz.

File metadata

  • Download URL: sqlsaber-0.20.0.tar.gz
  • Upload date:
  • Size: 4.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.16

File hashes

Hashes for sqlsaber-0.20.0.tar.gz
Algorithm Hash digest
SHA256 1f4a0a740ad0a6dc63544e4fd261745985e4d08d05d4757d381d5f71aa103335
MD5 c8dc393764d1908fb99036f870facfa7
BLAKE2b-256 94bf84625d51021a55b7cd75ef0bdf93eb7454049008106f1d47131c21ec96a9

See more details on using hashes here.

File details

Details for the file sqlsaber-0.20.0-py3-none-any.whl.

File metadata

  • Download URL: sqlsaber-0.20.0-py3-none-any.whl
  • Upload date:
  • Size: 75.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.16

File hashes

Hashes for sqlsaber-0.20.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aed4e90b5eb00d4d1c52362abe1b859161f9daaa199b3b0f83b66b70d6d71c45
MD5 cc10580d88a54a9449d326ffdb1e7429
BLAKE2b-256 b27178d58b8b789fddafec66c70ef78fbd58b8cd440126ce91a3ab1aee04859a

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