Getting Started with MCP Mesh¶
From zero to distributed MCP services in 10 minutes
Overview¶
MCP Mesh makes building distributed MCP services as easy as writing Python functions. Add decorators to your classes and functions, and they automatically discover and use other services across your network.
What is MCP Mesh?¶
MCP Mesh is a distributed service mesh framework that enhances FastMCP with automatic discovery and dependency injection:
- π Dual decorators: Combine familiar
@app.tool
(FastMCP) with@mesh.tool
(orchestration) - π All MCP decorators: Support for
@app.tool
,@app.prompt
,@app.resource
from FastMCP - π Smart dependency injection: Use remote functions with type safety (
mesh.McpMeshAgent
) - π·οΈ Tag-based resolution: Smart capability matching using tags and metadata
- π Zero boilerplate: Mesh discovers your FastMCP
app
and handles everything - π¦ Production ready: Go registry + Python agents + Kubernetes support
The Simplest Example¶
import mesh
from fastmcp import FastMCP
# Single FastMCP server instance
app = FastMCP("Hello World Service")
# 1. Add a simple tool with dual decorators
@app.tool() # β FastMCP decorator (familiar MCP development)
@mesh.tool(capability="greeting") # β Mesh decorator (adds orchestration)
def greet(name: str = "World") -> str:
return f"Hello, {name}!"
# 2. Add a tool with dependency injection
@app.tool() # β FastMCP handles MCP protocol
@mesh.tool(
capability="advanced_greeting",
dependencies=["date_service"] # β Mesh handles service discovery
)
def greet_with_date(name: str = "World", date_service: mesh.McpMeshAgent = None) -> str:
if date_service:
current_date = date_service() # Calls remote system agent
return f"Hello, {name}! Today is {current_date}"
return f"Hello, {name}! (Date service not available)"
# 3. Configure the agent
@mesh.agent(
name="hello-world",
http_port=9090,
auto_run=True # Mesh handles server startup automatically
)
class HelloWorldAgent:
pass
# No main method needed! Mesh discovers 'app' and handles everything.
That's it! The dual decorator pattern gives you:
- FastMCP decorators (
@app.tool
) for familiar MCP development - Mesh decorators (
@mesh.tool
) for dependency injection and orchestration - Automatic discovery - Mesh finds your FastMCP
app
and handles server startup - Zero boilerplate - No main methods or manual server management needed
Quick Start (Docker - 2 Minutes)¶
Easiest way to get started:
# 1. Clone the repository (for agent code)
git clone https://github.com/dhyansraj/mcp-mesh.git
cd mcp-mesh/examples/docker-examples
# 2. Start everything (uses published Docker images)
docker-compose up
# 3. Test it (in another terminal)
curl -s -X POST http://localhost:8081/mcp \
-H "Content-Type: application/json" \
-d '{"method": "tools/call", "params": {"name": "hello_mesh_simple", "arguments": {}}}' | jq .
Expected response:
That's it! You now have a working distributed MCP service mesh! π
Alternative: macOS with Homebrew (2 Minutes)¶
For macOS users with Homebrew:
# 1. Install MCP Mesh CLI tools
brew tap dhyansraj/mcp-mesh
brew install mcp-mesh
# 2. Install Python package with semantic versioning
pip install "mcp-mesh>=0.5,<0.6"
# 3. Download example agents
git clone https://github.com/dhyansraj/mcp-mesh.git
cd mcp-mesh/examples/simple
# 4. Start registry and agents
mcp-mesh-registry --host 0.0.0.0 --port 8000 &
python system_agent.py &
python hello_world.py &
# 5. Test it
curl -s -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{"method": "tools/call", "params": {"name": "hello_mesh_simple", "arguments": {}}}' | jq .
Alternative: Linux/macOS Install Script (3 Minutes)¶
For Linux or manual macOS installation:
# 1. Install MCP Mesh with semantic versioning (allows patch updates)
pip install "mcp-mesh>=0.5,<0.6"
# 2. Download and start registry (use minor version for latest patches)
curl -sSL https://raw.githubusercontent.com/dhyansraj/mcp-mesh/main/install.sh | bash -s -- --registry-only --version v0.5
mcp-mesh-registry --host 0.0.0.0 --port 8000 &
# 3. Download example agents
git clone https://github.com/dhyansraj/mcp-mesh.git
cd mcp-mesh/examples/simple
# 4. Run agents
python system_agent.py &
python hello_world.py &
# 5. Test it
curl -s -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{"method": "tools/call", "params": {"name": "hello_mesh_simple", "arguments": {}}}' | jq .
Alternative: Local Development (5 Minutes)¶
For developers who want to build from source:
# 1. Build the project
make install-dev
# 2. Start registry (terminal 1)
./bin/meshctl start-registry
# 3. Start system agent (terminal 2)
./bin/meshctl start examples/simple/system_agent.py
# 4. Start hello world agent (terminal 3)
./bin/meshctl start examples/simple/hello_world.py
# 5. Test it
./bin/meshctl list agents
Learning Paths¶
Choose your journey based on your goals:
π I want to see it working (5 minutes)¶
- Docker Quick Start - Complete environment
- Test the examples - See dependency injection in action
- Explore with meshctl - Understand the architecture
π§ I want to develop agents (15 minutes)¶
- Local Development Setup - Build from source
- Run examples locally - Direct binary execution
- Modify an agent - Make your first change
- Create new tools - Add your own functionality
π I want production deployment (30 minutes)¶
- Kubernetes Guide - Production-ready setup
- Deploy to cluster - Scale and monitor
- Test resilience - Failure scenarios
- Monitor with meshctl - Operational insights
π I want to understand everything (60 minutes)¶
- Start with Docker to see the big picture
- Try local development to understand internals
- Deploy to Kubernetes for production patterns
- Read the architecture docs for deep understanding
How MCP Mesh Works¶
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Registry β β Hello World β β System Agent β
β (Go + DB) β β Agent (Python) β β (Python) β
β Port: 8000 βββββΊβ Port: 8081 βββββΊβ Port: 8082 β
β [Discovery] β β [Capabilities] β β [Services] β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β² β² β²
β βββββββββββ΄βββββββββ β
βββββββββββββββββ meshctl Client ββββββββββββββββ
β (CLI/Dashboard) β
ββββββββββββββββββββ
Your Code MCP Mesh Runtime Automatic
βββββββββββββββββββ ββββββββββββββββββββββ ββββββββββββββββ
β @mesh.agent ββββββββββΆβ β’ HTTP Wrapper βββββββββ β’ Registry β
β @mesh.tool β β β’ Dependency Graph β β β’ Discovery β
β def my_func(): βββββββββββ β’ JSON-RPC/MCP β β β’ Health β
βββββββββββββββββββ ββββββββββββββββββββββ ββββββββββββββββ
You write this Handles complexity Runs for you
Key Concepts in 30 Seconds¶
- Agents: Python classes decorated with
@mesh.agent
that group related tools - Tools: Functions decorated with
@mesh.tool
that provide specific capabilities - Registry: Go service that tracks all agents and handles service discovery
- Capabilities: What each tool provides (e.g., "date_service", "weather", "database")
- Dependencies: What capabilities a tool needs from other agents
- Injection: Remote functions automatically injected as function parameters
- meshctl: CLI tool for managing, monitoring, and debugging the mesh
Why Developers Love MCP Mesh¶
- Zero boilerplate: Just add decorators to existing functions
- Graceful degradation: Agents work standalone, enhance when connected
- MCP protocol: Full compatibility with existing MCP tools and clients
- Local to production: Same code runs locally, in Docker, and Kubernetes
- Real-time updates: Hot dependency injection without restarts
- Operational visibility: Built-in monitoring and debugging tools
Ready to Start?¶
Choose your path:
- π Quick Demo: Try the Docker examples
- π§ Local Development: Follow the simple examples guide
- π Production Setup: Deploy with Kubernetes
- π Deep Dive: Read the complete examples overview
π‘ Tip: Start with Docker for the complete experience, then try local development for faster iteration.
π Note: All examples use the same core agents, so you can easily switch between deployment methods.
π§ Troubleshooting¶
Common issues when getting started:
Docker Issues:
- Port conflicts: Change ports in
.env.local
file - Build failures: Try
docker-compose build --no-cache
- Registry connection: Check
docker-compose logs registry
Local Development Issues:
- Build errors: Ensure Go 1.21+ and Python 3.9+ are installed
- Registry not starting: Check if port 8000 is available
- Agent connection failures: Verify registry is running first
- Import errors: Run
make install-dev
to install dependencies
Testing Issues:
- Tool calls fail: Use
/mcp
endpoint, not/tools/call
- No dependency injection: Wait 30-60 seconds for full mesh setup
- JSON errors: Ensure proper JSON-RPC format in curl commands
For detailed solutions, see the troubleshooting sections in each example README.
β οΈ Known Limitations¶
- Windows Support: Native Windows support is experimental; WSL2 or Docker recommended
- Python 3.8: Not supported; requires Python 3.9+
- PyPI Package: Not yet published; must build from source or use Docker
- ARM Architecture: Some Go binary builds may need local compilation
- Network Policies: Strict firewall/network policies may block agent communication
π― What's Next?¶
After getting started:
-
Explore the Examples:
-
Modify existing agents to understand the patterns
- Add new tools to see dependency injection in action
-
Test resilience by stopping and starting agents
-
Build Your Own Agent:
-
Copy
hello_world.py
as a template - Add your own capabilities and dependencies
-
Test integration with existing agents
-
Scale to Production:
-
Deploy to Kubernetes for production workloads
- Set up monitoring and alerting
-
Configure security and access controls
-
Advanced Features:
- Tag-based dependency resolution
- Multi-replica agent deployments
- Cross-namespace service discovery
- Custom capability development
π Additional Resources¶
- Examples Overview - Compare all deployment options
- Docker Examples - Complete containerized setup
- Kubernetes Examples - Production deployment
- Local Development - Build and run from source