A Model Context Protocol (MCP) server that provides SQLite database access through standardized tools. This server allows AI assistants to interact with SQLite databases by listing tables, describing schemas, and executing queries.
This MCP server was written using Claude Desktop and the Claude Sonnet 4. This README was generated by Claude Sonnet 4 based on the files in this repo.
- List Tables: View all tables in the connected SQLite database
- Describe Schema: Get detailed table structure including column types, constraints, and primary keys
- Execute Queries: Run SELECT, INSERT, UPDATE, DELETE, and other SQL commands
- Error Handling: Comprehensive error handling with detailed logging
- Safe Operations: Built-in protections and query validation
- Python 3.8 or higher
- pip package manager
- Clone this repository:
git clone https://github.com/makeralchemy/claude-desktop-mcp-sqlite
cd mcp-sqlite- Create a virtual environment:
python -m venv venv- Activate the virtual environment:
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate- Install dependencies:
pip install -r requirements.txtEdit mcpsqlite.py and modify the DB_PATH variable to point to your SQLite database:
DB_PATH = r"path/to/your/database.db"Add the server configuration to your Claude Desktop config file:
Location of config file:
- Windows:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
Configuration:
{
"mcpServers": {
"sqlite": {
"command": "/path/to/your/venv/Scripts/python.exe",
"args": [
"/path/to/your/mcpsqlite.py"
]
}
}
}Replace the paths with your actual installation paths.
Once configured, the server provides three main tools that can be used through Claude Desktop:
Lists all tables in the connected database.
Example usage:
"Show me all tables in the database"
Provides detailed schema information for a specific table.
Parameters:
table_name(string): Name of the table to describe
Example usage:
"Describe the structure of the 'users' table"
Executes SQL queries against the database.
Parameters:
query(string): SQL query to execute
Example usage:
"SELECT * FROM users WHERE age > 21"
"UPDATE products SET price = 29.99 WHERE id = 1"
mcp-sqlite/
├── mcpsqlite.py # Main MCP server implementation
├── claude_desktop_config.json # Example configuration
├── mcp_sqlite.log # Log file (generated at runtime)
├── venv/ # Virtual environment
└── README.md # This file
The server automatically logs all operations to both:
- Console output
mcp_sqlite.logfile
Log entries include:
- Tool requests and executions
- Database connection status
- Error messages and stack traces
- Query execution results
The server includes robust error handling for:
- Missing database files
- Invalid SQL queries
- Connection failures
- Missing required parameters
- SQLite-specific errors
All errors are logged and returned as descriptive messages to the client.
- Database Access: The server has full read/write access to the configured database
- Query Validation: Basic validation is performed, but consider additional restrictions for production use
- File Permissions: Ensure the database file has appropriate access permissions
- Network Security: This server is designed for local use with Claude Desktop
- Activate your virtual environment
- Run the server directly:
python mcpsqlite.pyYou can test the server functionality by:
- Configuring it with Claude Desktop
- Using the MCP Inspector tool
- Running direct SQLite queries to verify database access
Server not connecting:
- Verify the Python path in your configuration
- Check that the virtual environment is properly set up
- Ensure all dependencies are installed
Database not found:
- Verify the
DB_PATHinmcpsqlite.pypoints to your database - Check file permissions on the database file
- Ensure the database file exists and is accessible
Tool execution fails:
- Check the
mcp_sqlite.logfile for detailed error messages - Verify your SQL syntax for query operations
- Ensure table names are spelled correctly
Check mcp_sqlite.log for detailed information about:
- Server startup and initialization
- Tool execution attempts
- Database connection status
- Specific error messages
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License
For issues and questions:
- Check the troubleshooting section above
- Review the log files for error details
- Open an issue on GitHub with relevant log entries