Making local data equally accessible to AI agents and humans. Datasette-compatible!
Project description
mcp-sqlite
Provide useful data to AI agents without giving them access to external systems. Datasette-compatible!
Quickstart
- Install uv.
- Create or download a SQLite database file.
- Optionally create a metadata file for your dataset. See Datasette metadata docs for details.
- Create an entry in your MCP client for your database and metadata
{ "mcpServers": { "sqlite": { "command": "uvx", "args": [ "mcp-sqlite", "/absolute/path/to/database.db", "--metadata", "/absolute/path/to/metadata.yml" ] } } }
Your AI agent should now be able to use mcp-sqlite tools like sqlite_get_catalog and sqlite_execute!
Exploring with MCP Inspector
Use the MCP Inspector dashboard to interact with the SQLite database the same way that an AI agent would:
- Install npm.
- Run:
npx @modelcontextprotocol/inspector uvx mcp-sqlite path/to/database.db --metadata path/to/metadata.yml - Open the MCP Inspector dashboard URL that's outputted in your terminal window.
Exploring with 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/data.db --metadata path/to/metadata.yml
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, as that is the format LLMs seem to perform best with according to Siu et al.
- sqlite_execute_main_{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-server [-h] [-m METADATA] [-w] [-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 JSON file.
-w, --write Set this flag to allow the AI agent to write to the database. By default the database is opened in read-only
mode.
-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 get_catalog() MCP tool.
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 sqlite_execute_main_my_canned_query.
The canned queries functionality is still in active development with more features planned for development soon:
| Datasette canned query feature | Supported in mcp-sqlite? |
|---|---|
| Displayed in catalog | ✅ |
| Executable | ✅ |
| Titles | ❌ (planned) |
| Descriptions | ❌ (planned) |
| Parameters | ✅ |
| Explicit parameters | ❌ (planned) |
| Hide SQL | ❌ (planned) |
| Fragments | ❌ (not planned) |
| Write restrictions on canned queries | ❌ (planned) |
| Magic parameters | ❌ (not planned) |
This will open up a Datasette dashboard where you can see the exact same descriptions and sample queries that the LLM would see. Compatibility with Datasette allows both humans and AI to interact with the same local data!
Developing
- Clone this repo locally.
- Run
uv venvto create the Python virtual environment. Then runsource .venv/bin/activateon Unix or.venv\Scripts\activateon Windows. - Run the server with MCP Inspector
(you'll have to install Node.js and npm first):
npx @modelcontextprotocol/inspector uv run mcp_sqlite/server.py test.db --metadata test.yml
- Run
python -m pytestto run tests. - Run
ruff formatto format Python code. - Run
pyrightfor static type checking.
Publishing
Tagging a commit with a release candidate tag (containing rc) will trigger build and upload to TestPyPi.
Tagging a commit with a non-release candidate tag (not containing rc) will trigger build and upload to PyPi.
Note that Python package version numbers are NOT SemVer! See Python packaging versioning.
To test that the package works on TestPyPi, use: uvx --default-index https://test.pypi.org/simple/ --index https://pypi.org/simple/ mcp-sqlite@0.1.0rc2 --help (replacing 0.1.0rc2 with your own version number).
Similarly, to test the TestPyPi package with MCP inspector, use: npx @modelcontextprotocol/inspector uvx --default-index https://test.pypi.org/simple/ --index https://pypi.org/simple/ mcp-sqlite@0.1.0rc2 test.db --metadata test.yml.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_sqlite-0.1.0.tar.gz.
File metadata
- Download URL: mcp_sqlite-0.1.0.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53e64f466e476bff984cd6915ccd47861e1abc102944eb2100b2326f6c7d107b
|
|
| MD5 |
1e00af13a6f7b4880326de33b194dd83
|
|
| BLAKE2b-256 |
797f3d392ef6b18da9c88f9d733092a36694d932f1e1bee5840f67a915423ae4
|
Provenance
The following attestation bundles were made for mcp_sqlite-0.1.0.tar.gz:
Publisher:
publish-to-test-pypi.yml on panasenco/mcp-sqlite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_sqlite-0.1.0.tar.gz -
Subject digest:
53e64f466e476bff984cd6915ccd47861e1abc102944eb2100b2326f6c7d107b - Sigstore transparency entry: 229907719
- Sigstore integration time:
-
Permalink:
panasenco/mcp-sqlite@cc3332c593d38a2c8fc2d644d7484cd07be9be1f -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/panasenco
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-test-pypi.yml@cc3332c593d38a2c8fc2d644d7484cd07be9be1f -
Trigger Event:
push
-
Statement type:
File details
Details for the file mcp_sqlite-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mcp_sqlite-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2038f5bce0c74bb19000caebd05981fe3565443155ae5ca51abe7a4219ace0b0
|
|
| MD5 |
dca1f18e337c20abd23e3272e31063cd
|
|
| BLAKE2b-256 |
cf24a5ff7c7b91ba04b8dacebd742b55f240caec9d68b3bdbb09248e3381bf66
|
Provenance
The following attestation bundles were made for mcp_sqlite-0.1.0-py3-none-any.whl:
Publisher:
publish-to-test-pypi.yml on panasenco/mcp-sqlite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_sqlite-0.1.0-py3-none-any.whl -
Subject digest:
2038f5bce0c74bb19000caebd05981fe3565443155ae5ca51abe7a4219ace0b0 - Sigstore transparency entry: 229907721
- Sigstore integration time:
-
Permalink:
panasenco/mcp-sqlite@cc3332c593d38a2c8fc2d644d7484cd07be9be1f -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/panasenco
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-test-pypi.yml@cc3332c593d38a2c8fc2d644d7484cd07be9be1f -
Trigger Event:
push
-
Statement type: