A simple Model Context Protocol (MCP) server for interacting with SQLite databases.
- Execute SQL queries on SQLite databases
- Get database schema information
- List all tables in the database
- JSON-formatted results for easy parsing
-
Install dependencies:
pip install -r requirements.txt
-
The server is configured to work with
employees.dbin the current directory.
python mcp_sqlite_server.py employees.db-
query_database: Execute SQL queries
- Input:
{"query": "SELECT * FROM employees LIMIT 5"}
- Input:
-
get_schema: Get database schema
- Input:
{}
- Input:
-
list_tables: List all tables
- Input:
{}
- Input:
Add this to your MCP client configuration:
{
"mcpServers": {
"sqlite-employees": {
"command": "python",
"args": ["mcp_sqlite_server.py", "employees.db"],
"env": {}
}
}
}Run the test script to verify everything is working:
python test_mcp_server.pyOnce connected through an MCP client, you can use these example queries:
SELECT * FROM employees LIMIT 10SELECT COUNT(*) FROM employeesSELECT department, COUNT(*) FROM employees GROUP BY departmentPRAGMA table_info(employees)
This server executes SQL queries directly. In a production environment, consider implementing query validation and sanitization.