Skip to main content

MCP server for SQLite files. Supports Datasette-compatible metadata!

Project description

mcp-sqlite

Provide useful data to AI agents without giving them access to external systems. Compatible with Datasette for human users!

Features

  • AI agents can get the structure of all tables and columns in the SQLite database in one command - sqlite_get_catalog.
    • The catalog can be enriched with descriptions for the tables and columns using a simple YAML or JSON metadata file.
  • The same metadata file can contain canned queries to the AI to use. Each canned query will be turned into a separate MCP tool sqlite_execute_main_{tool name}.
  • AI agents can execute arbitrary SQL queries with sqlite_execute.

Quickstart

  1. Install uv.
  2. Download the sample SQLite database titanic.db.
  3. Create a metadata file titanic.yml for your dataset:
    databases:
      titanic:
        tables:
          Observation:
            description: Main table connecting passenger attributes to observed outcomes.
            columns:
              survived: "0/1 indicator whether the passenger survived."
              age: The passenger's age at the time of the crash.
              # Other columns are not documented but are still visible to the AI agent
        queries:
          get_survivors_of_age:
            title: Count survivors of a specific age
            description: Returns the total counts of passengers and survivors, both for all ages and for a specific provided age.
            sql: |-
              select
                count(*) as total_passengers,
                sum(survived) as survived_passengers,
                sum(case when age = :age then 1 else 0 end) as total_specific_age,
                sum(case when age = :age and survived = 1 then 1 else 0 end) as survived_specific_age
              from Observation
    
  4. Create an entry in your MCP client for your database and metadata
    {
        "mcpServers": {
            "sqlite": {
                "command": "uvx",
                "args": [
                    "mcp-sqlite",
                    "/absolute/path/to/titanic.db",
                    "--metadata",
                    "/absolute/path/to/titanic.yml"
                ]
            }
        }
    }
    

Your AI agent should now be able to use mcp-sqlite tools sqlite_get_catalog, sqlite_execute, and get_survivors_of_age!

Interactive exploration with MCP Inspector and Datasette

The same database and metadata files can be used to explore the data interactively with MCP Inspector and Datasette.

MCP Inspector Datasette

MCP Inspector

Use the MCP Inspector dashboard to interact with the SQLite database the same way that an AI agent would:

  1. Install npm.
  2. Run:
    npx @modelcontextprotocol/inspector uvx mcp-sqlite path/to/titanic.db --metadata path/to/titanic.yml
    

Datasette

Since mcp-sqlite metadata is compatible with the Datasette metadata file, you can also explore your data with Datasette:

uvx datasette serve path/to/titanic.db --metadata path/to/titanic.yml

Compatibility with Datasette allows both AI agents and humans to easily explore the same local data!

MCP Tools provided by mcp-sqlite

  • sqlite_get_catalog(): Tool the agent can call to get the complete catalog of the databases, tables, and columns in the data, combined with metadata from the metadata file. In an earlier iteration of mcp-sqlite, this was a resource instead of a tool, but resources are not as widely supported, so it got turned into a tool. If you have a usecase for the catalog as a resource, open an issue and we'll bring it back!
  • sqlite_execute(sql): Tool the agent can call to execute arbitrary SQL. The table results are returned as HTML. For more information about why HTML is the best format for LLMs to process, see Siu et al.
  • {canned query name}({canned query args}): A tool is created for each canned query in the metadata, allowing the agent to run predefined queries without writing any SQL.

Usage

Command-line options

usage: mcp-sqlite [-h] -m METADATA [-p PREFIX] [-v] sqlite_file

CLI command to start an MCP server for interacting with SQLite data.

positional arguments:
  sqlite_file           Path to SQLite file to serve the MCP server for.

options:
  -h, --help            show this help message and exit
  -m METADATA, --metadata METADATA
                        Path to Datasette-compatible metadata YAML or JSON file.
  -p PREFIX, --prefix PREFIX
                        Prefix for MCP tools. Defaults to no prefix.
  -v, --verbose         Be verbose. Include once for INFO output, twice for DEBUG output.

Metadata

Hidden tables

Hiding a table with hidden: true will hide it from the catalog returned by the MCP tool sqlite_get_catalog(). However, note that the table will still be accessible by the AI agent! Never rely on hiding a table from the catalog as a security feature.

Canned queries

Canned queries are each turned into a separate callable MCP tool by mcp-sqlite.

For example, a query named my_canned_query will become a tool my_canned_query.

The canned queries functionality is still in active development with more features planned for development soon:

Roadmap

Datasette query feature Supported in mcp-sqlite?
Displayed in catalog
Executable
Titles
Descriptions
Parameters
Explicit parameters ❌ (planned)
Hide SQL
Write restrictions on canned queries
Pagination ❌ (planned)
Cross-database queries ❌ (planned)
Fragments ❌ (not planned)
Magic parameters ❌ (not planned)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_sqlite-0.3.1.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_sqlite-0.3.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file mcp_sqlite-0.3.1.tar.gz.

File metadata

  • Download URL: mcp_sqlite-0.3.1.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mcp_sqlite-0.3.1.tar.gz
Algorithm Hash digest
SHA256 3fca8590bef4716b984de18cdd22c4e7e20ccff3b189cc9b1bd84a5dda84106f
MD5 2e677ee643bccc2303c77ddce91b1034
BLAKE2b-256 f8063628950c94d53afca75d234cc33e5e9d703c95a15ff19aa0375a0f72e7e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_sqlite-0.3.1.tar.gz:

Publisher: publish-to-test-pypi.yml on panasenco/mcp-sqlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mcp_sqlite-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: mcp_sqlite-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mcp_sqlite-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cb68e9c8931287b5c50bf0b3ae2a0e3065e038411ddd18bf787ff84a51973f5f
MD5 d95f6348e0a352b7aa13ac5456ca9db2
BLAKE2b-256 f980c2d50560b6d38363d27ef437b2c4829a5ebe777ceff66462a13a7d3c3067

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_sqlite-0.3.1-py3-none-any.whl:

Publisher: publish-to-test-pypi.yml on panasenco/mcp-sqlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page