This MCP server allows you to connect SQLite databases to language models using the Model Context Protocol. It provides access to database schemas, SQL query execution capabilities, and helpful prompt templates for data analysis, all through a standardized interface.
Before using the SQLite MCP server, you'll need to set up a sample database and prepare your environment.
Create a database with sample startup funding data:
create_db.py
:import sqlite3
import os
# Create database file
db_path = "startups.db"
if os.path.exists(db_path):
os.remove(db_path)
# Connect to database
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Create tables
cursor.execute('''
CREATE TABLE startups (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
industry TEXT,
founding_year INTEGER,
location TEXT,
founder TEXT,
funding_amount REAL,
funding_round TEXT
)
''')
# Insert sample data
sample_data = [
(1, "TechNova", "AI", 2020, "San Francisco", "Alex Smith", 5000000, "Series A"),
(2, "GreenEnergy", "Renewable Energy", 2018, "Boston", "Maria Chen", 12000000, "Series B"),
(3, "HealthPlus", "Healthcare", 2019, "New York", "James Wilson", 3000000, "Seed"),
(4, "FoodDeliveryX", "Food Tech", 2021, "Chicago", "Sarah Johnson", 8000000, "Series A"),
(5, "CryptoFinance", "Fintech", 2017, "Miami", "Michael Brown", 15000000, "Series B")
]
cursor.executemany('''
INSERT INTO startups (id, name, industry, founding_year, location, founder, funding_amount, funding_round)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
''', sample_data)
# Commit changes and close connection
conn.commit()
conn.close()
print(f"Database created at {db_path} with sample startup data.")
python create_db.py
python -m venv venv
macOS/Linux:
source venv/bin/activate
Windows:
venv\Scripts\activate
pip install "mcp[cli]"
Save your server code as sqlite_mcp_server.py
and run:
python sqlite_mcp_server.py
To integrate with Claude Desktop:
{
"mcpServers": {
"sqlite_mcp_server": {
"command": "python",
"args": ["-u", "/absolute/path/to/sqlite_mcp_server.py"]
}
}
}
The server exposes database schemas as resources that Claude can access:
schema://sqlite/all
- Get schemas for all tablesschema://sqlite/startups
- Get schema for the startups table onlyYou can run SQL queries on the database using the sql_query
tool. Only SELECT statements are allowed:
SELECT * FROM startups WHERE funding_amount > 10000000;
SELECT name, industry, funding_amount
FROM startups
ORDER BY funding_amount DESC
LIMIT 3;
The server provides prompt templates to help with:
These templates help Claude generate more informative and accurate responses when working with the database.
If you encounter issues:
The server logs to stderr by default, which can help diagnose problems.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.