MCP Demo Server
A production-ready demonstration of a Model Context Protocol (MCP) server implemented in Python. This project showcases best practices for building MCP servers with comprehensive examples of tools, resources, and prompts.
What is MCP?
The Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to Large Language Models (LLMs). MCP servers expose:
Tools: Executable functions that LLMs can call (e.g., calculator, file operations)
Resources: Data sources that LLMs can read (e.g., configuration, documentation)
Prompts: Reusable prompt templates for common tasks
Features
Tools Implemented
Calculator - Basic mathematical operations
Operations: add, subtract, multiply, divide
Full input validation and error handling
File Operations - File system interactions
Read, write, list directories, check file existence
Safe path handling with proper error messages
Weather - Simulated weather information
Get weather data for any city
Support for Celsius and Fahrenheit
Timestamp - Get current time in various formats
ISO format, Unix timestamp, human-readable format
Resources Available
Server Configuration (
config://server/settings)Current server settings and metadata
JSON formatted configuration
System Information (
system://info)OS, Python version, working directory
Server process information
Documentation (
docs://getting-started)Getting started guide
Usage instructions
Prompts Provided
Code Review - Generate code review checklists
Customizable by programming language
Adjustable complexity level
Documentation - Documentation templates
API, User, and Developer documentation types
Project-specific customization
Debug Assistant - Debugging guidance
Structured debugging approach
Common techniques and best practices
Installation
Prerequisites
Python 3.10 or higher
pip (Python package manager)
Install Dependencies
Development Setup
Usage
Running the Server
The server uses stdio for communication, which is the standard transport for MCP servers:
Configuration for Claude Desktop
To use this MCP server with Claude Desktop, add it to your Claude configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Or using the installed command:
Using with MCP Client
You can also use the included example client:
Project Structure
Code Architecture
Server Implementation
The server follows a clean, modular architecture:
Key Design Patterns
Type Safety: Full type hints with Pydantic models
Error Handling: Comprehensive try-catch with logging
Validation: Input validation using Pydantic schemas
Logging: Structured logging to file and stderr
Async/Await: Proper async patterns throughout
Separation of Concerns: Each tool in its own method
Examples
Example 1: Using the Calculator Tool
Example 2: Reading a Resource
Example 3: Getting a Prompt
Development
Adding a New Tool
Define input schema with Pydantic:
Add tool to
list_tools():
Implement tool logic:
Add to
call_tool()dispatcher:
Adding a New Resource
Add to
list_resources():
Add handler in
read_resource():
Adding a New Prompt
Add to
list_prompts():
Add handler in
get_prompt():
Testing
Run the test suite:
Best Practices Demonstrated
Input Validation: All tool inputs validated with Pydantic
Error Handling: Comprehensive error handling with meaningful messages
Logging: Structured logging for debugging and monitoring
Type Safety: Full type hints throughout the codebase
Documentation: Comprehensive docstrings and comments
Testing: Unit tests for all major functionality
Code Quality: Formatted with Black, linted with Ruff
Async Patterns: Proper use of async/await
Resource Management: Proper cleanup and resource handling
Security: Safe file operations with path validation
Troubleshooting
Common Issues
Issue: Module not found error
Issue: Server not appearing in Claude Desktop
Issue: Import errors for mcp package
Debug Mode
Enable debug logging:
Check the log file:
Contributing
Contributions are welcome! Please:
Fork the repository
Create a feature branch (
git checkout -b feature/amazing-feature)Commit your changes (
git commit -m 'Add amazing feature')Push to the branch (
git push origin feature/amazing-feature)Open a Pull Request
Resources
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
Built with the MCP Python SDK
Inspired by the MCP community examples
Thanks to Anthropic for developing the Model Context Protocol
Support
Create an issue: GitHub Issues
Documentation: README
MCP Community: MCP Discord
Happy MCP Server Building! 🚀
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
A demonstration MCP server showcasing tools (calculator, file operations, weather, timestamp), resources (server config, system info, documentation), and reusable prompt templates for code review, documentation, and debugging.