SQLite Database Demo
About
Some examples to build server, client test in model context protocol. Một số ví dụ sử dụng MCP
Details
- Author
- anhnx000
- Downloads
- 447
- Categories
- Database
Jump to
- Async SQLite operations via aiosqlite
- Automatic database creation and sample data insertion
- Type‑safe database context management
- Proper connection lifecycle handling (cleanup on shutdown)
- Simple query_db tool for retrieving all users
Setting up with Highlight
This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:
- Download and install Highlight from highlightai.com/download
- Navigate to the plugins tab and select "Add Custom Plugin"
-
Configure the plugin with the settings below
Plugin Name
SQLite Database DemoCommand (node, npx, python, etc.)Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.
- Enable "Start Automatically" if you want the plugin to start when Highlight launches
From the repository
Clone the repository, install dependencies (pip install -r requirements.txt), then start the server with python server.py. On first run the database is automatically created and populated with sample data. Use the built‑in query_db tool to query all users.
Claude Desktop / Cursor
Paste into your MCP client config file to install this server.
{
"mcpServers": {
"sqlite database demo": {
"model_context_protocol_examples": {
"command": "python",
"args": [
"server.py"
]
}
}
}
}
McpServers
{
"model_context_protocol_examples": {
"command": "python",
"args": [
"server.py"
]
}
}
SQLite 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
1. Clone this repository
2. Install the required dependencies:
pip install -r requirements.txt
Project Structure
- server.py: Main FastMCP server implementation with database context management
- database.py: SQLite database implementation with async support
- demo.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 (john@example.com)
- Jane Smith (jane@example.com)
Usage
1. Start the server:
python server.py
2. The database will be automatically initialized with the sample data on first run.
3. Use the query_db tool to retrieve data from the database.
Database Operations
The Database class provides the following methods:
- connect(): Creates a new database connection and initializes the schema
- query(): Executes a sample query to retrieve all users
- disconnect(): Closes the database connection
Customization
To modify the database schema or add new tables:
1. Edit the _init_db() method in database.py
2. Add new methods to Database class for custom queries
3. Update the query_db tool in server.py to 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
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.



