About SQLite Database Demo
SQLite Database Demo shows how to use an asynchronously operated SQLite database in a FastMCP application. It is for developers exploring MCP server and client examples, and includes an automatically initialized sample database with a tool for retrieving user data.
Key features
- 01Async database operations with aiosqlite
- 02Automatic database and sample-data initialization
- 03Type-safe database context management
- 04Connection lifecycle handling and cleanup
Use cases
- 01Learn async SQLite use in FastMCP
- 02Test retrieving user data through an MCP tool
MCP support
The project demonstrates an MCP server built with FastMCP and exposes the `query_db` tool to retrieve database users.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMESQLite Database Demo
This project demonstrates the usage of SQLite database with async support in a FastMCP application.
Features
- Async SQLite database operations using
aiosqlite - Automatic database initialization with sample data
- Type-safe database context management
- Proper connection lifecycle handling
Prerequisites
- Python 3.7+
- pip (Python package installer)
Installation
- Clone this repository
- Install the required dependencies:
pip install -r requirements.txt
Project Structure
server.py: Main FastMCP server implementation with database context managementdatabase.py: SQLite database implementation with async supportdemo.db: SQLite database file (created automatically on first run)
Database Schema
The demo database includes a users table with the following structure:
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL
)
Sample data is automatically inserted on first run:
- John Doe ([email protected])
- Jane Smith ([email protected])
Usage
- Start the server:
python server.py
-
The database will be automatically initialized with the sample data on first run.
-
Use the
query_dbtool to retrieve data from the database.
Database Operations
The Database class provides the following methods:
connect(): Creates a new database connection and initializes the schemaquery(): Executes a sample query to retrieve all usersdisconnect(): Closes the database connection
Customization
To modify the database schema or add new tables:
- Edit the
_init_db()method indatabase.py - Add new methods to
Databaseclass for custom queries - Update the
query_dbtool inserver.pyto use new methods
Error Handling
The database implementation includes:
- Automatic connection cleanup on server shutdown
- Proper async context management
- Type safety with Python type hints
Dependencies
- aiosqlite>=0.19.0: Async SQLite database driver
- pandas>=2.0.0: Data manipulation library
- numpy>=1.24.0: Numerical computing library
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.