ClaudiuJitea/sqlite-mcp-server
If you are the rightful owner of sqlite-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The SQLite MCP Server is a Model Context Protocol server designed to facilitate comprehensive management of SQLite databases through a standardized interface, enabling AI assistants and other MCP clients to interact seamlessly with SQLite databases.
discover_database
Complete database overview with schema, relationships, and examples.
get_schema_summary
Quick summary of all tables with basic info.
explain_table
Simple explanation of a table with examples.
smart_query
Ask questions in plain English and get answers.
show_table
Shows table structure and sample data quickly.
SQLite MCP Server
A Model Context Protocol (MCP) server that provides comprehensive SQLite database management capabilities. This server allows AI assistants and other MCP clients to interact with SQLite databases through a standardized interface.
Features
- Database Management: Create, backup, and get database information
- Table Operations: List tables, get table info, list columns with detailed metadata
- Data Querying: Execute arbitrary SQL queries with parameterization support
- Data Import/Export: Import and export data in CSV and JSON formats
- Database Schema: List indexes, triggers, and views
- Query Optimization: Get query execution plans for performance analysis
- Safety: Built-in SQL injection protection and error handling
Installation
Prerequisites
- Python 3.8 or higher
- pip (Python package installer)
Step 1: Clone the Repository
git clone https://github.com/ClaudiuJitea/sqlite-mcp-server.git
cd sqlite-mcp-server
Step 2: Install Dependencies
pip install -r requirements.txt
Step 3: Configure MCP Client
The server includes a sample configuration file (mcp_config.json
) that you can use with MCP-compatible clients like Claude Desktop or other MCP clients.
For Claude Desktop, add the following to your MCP configuration:
{
"mcpServers": {
"sqlite_explorer_server": {
"command": "python",
"args": [
"/path/to/your/sqlite_mcp_server.py"
],
"disabled": false
}
}
}
Replace /path/to/your/sqlite_mcp_server.py
with the actual path to the server file.
Usage
Running the Server
The server can be run directly for testing:
python sqlite_mcp_server.py
However, it's typically used through an MCP client like Claude Desktop.
Available Tools
The server provides the following tools:
š¤ Perfect for Small Models (Start Here!)
discover_database(db_path)
- START HERE! Complete database overview with schema, relationships, and examplesget_schema_summary(db_path)
- Quick summary of all tables with basic infoexplain_table(table_name, db_path)
- Simple explanation of a table with examplessmart_query(question, db_path)
- Ask questions in plain English and get answersshow_table(table_name, db_path)
- Shows table structure and sample data quicklylist_tables(db_path)
- Simple list of all table namesquery_database(sql, db_path)
- Run any SQL query and get results
Database Management
create_database(db_path)
- Create a new SQLite databaseget_database_info(db_path)
- Get comprehensive database informationbackup_database(db_path, backup_path)
- Create a database backup
Advanced Schema Exploration
list_columns(table_name, db_path)
- Get column information for a tableget_table_info(table_name, db_path)
- Get detailed table informationlist_indexes(db_path, table_name=None)
- List database indexeslist_triggers(db_path, table_name=None)
- List database triggerslist_views(db_path)
- List database views
Data Operations
execute_sql(sql_query, db_path, parameters=None)
- Execute SQL queries with parametersexport_data(table_name, db_path, format="csv", output_path=None, limit=None)
- Export table dataimport_data(table_name, db_path, file_path, format="csv", create_table=False)
- Import data from files
Query Analysis
get_query_plan(db_path, sql_query)
- Get query execution plan for optimization
Example Usage with MCP Client
Once configured with an MCP client, you can use natural language to interact with your SQLite databases:
"List all tables in my database at ./data/example.db"
"Show me the structure of the users table"
"Execute this SQL query: SELECT * FROM users WHERE age > 25"
"Export the products table to CSV format"
"Create a backup of my database"
š¤ Optimized for Small Models
This server is specifically designed to work well with small language models. Small models should always start with schema discovery:
Recommended Workflow for Small Models:
-
First, discover the database structure:
"Use discover_database tool with my database to understand what's in it"
-
Then explore specific tables:
"Use explain_table to understand the Customer table"
-
Finally, query the data:
"Use smart_query to show me customers from Germany"
Key Features for Small Models:
- Schema Discovery First: Tools like
discover_database
provide complete database overview - Simple Language: All tool descriptions use clear, simple language with emojis
- Guided Examples: Every response includes example queries to try next
- Error Guidance: When errors occur, tools suggest what to try instead
- Plain English Queries:
smart_query
tool accepts natural language questions
Sample Database
The repository includes Chinook_Sqlite.sqlite
, a sample database you can use for testing. This is a popular sample database that represents a digital media store.
Security Features
- Parameterized Queries: Supports parameter binding to prevent SQL injection
- Path Validation: Validates database paths and prevents unauthorized access
- Error Handling: Comprehensive error handling with detailed error messages
- Table Validation: Validates table existence before operations
Configuration Options
The server supports various configuration options through the mcp_config.json
file:
- command: Python executable path (use "python" for system Python)
- args: Path to the server script
- disabled: Whether the server is enabled
Development
Project Structure
sqlite-mcp-server/
āāā sqlite_mcp_server.py # Main server implementation
āāā mcp_config.json # MCP client configuration
āāā requirements.txt # Python dependencies
āāā Chinook_Sqlite.sqlite # Sample database
āāā README.md # This file
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Troubleshooting
Common Issues
- Server won't start: Ensure all dependencies are installed and Python path is correct
- Database connection errors: Check that the database path is accessible and valid
- Permission errors: Ensure the server has read/write permissions for the database location
Debug Mode
The server includes extensive logging. Check the console output for error messages and debugging information.
License
This project is open source. Please check the repository for license information.
Support
For issues, questions, or contributions, please visit the GitHub repository at: https://github.com/ClaudiuJitea/sqlite-mcp-server
Changelog
Version 1.0.0
- Initial release with comprehensive SQLite MCP server functionality
- Support for all major SQLite operations
- Import/Export capabilities
- Query optimization tools
- Comprehensive error handling and security features