Overview
Kortix provides comprehensive support for the Model Context Protocol (MCP), enabling agents to interact with external tools and services through standardized MCP servers. The MCP integration supports multiple connection types and includes advanced features like schema caching, JIT loading, and connection pooling.MCP Architecture
Kortix’s MCP system consists of several key components:MCP Registry
TheMCPRegistry (core/agentpress/mcp_registry.py) manages all MCP tool discovery and activation:
Tool Status Lifecycle
MCP Tool Wrapper
TheMCPToolWrapper (core/tools/mcp_tool_wrapper.py) provides the interface for using MCP tools:
Supported MCP Types
Kortix supports four types of MCP server connections:1. SSE (Server-Sent Events)
For HTTP-based streaming connections:custom_mcp_handler.py):
2. HTTP (Streamable HTTP)
For standard HTTP-based MCP servers:3. JSON/stdio (Process-based)
For local MCP servers running as processes:4. Composio MCP
For Composio-managed MCP servers (see Composio Integration):Schema Caching
Kortix implements Redis-based schema caching for fast MCP tool loading:Cache Configuration
Cache Flow
Benefits
- Instant startup: Cached schemas load in milliseconds
- Reduced API calls: No need to reconnect to MCP servers
- Improved reliability: Works even if MCP server is temporarily down
- Lower latency: Cached schemas reduce tool activation time
JIT (Just-In-Time) Tool Loading
MCP tools use JIT loading to minimize startup time:Tool Discovery
Auto-Activation
Using MCP Tools
Initialize MCP Wrapper
Dynamic Method Access
Tool Registry Integration
Connection Management
TheMCPConnectionManager handles connection pooling:
Error Handling
Failed Tool Loading
Execution Errors
Performance Optimization
Parallel Initialization
Schema Pre-warming
Monitoring and Statistics
Best Practices
- Enable Caching: Always use
use_cache=Truefor production - Filter Tools: Use
enabledToolsto load only needed tools - Handle Failures: MCP servers may be unavailable - design for resilience
- Monitor Performance: Track activation times and cache hit rates
- Batch Operations: Initialize multiple MCP servers in parallel
- Error Recovery: Implement retry logic for transient failures
Next Steps
- Custom Tools - Create your own tools
- Composio Integration - Use Composio MCP servers
- Built-in Tools - Explore native tools