README.md•2.53 kB
# MCP Server Demo
A demonstration project for building MCP (Model Context Protocol) servers using the Python MCP SDK.
## What is MCP?
The Model Context Protocol (MCP) allows applications to provide context for LLMs in a standardized way. This project demonstrates how to:
- Build MCP servers that expose resources, tools, and prompts
- Use the FastMCP framework for rapid development
- Run servers in development mode with hot reloading
## Features
This demo server includes:
- **Calculator Tools**: Basic arithmetic operations
- **Greeting Resources**: Dynamic personalized greetings
- **Code Review Prompts**: Reusable templates for code review
- **Development Mode**: Hot reloading and debugging support
## Installation
1. Create and activate a virtual environment:
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
2. Install dependencies:
```bash
pip install -r requirements.txt
```
## Quick Start
### Development Mode (Recommended)
Run the server in development mode with hot reloading:
```bash
mcp dev server.py
```
This will start the MCP Inspector where you can test your server interactively.
### Direct Execution
Run the server directly:
```bash
python server.py
```
### Claude Desktop Integration
Install the server in Claude Desktop:
```bash
mcp install server.py
```
## Project Structure
```
mcp-server/
├── server.py # Main MCP server implementation
├── requirements.txt # Python dependencies
├── pyproject.toml # Project configuration
├── run_dev.py # Development runner script
└── README.md # This file
```
## API Reference
### Tools
- `add(a: int, b: int) -> int`: Add two numbers
- `multiply(a: int, b: int) -> int`: Multiply two numbers
- `calculate_bmi(weight_kg: float, height_m: float) -> float`: Calculate BMI
### Resources
- `greeting://{name}`: Get a personalized greeting for a given name
- `config://app`: Get application configuration
### Prompts
- `review_code`: Template for code review requests
- `debug_error`: Template for debugging error messages
## Development
The server uses FastMCP which provides:
- Automatic type validation
- Built-in error handling
- Development mode with hot reloading
- Easy integration with Claude Desktop
## Learn More
- [MCP Python SDK Documentation](https://pypi.org/project/mcp/)
- [Model Context Protocol Specification](https://modelcontextprotocol.io/)
- [FastMCP Examples](https://github.com/modelcontextprotocol/python-sdk)