Skip to main content

Overview

Model Context Protocol (MCP) is an open standard that enables agents to connect with external tools, APIs, and data sources. The platform provides comprehensive MCP support, allowing agents to access hundreds of integrations including GitHub, Slack, Google Workspace, databases, and custom services.

MCP Architecture

MCP Registry

The MCPRegistry is the central component managing all MCP tools:
Reference: backend/core/agentpress/mcp_registry.py:64-78

MCP Tool Info

Each MCP tool is tracked with comprehensive metadata:
Reference: backend/core/agentpress/mcp_registry.py:33-49

MCP Tool Status

Tools progress through lifecycle states:
Reference: backend/core/agentpress/mcp_registry.py:25-30

MCP Server Types

The platform supports three types of MCP servers:

1. HTTP/Streamable HTTP

HTTP-based MCP servers using the streamable HTTP transport:
Reference: backend/core/agentpress/mcp_registry.py:487-525

2. SSE (Server-Sent Events)

Server-Sent Events for real-time tool communication:
Reference: backend/core/agentpress/mcp_registry.py:419-485

3. JSON/stdio (Local Processes)

Local process-based MCP servers:
Reference: backend/core/agentpress/mcp_registry.py:527-571

Schema Caching

MCP schemas are cached in Redis for fast access:

Cache Strategy

  1. Check Redis first: Look for cached toolkit schemas
  2. Cache miss: Load from MCP server
  3. Store in Redis: Cache for 24 hours (configurable)
  4. Opportunistic caching: Cache all tools from toolkit, not just requested ones
Reference: backend/core/agentpress/mcp_registry.py:153-169

Cache TTL

Schemas are cached for 24 hours by default:
Reference: backend/core/agentpress/mcp_registry.py:65

Tool Discovery

MCP tools are discovered through multiple methods:

1. Composio Integration

For Composio-based MCP tools:
Reference: backend/core/agentpress/mcp_registry.py:304-361

2. Custom MCP Servers

For custom MCP servers:
Reference: backend/core/agentpress/mcp_registry.py:261-300

MCP Execution Context

MCP tools execute within a context that tracks usage:
Reference: backend/core/agentpress/mcp_registry.py:52-61

Tool Execution

MCP tools are executed through the registry:
Reference: backend/core/agentpress/mcp_registry.py:573-619

Auto-Activation

Tools are automatically activated on first use:
Reference: backend/core/agentpress/mcp_registry.py:621-665

Schema Pre-warming

Schemas can be pre-loaded at startup for faster first use:
Reference: backend/core/agentpress/mcp_registry.py:671-690

Registry Operations

Register Tool

Reference: backend/core/agentpress/mcp_registry.py:80-92

Activate Tool

Reference: backend/core/agentpress/mcp_registry.py:94-108

Query Tools

Reference: backend/core/agentpress/mcp_registry.py:126-140

Get Statistics

Reference: backend/core/agentpress/mcp_registry.py:693-703

Integration with Agent Loader

The MCP registry is initialized from the JIT loader:
Reference: backend/core/agentpress/mcp_registry.py:719-741

Description Enrichment

Some tools have their descriptions enriched with usage hints:
Reference: backend/core/agentpress/mcp_registry.py:10-22

Singleton Pattern

The MCP registry uses a singleton pattern:
Reference: backend/core/agentpress/mcp_registry.py:706-716

Performance Optimizations

Multi-Level Caching

  1. In-memory cache: Tool schemas cached in registry
  2. Redis cache: Toolkit schemas cached for 24 hours
  3. Opportunistic caching: All toolkit tools cached when one is loaded

Batch Loading

When loading multiple MCP tools, schemas are batched by toolkit:
Reference: backend/core/agentpress/mcp_registry.py:236-300

Lazy Activation

MCP tools are not activated until first use, saving:
  • Startup time
  • Memory usage
  • Network calls to MCP servers

Tools

Learn about the broader tool system

Agents

Understand how agents use MCP tools

Credentials

Manage MCP authentication

Profiles

Configure MCP profiles