MCPClientProtocol interface enables custom MCP client implementations while maintaining compatibility with the PraisonAI agent system.
Quick Start
Protocol Methods
| Method | Sync | Async | Description |
|---|---|---|---|
list_tools() | ✅ | ✅ (async_list_tools) | List available tools from the server |
get_tools() | ✅ | ✅ (async_get_tools) | Alias for list_tools() (backward compatibility) |
call_tool(name, args) | ✅ | ✅ (async_call_tool) | Execute a tool with given arguments |
shutdown() | ✅ | ✅ (async_shutdown) | Clean up resources and connections |
Implementation Example
HTTP-based MCP Client
Protocol Compliance
The protocol interface provides runtime type checking:Required Methods
Every MCP client implementation must provide:Common Use Cases
Database MCP Client
Connect to databases directly without external servers:Mock MCP Client (Testing)
Create predictable responses for testing:Best Practices
Implement Both Sync and Async
Implement Both Sync and Async
While not strictly required, providing both sync and async versions of methods ensures compatibility with different agent execution modes.
Handle Errors Gracefully
Handle Errors Gracefully
Implement proper error handling in
call_tool(). Raise descriptive exceptions that help with debugging and user feedback.Resource Cleanup
Resource Cleanup
Always implement
shutdown() to clean up connections, files, or other resources. This prevents resource leaks in long-running applications.Validate Tool Schemas
Validate Tool Schemas
Return proper JSON schemas in
list_tools() to enable agent tool validation and better error messages.Related
Load MCP Tools
Wire configured MCP servers into agents with one line
MCP Tool Filtering
Restrict which MCP tools an agent can see and call

