Fire in da houseTop Tip:Most people pay up to $340 per month for Perplexity, MidJourney, Runway, ChatGPT, and more - but you can get them all your AI tools for $15 with Galaxy. It's free to test!Fire in da houseCheck it out

mcp-sqlite-server

MCP.Pizza Chef: prayanks

The mcp-sqlite-server is a Python-based MCP server that connects to a SQLite database, exposing table schemas and providing a read-only SQL query interface. It supports both SDIO and SSE protocols, enabling MCP clients and LLMs to perform structured data analysis and querying on startup funding data. The server includes prompt templates for common data tasks and integrates seamlessly with MCP clients like Claude Desktop.

Use This MCP server To

Query SQLite databases via MCP clients using natural language Expose database schemas as structured resources for LLMs Perform read-only SQL queries on startup funding data Integrate SQLite data access into AI-enhanced workflows Use prompt templates for common data analysis tasks Connect MCP clients to SQLite databases with SDIO or SSE protocols Enable LLMs to analyze and summarize database content Test and log SQL query interactions within MCP environments

README

SQLite MCP Server

This repository contains an MCP (Model Context Protocol) server written in Python that connects to a SQLite database containing startup funding data. The server exposes table schemas as resources, provides a read-only SQL query tool, and offers prompt templates for common data analysis tasks. It is designed to work with MCP clients and language models (LLMs) and communicates via the STDIO protocol.

Table of Contents


Overview

The MCP server uses the MCP Python SDK (with CLI extras) to implement a server that:

  • Connects to a SQLite database (e.g., a database with startup funding information).
  • Exposes table schemas as MCP resources.
  • Provides a tool for executing read-only SQL queries.
  • Offers prompt templates that help language models generate data analysis insights.
  • Communicates via the STDIO protocol, reading JSON-RPC messages from standard input and writing responses to standard output.

Features

  • Resources

    • schema://sqlite/{table}: Returns the SQL schema for a specific table.
    • schema://sqlite/all: Returns a JSON mapping of all table schemas.
  • Tools

    • sql_query: Executes read-only SQL queries. Only SELECT statements are permitted.
  • Prompts

    • analyze_table_prompt: Generates an analysis prompt for a specific table.
    • describe_query_prompt: Generates a prompt explaining a SQL query.
  • STDIO Protocol

    • Reads from stdin and writes responses to stdout, making integration easy.
  • Logging

    • Uses Python’s logging module to trace activity and debug errors.

Setup and Installation

Creating the Sample SQLite Database

Save the following script as create_db.py:

<same as earlier>

Run with:

python create_db.py

Creating a Virtual Environment

python -m venv venv

Activate the environment:

  • macOS/Linux:

    source venv/bin/activate
  • Windows:

    venv\Scripts\activate

Install dependencies:

pip install "mcp[cli]"

Running the MCP Server

  1. Save your server code as sqlite_mcp_server.py.
  2. Run the server:
python sqlite_mcp_server.py

Optional (using uv):

uv run sqlite_mcp_server.py

Installing into Claude Desktop

Save the following as install_to_claude.py and run it:

python install_to_claude.py

Update Claude Desktop config with:

{
  "mcpServers": {
    "sqlite_mcp_server": {
      "command": "python",
      "args": ["-u", "/absolute/path/to/sqlite_mcp_server.py"]
    }
  }
}

Restart Claude Desktop afterward.


Usage

  • Access Resources: schema://sqlite/all, schema://sqlite/startups
  • Invoke Tools:
    SELECT * FROM startups WHERE funding_amount > 10000000;
  • Use Prompts: Generate SQL or explain queries.

Testing

Run the test script:

python sqlite_mcp_client_tests.py sqlite_mcp_server.py

This script tests:

  • Listing resources
  • Retrieving schemas
  • Valid/invalid queries
  • Prompt templates

Logging

Modify logging config:

logging.basicConfig(
    filename='mcp_server.log',
    level=logging.DEBUG,
    format="[%(asctime)s] %(levelname)s - %(message)s",
    datefmt="%Y-%m-%d %H:%M:%S"
)

Logs print to stderr by default.


License

This project is licensed under the MIT License. See the LICENSE file.


Additional Notes

  • Adjust paths in installation/config scripts as needed.
  • Ensure the SQLite database is created before running the server.
  • Integrates with MCP Inspector or Claude Desktop.

mcp-sqlite-server FAQ

How do I set up the mcp-sqlite-server?
Follow the README instructions to create a sample SQLite database, set up a Python virtual environment, and run the server using the provided commands.
Can the mcp-sqlite-server modify the database?
No, it provides read-only SQL query access to ensure data integrity and security.
Which protocols does the mcp-sqlite-server support?
It supports both SDIO and SSE protocols for communication with MCP clients.
How does the server expose database schemas?
It exposes table schemas as MCP resources, allowing LLMs to understand the database structure.
Can I use the mcp-sqlite-server with different LLM providers?
Yes, it is compatible with various LLMs including OpenAI, Claude, and Gemini through MCP clients.
Is there support for prompt templates?
Yes, the server includes prompt templates for common data analysis tasks to simplify querying.
How do I integrate this server with MCP clients like Claude Desktop?
Installation instructions for Claude Desktop are provided in the README to enable seamless integration.
Does the server provide logging capabilities?
Yes, it includes logging features to track SQL query interactions and server activity.