Skip to main content

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.

Metadata

Release files for iflow-mcp_prayanks-mcp-sqlite-server 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iflow-mcp_prayanks-mcp-sqlite-server 0.1.1
File Size Uploaded
iflow_mcp_prayanks_mcp_sqlite_server-0.1.1.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iflow-mcp_prayanks-mcp-sqlite-server 0.1.1
File Interpreter ABI Platform
iflow_mcp_prayanks_mcp_sqlite_server-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.8 kB

Release files / iflow_mcp_prayanks_mcp_sqlite_server-0.1.1.tar.gz

Download URL iflow_mcp_prayanks_mcp_sqlite_server-0.1.1.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
08a153d18aa5bdb364af22f258cb86a3fee4b8330cdc42887c532b3137d67a8d
BLAKE2b-256 checksum
How to use checksums
a09fbb2dd028d3ed4dbd46ed4c00ec151b455335e96328cd9d38f8b49aab4c4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / iflow_mcp_prayanks_mcp_sqlite_server-0.1.1-py3-none-any.whl

Download URL iflow_mcp_prayanks_mcp_sqlite_server-0.1.1-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0294f38a4fd93892168efb361a8b6c396c49aa86744d11a166fc62f4ee50c25c
BLAKE2b-256 checksum
How to use checksums
59ef0a88903a0ad3054971aafe1638dde9322df9ffca0035580ee1ef3d9190e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page