model_context_protocol_examples
Some examples to build server, client test in model context protocol. Một số ví dụ sử dụng MCP
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:
pip install -r requirements.txtProject 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.py2. 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
🙌 OpenHands: Code Less, Make More for the Model Context Protocol. Enhance AI assistants with powerful integrations. Python-based implementation.
Universal memory layer for AI Agents; Announcing OpenMemory MCP - local and secure memory management. Python-based implementation.
基于大模型搭建的聊天机器人,同时支持 微信公众号、企业微信应用、飞书、钉钉 等接入,可选择ChatGPT/Claude/DeepSeek/文心一言/讯飞星火/通义千问/ Gemini/GLM-4/Kimi/LinkAI,能处理文本、语音和图片,访问操作系统和互联网,支持基于自有知识库进行定制企业智能客服。
An LLM agent that conducts deep research (local and web) on any given topic and generates a long report with citations. Built for the Model Context Protocol to
🚀 The fast, Pythonic way to build MCP servers and clients Trusted by 19900+ developers. Trusted by 19900+ developers. Trusted by 19900+ developers.
🔥 MaxKB is an open-source platform for building enterprise-grade agents. MaxKB 是强大易用的开源企业级智能体平台。 for the Model Context Protocol. Enhance AI assistants with po
Run your own MCP server? See who uses it and what to fix.
Measure it with TrackMCP