trackmcp
Back to directory
anhnx000

model_context_protocol_examples

View on GitHub

Some examples to build server, client test in model context protocol. Một số ví dụ sử dụng MCP

0 stars PythonAI & Machine Learning Updated Apr 2, 2025

Documentation

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:

bash
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:

sql
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:

bash
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

Frequently asked questions

What is model_context_protocol_examples?

model_context_protocol_examples is Some examples to build server, client test in model context protocol. Một số ví dụ sử dụng MCP

How do I install model_context_protocol_examples?

Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.

Is model_context_protocol_examples open source?

Yes — it is hosted on GitHub at https://github.com/anhnx000/model_context_protocol_examples.

Related MCP tools

Run your own MCP server? See who uses it and what to fix.

Measure it with TrackMCP