MCP Python Server

MCP Python Server

A Python-based MCP server that exposes SQLite database CRUD and search operations on Users, Products, and Orders as tools for AI clients like Claude Desktop.

Category
Visit Server

README

๐Ÿš€ MCP Server & Database Integration using Python

A Python-based Model Context Protocol (MCP) server built using FastMCP that exposes database operations as MCP tools. The project integrates a local SQLite database and demonstrates how AI clients such as Claude Desktop and a custom Python client can interact with backend services through MCP.


๐Ÿ“Œ Project Overview

This project was developed as part of my internship to understand and implement the Model Context Protocol (MCP).

The server exposes database operations through MCP tools, allowing AI applications and clients to interact with a structured SQLite database.

The project demonstrates:

  • Building an MCP server using FastMCP
  • Integrating a SQLite database with multiple tables
  • Exposing database operations as MCP tools
  • Connecting through a Python client
  • Integrating with Claude Desktop
  • Automated testing using pytest

โœจ Features

  • โœ… Python-based MCP Server using FastMCP
  • โœ… SQLite Database Integration
  • โœ… Users, Products and Orders Database
  • โœ… CRUD Operations
  • โœ… Search Functionality
  • โœ… Parameterized SQL Queries
  • โœ… Structured JSON Responses
  • โœ… Logging
  • โœ… Python MCP Client
  • โœ… Claude Desktop Integration
  • โœ… Automated Testing using pytest

๐Ÿ›  Tech Stack

Technology Purpose
Python 3.13 Programming Language
FastMCP MCP Server Framework
SQLite Local Database
pytest Automated Testing
Claude Desktop MCP Client
MCP Inspector Tool Testing
VS Code Development Environment

๐Ÿ— System Architecture

                 Claude Desktop
                       โ”‚
                       โ”‚
                (MCP Tool Calls)
                       โ”‚
                       โ–ผ
            โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
            โ”‚    FastMCP Server   โ”‚
            โ”‚      server.py      โ”‚
            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚         โ”‚
                  โ–ผ         โ–ผ
             MCP Tools   Logging
                  โ”‚
                  โ–ผ
             Database Layer
                 db.py
                  โ”‚
                  โ–ผ
            SQLite Database
      (Users โ€ข Products โ€ข Orders)

๐Ÿ“‚ Project Structure

mcp-python-server/
โ”‚
โ”œโ”€โ”€ client.py              # Python MCP client
โ”œโ”€โ”€ server.py              # FastMCP server exposing database tools
โ”œโ”€โ”€ db.py                  # Database access layer
โ”œโ”€โ”€ seed.py                # Creates and seeds the SQLite database
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ pytest.ini
โ”œโ”€โ”€ README.md
โ”‚
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_db.py         # Database tests
โ”‚   โ””โ”€โ”€ test_tools.py      # MCP tool tests
โ”‚
โ””โ”€โ”€ .gitignore

๐Ÿ—„ Database Schema

The project uses a SQLite database consisting of three tables.

Users

Column Type
id INTEGER
name TEXT
email TEXT

Products

Column Type
id INTEGER
name TEXT
category TEXT
price REAL
stock INTEGER

Orders

Column Type
id INTEGER
user_id INTEGER
product_id INTEGER
quantity INTEGER
order_date TEXT

๐Ÿ”ง MCP Tools

User Tools

Tool Description
get_all_users Retrieve all users
get_user Retrieve a user by ID
search_user Search users by name
add_user Add a new user
remove_user Delete a user

Product Tools

Tool Description
get_all_products Retrieve all products
get_product Retrieve a product by ID
search_product Search products

Order Tools

Tool Description
get_all_orders Retrieve all orders

๐Ÿš€ Installation & Setup

Clone the repository

git clone https://github.com/<your-username>/mcp-python-server.git

cd mcp-python-server

Create a virtual environment

python -m venv venv

Activate the environment

venv\Scripts\activate

Install dependencies

pip install -r requirements.txt

Generate the SQLite database

python seed.py

โ–ถ Running the Project

Start the MCP Server

mcp dev server.py

Run the Python Client

python client.py

Execute Tests

pytest

Expected Output

===========================
10 passed
===========================

๐Ÿ“ธ Screenshots

MCP Inspector

MCP Inspector


Claude Desktop Integration

Claude Desktop


Python Client

Python Client


Automated Testing

Pytest


๐Ÿค– Claude Desktop Integration

The MCP server can be integrated with Claude Desktop using the MCP configuration file.

Once configured, Claude Desktop can directly invoke the available MCP tools.

Example prompts:

  • Show all users.
  • List all products.
  • Search for Laptop.
  • Show all orders.
  • Create a new user.

๐Ÿงช Testing

Automated testing was implemented using pytest.

The test suite validates:

  • Database operations
  • CRUD functionality
  • Search operations
  • Invalid user handling
  • Invalid product handling
  • MCP tool responses

Current Status

โœ… 10 Tests Passed


Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured