A comprehensive collection of Model Context Protocol (MCP) server examples demonstrating various capabilities and use cases. These examples progress from basic tool functionality to advanced real-world integrations, providing hands-on learning materials for MCP development.
This collection contains 5 progressively complex MCP server examples, each showcasing different aspects of MCP development:
- Simple Calculator - Basic tool functionality
- Weather Service - External API integration
- File System Access - Resources and local data
- Task Manager - CRUD operations with persistence
- GitHub Analyzer - Advanced real-world integration
- Python 3.8+ installed on your system
- Claude Desktop application
- Basic understanding of MCP concepts
-
Clone this repository:
git clone <repository-url> cd mcp-examples
-
Choose an example to start with (we recommend starting with the calculator):
cd 01-calculator pip install -r requirements.txt -
Configure Claude Desktop by adding the server to your config file:
{ "mcpServers": { "calculator": { "command": "python", "args": ["/path/to/mcp-examples/01-calculator/server.py"], "env": {} } } } -
Restart Claude Desktop and start using the tools!
Difficulty: Beginner
Concepts: Basic tools, parameter validation, error handling
A foundational example demonstrating core MCP tool functionality through mathematical operations.
Features:
- β Basic arithmetic operations (add, subtract, multiply, divide)
- π’ Advanced operations (power, square root)
- π Expression evaluation
- β Input validation and error handling
Perfect for: Learning MCP basics, understanding tool registration, and parameter handling.
Difficulty: Intermediate
Concepts: API integration, async operations, environment variables
Demonstrates external API integration with the OpenWeatherMap service.
Features:
- π€οΈ Current weather by city or coordinates
- π Multi-day weather forecasts
- π API key management
- π Network error handling
- β‘ Async HTTP requests
Perfect for: Learning API integration, authentication, and async patterns.
Difficulty: Intermediate
Concepts: MCP resources, local data access, security
Showcases both MCP tools and resources for secure file system operations.
Features:
- π Directory listing and navigation
- π File reading and writing
- π Security and path validation
- π File metadata and information
- π File search capabilities
- π MCP resources for file content
Perfect for: Understanding MCP resources vs tools, security considerations, and local data access.
Difficulty: Advanced
Concepts: CRUD operations, data persistence, complex data structures
A complete task management system with persistent JSON storage.
Features:
- β Full CRUD operations (Create, Read, Update, Delete)
- πΎ Persistent JSON storage with backups
- π Advanced search and filtering
- π Statistics and analytics
- π·οΈ Tags, priorities, and assignments
- β±οΈ Time tracking and due dates
Perfect for: Learning data persistence, complex data structures, and state management.
Difficulty: Expert
Concepts: Complex API integration, caching, data aggregation
The most advanced example, providing comprehensive GitHub repository analysis.
Features:
- π Comprehensive repository analysis
- π Repository comparison
- π Trending and activity analysis
- π File content retrieval
- π§ Repository health scoring
- β‘ Intelligent caching system
- π¦ Rate limit management
Perfect for: Mastering complex integrations, caching strategies, and advanced analytics.
Each example includes specific configuration instructions, but here's the general pattern:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"calculator": {
"command": "python",
"args": ["/absolute/path/to/01-calculator/server.py"],
"env": {}
},
"weather": {
"command": "python",
"args": ["/absolute/path/to/02-weather/server.py"],
"env": {
"OPENWEATHER_API_KEY": "your_api_key_here"
}
},
"filesystem": {
"command": "python",
"args": ["/absolute/path/to/03-filesystem/server.py"],
"env": {}
},
"task-manager": {
"command": "python",
"args": ["/absolute/path/to/04-task-manager/server.py"],
"env": {}
},
"github-analyzer": {
"command": "python",
"args": ["/absolute/path/to/05-github-analyzer/server.py"],
"env": {
"GITHUB_TOKEN": "your_github_token_here"
}
}
}
}For better dependency management, you can use uv:
{
"mcpServers": {
"calculator": {
"command": "uv",
"args": ["--directory", "/path/to/01-calculator", "run", "python", "server.py"],
"env": {}
}
}
}Some examples require external API keys:
- Service: OpenWeatherMap
- Get Key: https://openweathermap.org/api
- Environment Variable:
OPENWEATHER_API_KEY - Free Tier: 1,000 calls/day
- Service: GitHub API
- Get Token: GitHub Settings > Developer settings > Personal access tokens
- Environment Variable:
GITHUB_TOKEN - Permissions:
public_repo(andrepofor private repositories) - Free Tier: 5,000 requests/hour
- Start with Calculator - Learn MCP fundamentals
- Try Weather Service - Understand API integration
- Explore File System - Learn about MCP resources
- Build with Task Manager - Master data persistence
- Analyze with GitHub - Advanced integration patterns
| Concept | Calculator | Weather | FileSystem | TaskManager | GitHub |
|---|---|---|---|---|---|
| Basic Tools | β | β | β | β | β |
| API Integration | β | β | β | β | β |
| MCP Resources | β | β | β | β | β |
| Data Persistence | β | β | β | β | β |
| Async Operations | β | β | β | β | β |
| Caching | β | β | β | β | β |
| Error Handling | β | β | β | β | β |
User: What's 15 + 27?
Claude: I'll calculate that for you.
[Uses add tool: a=15, b=27]
Result: 15 + 27 = 42
User: What's the weather like in Tokyo?
Claude: I'll get the current weather for Tokyo.
[Uses get_current_weather tool: city="Tokyo"]
Result: Tokyo: 22Β°C, Clear sky, Humidity 65%
User: List the files in my project directory
Claude: I'll list the contents of your project directory.
[Uses list_directory tool: path="."]
Result: Found 5 items: src/, tests/, main.py, README.md, requirements.txt
User: Create a task to implement user authentication
Claude: I'll create that task for you.
[Uses create_task tool: title="Implement user authentication"]
Result: Task created with ID abc12345
User: Analyze the React repository
Claude: I'll perform a comprehensive analysis of the React repository.
[Uses analyze_repository tool: owner="facebook", repo="react"]
Result: React has 228k stars, 1.5k contributors, health score 95/100
mcp-examples/
βββ README.md # This file
βββ 01-calculator/
β βββ server.py # Calculator MCP server
β βββ requirements.txt # Dependencies
β βββ README.md # Calculator documentation
βββ 02-weather/
β βββ server.py # Weather MCP server
β βββ requirements.txt # Dependencies
β βββ README.md # Weather documentation
βββ 03-filesystem/
β βββ server.py # File system MCP server
β βββ requirements.txt # Dependencies
β βββ README.md # File system documentation
βββ 04-task-manager/
β βββ server.py # Task manager MCP server
β βββ requirements.txt # Dependencies
β βββ README.md # Task manager documentation
βββ 05-github-analyzer/
βββ server.py # GitHub analyzer MCP server
βββ requirements.txt # Dependencies
βββ README.md # GitHub analyzer documentation
All examples use:
mcp>=1.0.0- Core MCP libraryfastmcp>=0.1.0- Simplified MCP server frameworktyping-extensions>=4.0.0- Enhanced type hints
Additional dependencies per example:
- Weather:
aiohttpfor HTTP requests - GitHub:
aiohttpfor HTTP requests
Each example can be tested individually:
# Test a specific server
cd 01-calculator
python server.py
# The server will start and wait for MCP messages
# Use Claude Desktop or MCP Inspector to test-
Server won't start
- Check Python version (3.8+ required)
- Install dependencies:
pip install -r requirements.txt - Verify file paths in configuration
-
Claude Desktop doesn't see the server
- Check configuration file syntax (valid JSON)
- Use absolute paths in configuration
- Restart Claude Desktop after changes
-
API-based servers fail
- Verify API keys are set correctly
- Check internet connectivity
- Review API key permissions and quotas
-
Permission errors
- Ensure Python files are executable
- Check directory permissions
- Verify environment variables are set
- Check individual README files for specific troubleshooting
- Review error messages carefully - they often contain solutions
- Test with simple examples first (calculator) before complex ones
- Verify configuration using the provided examples
- Start with the Calculator to understand MCP basics
- Learn about tool registration and parameter handling
- Understand error handling patterns
- Explore API integration with the Weather server
- Learn about MCP resources vs tools with File System
- Understand async programming patterns
- Master data persistence with Task Manager
- Learn complex API integration with GitHub Analyzer
- Understand caching strategies and rate limiting
After working through these examples, you'll understand:
- β MCP Architecture: Tools, resources, and server patterns
- β API Integration: Authentication, error handling, rate limiting
- β Data Management: Persistence, caching, and state management
- β Security: Input validation, path traversal protection
- β Performance: Async operations, caching, optimization
- β Error Handling: Graceful degradation and user feedback
- β Best Practices: Code organization, documentation, testing
We welcome contributions to improve these examples!
- Bug Fixes: Report and fix issues in existing examples
- Documentation: Improve README files and code comments
- New Examples: Add new MCP server examples
- Enhancements: Add features to existing servers
- Testing: Add test cases and validation
- Follow existing patterns in code structure and documentation
- Include comprehensive README for new examples
- Add proper error handling and input validation
- Use type hints and clear variable names
- Test thoroughly before submitting
- Database Integration: PostgreSQL/MySQL MCP server
- Email Service: SMTP/IMAP integration
- Cloud Storage: AWS S3/Google Drive integration
- AI/ML Service: OpenAI/Anthropic API integration
- Monitoring: System metrics and log analysis
- Social Media: Twitter/LinkedIn API integration
This project is licensed under the MIT License - see individual files for details.
- Anthropic for creating the Model Context Protocol
- FastMCP contributors for the simplified server framework
- OpenWeatherMap for providing weather API services
- GitHub for their comprehensive API
- Community contributors who help improve these examples
Happy MCP Development! π
Start with the Calculator example and work your way up to building sophisticated MCP integrations.