An MCP (Model Context Protocol) server that enables LLMs to interact with SQLite databases. This server provides read-only access to any SQLite database through a set of tools for schema inspection and SQL query execution.
Built with async/await patterns using aiosqlite for non-blocking database operations.
- list_tables - Get all table names in the database
- describe_table - Get column details, types, and relationships for a specific table
- get_schema - Get complete database schema as CREATE TABLE statements
- query - Execute read-only SQL queries (SELECT only)
- Python 3.13+
- uv package manager
- Clone this repository
- Install dependencies:
uv syncThis project includes a CRM sample database for demonstration purposes.
uv run seed_database.pyThis creates crm.db with sample CRM data:
- 5 users (sales team)
- 20 companies
- 40 contacts
- 25 deals
- 30 activities
See Running the Server below.
The server uses crm.db in the same directory as the script (hardcoded).
uv run mcp dev sqlite_mcp_server.pyThis launches the MCP Inspector - a web-based debugging UI at http://localhost:5173 where you can:
- See all registered tools
- Test each tool interactively with custom inputs
- Inspect JSON responses
- Debug issues before connecting an LLM
uv run sqlite_mcp_server.pyThis starts the server in stdio mode, ready for LLM clients to connect.
Add to your Claude Desktop configuration (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"sqlite": {
"command": "uv",
"args": [
"--directory",
"/path/to/sqlite-mcp-server",
"run",
"sqlite_mcp_server.py"
]
}
}
}Returns all table names in the database.
Example response:
{
"tables": ["activities", "companies", "contacts", "deals", "users"]
}Get detailed information about a table's structure.
Parameters:
table_name(string): Name of the table to describe
Example response:
{
"table": "contacts",
"columns": [
{"name": "id", "type": "INTEGER", "nullable": false, "primary_key": true},
{"name": "first_name", "type": "TEXT", "nullable": false, "primary_key": false},
{"name": "email", "type": "TEXT", "nullable": true, "primary_key": false}
],
"foreign_keys": [
{"column": "company_id", "references_table": "companies", "references_column": "id"}
],
"indexes": []
}Returns complete database schema as CREATE TABLE statements.
Example response:
{
"schema": {
"users": "CREATE TABLE users (...)",
"companies": "CREATE TABLE companies (...)"
}
}Execute a read-only SQL query. Only SELECT statements are allowed.
Parameters:
sql(string): A SELECT SQL statement
Example response:
{
"columns": ["name", "email"],
"rows": [
["John Doe", "john@example.com"],
["Jane Smith", "jane@example.com"]
],
"row_count": 2
}Security: The server validates that queries are read-only by:
- Ensuring queries start with SELECT or WITH
- Blocking keywords like INSERT, UPDATE, DELETE, DROP, etc.
The server is hardcoded to use crm.db in the script directory. To use a different database:
- Replace
crm.dbwith your database file (keep the same name), or - Modify the
DB_PATHconstant insqlite_mcp_server.py