Model Context Protocol (MCP) Integration
The Proxy Base Agent (PBA) supports dynamic extension of its capabilities at runtime through the Model Context Protocol (MCP). MCP allows PBA to connect to external servers that offer specialized tools and functionalities.
What is MCP?
MCP is a standardized protocol designed for language models and agents to interact with external services and tools securely and efficiently. An MCP server exposes a set of tools, each with a defined schema, that connected agents can invoke.
Think of MCP servers as plug-and-play capability providers for your agent.
How PBA Uses MCP
PBA integrates with MCP through a built-in workflow facilitated by specific tools and internal mechanisms:
- Discovery (
list_mcp_servers
Tool): The agent can use the built-inlist_mcp_servers
tool to discover available MCP servers defined in its configuration (typicallyagent/mcp/servers/servers_list.json
). This tool returns information about each server, including its name, description, and identifier. - Connection (
add_mcp_server
Tool): Based on its planning and the information fromlist_mcp_servers
, the agent can decide to connect to a specific server using the built-inadd_mcp_server
tool, providing the server's unique identifier. - Runtime Integration: When
add_mcp_server
is called:- PBA's
MCPHost
establishes a connection to the server using anMCPClient
. - The agent retrieves the list of tools offered by that server.
- These external tools are converted into standard PBA
Tool
objects. - The agent calls its internal
add_tools()
method. - Crucially,
add_tools()
triggersagent.configure()
, which rebuilds theAgentStateMachine
and reconfigures the underlying PSEStructuringEngine
with the updated list of tools (including the newly added ones from the MCP server).
- PBA's
- Reliable Usage: Once connected and configured, the tools from the MCP server are seamlessly available within the agent's
ToolCallState
. The agent can generate calls to these tools, and PSE provides the same guarantee of structural validity for these dynamically added tools as it does for locally defined tools.
Benefits of MCP Integration
- Dynamic Adaptability: Add or remove agent capabilities without restarting or modifying the agent's core code.
- Extensibility: Easily integrate specialized third-party services or internal microservices.
- Modularity: Keep specialized logic separate from the core agent framework.
- Reliability: Dynamically added tools still benefit from PSE's schema enforcement guarantees.
Managing Servers
- Available servers are defined in
agent/mcp/servers/servers_list.json
. You can add definitions for custom or private MCP servers here. - MCP servers may require specific environment variables for authentication or configuration. PBA attempts to pass these from the agent's environment to the server process during connection (see
agent/mcp/client.py
). Ensure necessary variables are set in the agent's environment.
MCP provides a powerful mechanism for creating adaptive and highly capable agents by decoupling core logic from specialized, dynamically loaded functionalities.