A comprehensive implementation of the Model Context Protocol (MCP) - an open standard for connecting AI systems, particularly Large Language Models (LLMs), with external tools, services, and data sources.
- What is MCP?
- Project Structure
- Step-by-Step Setup Guide
- Features
- Usage
- Examples
- Architecture
- Integrations
- Resources
- Contributing
- License
The Model Context Protocol (MCP) is an open standard introduced by Anthropic that standardizes the integration of AI systems with external tools and data sources. It provides:
- Universal Interface: For reading files, executing functions, and handling contextual prompts
- Client-Server Architecture: Enables secure, bidirectional communication
- Tool Integration: Connect LLMs to databases, APIs, file systems, and more
- Context Management: Structured way to provide context to AI models
mcp-project/
βββ README.md # This file
βββ requirements.txt # Python dependencies
βββ .gitignore # Git ignore rules
βββ config/
β βββ mcp_config.json # MCP server configuration
βββ src/
β βββ __init__.py
β βββ mcp_server.py # Main MCP server implementation
β βββ tools/ # Custom MCP tools
β β βββ __init__.py
β β βββ file_tools.py # File system operations
β β βββ api_tools.py # API integration tools
β β βββ data_tools.py # Data processing tools
β βββ utils/
β βββ __init__.py
β βββ helpers.py # Utility functions
βββ examples/
β βββ basic_server.py # Basic MCP server example
β βββ client_example.py # MCP client example
β βββ custom_tools.py # Custom tools example
βββ tests/
β βββ __init__.py
β βββ test_mcp_server.py # Unit tests
βββ docs/
βββ ARCHITECTURE.md # Architecture documentation
βββ TUTORIAL.md # Detailed tutorial
π‘ Windows CMD Users: See SETUP_CMD.md for a complete CMD-specific guide with all commands.
Ensure you have the following installed:
- Python 3.9 or higher
- pip (Python package manager)
- Git
Windows CMD:
mkdir mcp-project
cd mcp-project
git initmacOS/Linux:
mkdir mcp-project
cd mcp-project
git initWindows CMD:
python -m venv venv
venv\Scripts\activate.batWindows PowerShell:
python -m venv venv
venv\Scripts\Activate.ps1macOS/Linux:
python3 -m venv venv
source venv/bin/activateWindows CMD/PowerShell:
pip install -r requirements.txtmacOS/Linux:
pip install -r requirements.txt# Install the official MCP Python SDK
pip install mcp
# Or install from source
pip install git+https://github.com/modelcontextprotocol/python-sdk.git- Edit
config/mcp_config.jsonto configure your server settings - Define your tools and resources
- Set up authentication if needed
Windows CMD:
REM Run the basic example
python examples\basic_server.py
REM Or run the full server
python src\mcp_server.pymacOS/Linux:
# Run the basic example
python examples/basic_server.py
# Or run the full server
python src/mcp_server.pyWindows CMD:
REM Run tests
python -m pytest tests\
REM Or run manually
python examples\client_example.pymacOS/Linux:
# Run tests
pytest tests/
# Or run manually
python examples/client_example.py- β MCP Server Implementation: Full-featured MCP server with tool support
- β Custom Tools: Examples of file operations, API calls, and data processing
- β Client Integration: Example client for connecting to MCP servers
- β Configuration Management: JSON-based configuration system
- β Error Handling: Robust error handling and logging
- β Type Safety: Type hints throughout the codebase
- β Testing: Unit tests for core functionality
from src.mcp_server import MCPServer
# Initialize server
server = MCPServer(config_path="config/mcp_config.json")
# Start server
server.start()from src.tools.file_tools import FileTools
# Initialize file tools
file_tools = FileTools()
# Read a file
content = file_tools.read_file("path/to/file.txt")
# Write to a file
file_tools.write_file("path/to/file.txt", "content")from src.mcp_client import MCPClient
# Connect to MCP server
client = MCPClient(server_url="http://localhost:8000")
# Call a tool
result = client.call_tool("read_file", {"path": "example.txt"})See the examples/ directory for:
- basic_server.py: Minimal MCP server implementation
- client_example.py: How to connect and use an MCP server
- custom_tools.py: Creating custom MCP tools
MCP follows a client-server architecture:
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β LLM App ββββββββββΊβ MCP Client ββββββββββΊβ MCP Server β
β (Claude) β β β β β
βββββββββββββββ βββββββββββββββ ββββββββ¬βββββββ
β
ββββββββββ΄βββββββββ
β β
ββββββββΌβββββββ ββββββββΌβββββββ
β Tools β β Resources β
β (Actions) β β (Data) β
βββββββββββββββ βββββββββββββββ
- MCP Server: Provides tools and resources to clients
- MCP Client: Connects to servers and makes requests
- Tools: Executable functions (e.g., read_file, call_api)
- Resources: Data sources (e.g., files, databases)
- Create a new file in
src/tools/ - Implement tool functions following the MCP tool interface
- Register tools in
mcp_server.py
Example:
from mcp import Tool
@Tool(name="my_custom_tool", description="Does something custom")
def my_custom_tool(param: str) -> str:
# Your implementation
return result# Run all tests
pytest
# Run with coverage
pytest --cov=src tests/This project includes comprehensive integration guides for popular tools and services:
-
INTEGRATIONS.md - Complete guide for integrating with:
- LM Studio
- Docker Desktop
- Obsidian (Local REST API & Marcel Marais' server)
- Logseq
- Cursor IDE
- Claude Sonnet
- Cloud Server Setup
-
CURSOR_LM_STUDIO_SETUP.md - Quick setup guide for:
- Connecting LM Studio with Cursor
- Testing the connection
- Using LM Studio tools in Cursor
- Remote access via iPhone A-Shell and Tailscale
- Troubleshooting common issues
-
REMOTE_ACCESS.md - Guide for remote access:
- Accessing LM Studio from iPhone/Android
- Tailscale setup and configuration
- A-Shell (iOS) and Termux (Android) usage
- SSH tunneling methods
- Security best practices
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Anthropic for creating the Model Context Protocol
- The MCP community for their contributions and support
Made with β€οΈ for the MCP community