MCP Tools Integration
The MCP (Model Context Protocol) module enables seamless integration of MCP-compliant tools and servers with PraisonAI agents, supporting both stdio and SSE transport methods.Overview
MCP (Model Context Protocol) is a standard for connecting AI assistants to external tools and data sources. The MCP module in PraisonAI provides:- Stdio Transport: Run MCP servers as subprocess commands
- SSE Transport: Connect to HTTP/SSE-based MCP servers
- Automatic Tool Discovery: Tools are automatically discovered and made available to agents
- Flexible Integration: Support for NPX packages, Python scripts, and remote servers
Quick Start
Transport Methods
Stdio Transport
The stdio transport runs MCP servers as subprocesses:SSE Transport
The SSE transport connects to HTTP endpoints using Server-Sent Events:Available MCP Servers
Official NPX Servers
Custom Python Servers
Create your own MCP server in Python:Tool Discovery
MCP automatically discovers available tools:Error Handling
MCP includes built-in error handling and retry logic for robust operation.Advanced Usage
Multiple MCP Servers
Environment Configuration
Debugging MCP Connections
Creating SSE MCP Servers
Example SSE server implementation:Best Practices
Transport Choice
- Use stdio for local tools and development
- Use SSE for remote/cloud deployments
- Consider latency and reliability needs
Reliability
- Implement timeouts for long-running operations
- Handle server disconnections gracefully
- Provide fallback options
Security
- Validate input/output from MCP servers
- Use environment variables for secrets
- Implement proper authentication for SSE
Performance
- Reuse MCP instances when possible
- Monitor subprocess resource usage
- Implement connection pooling for SSE