Skip to main content

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

The MCPRegistry (core/agentpress/mcp_registry.py) manages all MCP tool discovery and activation:

Tool Status Lifecycle

MCP Tool Wrapper

The MCPToolWrapper (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:
Implementation (custom_mcp_handler.py):

2. HTTP (Streamable HTTP)

For standard HTTP-based MCP servers:
Implementation:

3. JSON/stdio (Process-based)

For local MCP servers running as processes:
Implementation:

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

The MCPConnectionManager handles connection pooling:

Error Handling

Failed Tool Loading

Execution Errors

Performance Optimization

Parallel Initialization

Schema Pre-warming

Monitoring and Statistics

Best Practices

  1. Enable Caching: Always use use_cache=True for production
  2. Filter Tools: Use enabledTools to load only needed tools
  3. Handle Failures: MCP servers may be unavailable - design for resilience
  4. Monitor Performance: Track activation times and cache hit rates
  5. Batch Operations: Initialize multiple MCP servers in parallel
  6. Error Recovery: Implement retry logic for transient failures

Next Steps