A Model Context Protocol (MCP) server that provides AI assistants with tools to query an e-commerce database. This server exposes customer, order, and product information through a standardized interface that can be used by AI applications like Cursor or Claude.
This MCP server consists of three main components:
main.py: The MCP server implementation using FastMCPtransactional_db.py: In-memory database with sample e-commerce datatests/test_server.py: Unit tests to verify server functionality
The server provides access to three data tables:
- CUST123: Alice Johnson (alice@example.com, 555-1234)
- CUST456: Bob Smith (bob@example.com, 555-5678)
- ORD1001: Alice's order - $89.99 (Wireless Mouse + Keyboard) - Shipped
- ORD1015: Alice's order - $45.50 (USB-C Cable) - Processing
- ORD1022: Bob's order - $120.00 (2x Wireless Mouse) - Delivered
- SKU100: Wireless Mouse ($29.99, Stock: 42)
- SKU200: Keyboard ($59.99, Stock: 18)
- SKU300: USB-C Cable ($15.50, Stock: 77)
The MCP server exposes 5 tools that AI assistants can use:
| Tool | Description | Parameters | Returns |
|---|---|---|---|
get_customer_info |
Get customer details by ID | customer_id: str |
Customer information |
get_order_details |
Get detailed order information | order_id: str |
Order details with items |
check_inventory |
Search products by name | product_name: str |
Matching products with stock |
get_customer_ids_by_name |
Find customer IDs by full name | customer_name: str |
List of customer IDs |
get_orders_by_customer_id |
Get all orders for a customer | customer_id: str |
Dictionary of orders |
- Python 3.8 or higher
- Cursor IDE (or another MCP-compatible AI assistant)
# Clone the repository
git clone <repository-url>
cd python-mcp
# Create virtual environment
python3 -m venv venv
# Activate virtual environment
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt# Run the test suite
pytest tests/test_server.py -v
# Expected output:
# ✓ test_mcp_server_connection - Verifies all 5 tools are availableAdd the server to your Cursor MCP configuration file (~/.cursor/mcp.json):
{
"mcpServers": {
"ecommerce-db-server": {
"command": "/path/to/your/project/venv/bin/python",
"args": ["/path/to/your/project/main.py"],
"description": "A set of tools to query customer, order, and product information in a transactional database"
}
}
}/path/to/your/project/ with the actual absolute path to your project directory.
- Restart Cursor IDE
- Look for the "ecommerce-db-server" in your MCP servers list
- The server indicator should show green (connected)
- Try asking: "What customer IDs match the name Alice Johnson?"
Once configured, you can ask your AI assistant natural language questions:
- "What customer IDs match the name Alice Johnson?"
- "Tell me about customer CUST123"
- "Get me information for customers named Bob Smith"
- "What has Alice ordered?"
- "Show me details for order ORD1001"
- "What orders has customer CUST456 placed?"
- "Check inventory for wireless mouse"
- "What products do we have in stock?"
- "Search for keyboard products"
python-mcp/
├── main.py # MCP server implementation
├── transactional_db.py # Sample database
├── tests/
│ └── test_server.py # Unit tests
├── requirements.txt # Python dependencies
├── .gitignore # Git ignore rules
└── README.md # This file
# Activate virtual environment
source venv/bin/activate
# Run the server directly
python main.py
# The server will start and wait for MCP protocol messages via stdioTo add a new tool to the server:
- Define the function in
main.py - Add the
@mcp.tool()decorator - Include type hints and docstring
- Update the test expectations in
test_server.py
Example:
@mcp.tool()
async def new_tool_name(param: str) -> str:
"""Description of what the tool does"""
# Your implementation here
return result- Verify the Python path in
mcp.jsonpoints to your virtual environment - Check that the script path in
mcp.jsonis correct - Ensure all dependencies are installed:
pip install -r requirements.txt
- Check the server logs in Cursor's MCP panel
- Verify your database queries against the sample data
- Run the test suite to ensure basic functionality works
- Each tool includes a 1-second delay for demonstration
- Remove
await asyncio.sleep(1)lines for production use - Consider implementing proper database connections for larger datasets
Key dependencies included in requirements.txt:
- mcp: Model Context Protocol implementation
- pydantic: Data validation and serialization
- pytest: Testing framework
- pytest-asyncio: Async testing support
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass:
pytest - Submit a pull request
This project is licensed under the MIT License.
For issues and questions:
- Check the troubleshooting section above
- Review the MCP documentation
- Open an issue in the repository