Adapters API Reference
Adapters provide a bridge between MCP tools and different agent frameworks. They convert MCP tool definitions into framework-specific formats.BaseAdapter
The abstract base class for all adapters.BaseAdapter()
Base adapter class that defines the interface for tool conversion. Methods:async create_tools(client: MCPClient, **kwargs) -> List[Any]
Converts MCP tools to framework-specific tool format. Parameters:client
(MCPClient): The MCP client instance**kwargs
: Additional framework-specific parameters
List[Any]
: List of framework-specific tool objects
NotImplementedError
: Must be implemented by subclasses
LangChainAdapter
Adapter for LangChain framework integration.LangChainAdapter()
Creates tools compatible with LangChain agents and runnables. Example:Methods
async create_tools(client: MCPClient, allowed_tools=None, disallowed_tools=None) -> List[BaseTool]
Converts MCP tools to LangChain BaseTool objects. Parameters:client
(MCPClient): The MCP client instanceallowed_tools
(List[str], optional): Whitelist of tool names to includedisallowed_tools
(List[str], optional): Blacklist of tool names to exclude
List[BaseTool]
: List of LangChain tool objects
async create_tool(client: MCPClient, tool_definition: dict) -> BaseTool
Creates a single LangChain tool from an MCP tool definition. Parameters:client
(MCPClient): The MCP client instancetool_definition
(dict): MCP tool definition
BaseTool
: LangChain tool object
Tool Filtering
Adapters support various filtering mechanisms to control which tools are available.Whitelist Filtering
Only include specified tools:Blacklist Filtering
Exclude potentially dangerous tools:Pattern-Based Filtering
Use patterns for flexible filtering:Custom Adapters
Create custom adapters for other frameworks:CrewAI Adapter Example
AutoGen Adapter Example
Tool Metadata
Adapters preserve and enhance tool metadata:Accessing Tool Information
Enhanced Tool Descriptions
Error Handling
Adapters handle various error conditions:Tool Creation Errors
Runtime Error Handling
Performance Optimization
Lazy Tool Creation
Batch Tool Creation
Integration Examples
LangChain Agent
Custom Framework Integration
See Also
- MCPClient API Reference - Core client functionality
- MCPAgent API Reference - High-level agent interface
- Building Custom Agents - Creating custom agent implementations