MCP
Connect agents to external tools via Model Context Protocol
MCP (Model Context Protocol) connects your agent to external tools and services with zero code.
Quick Start
- Create MCP Client
rust use praisonai::{MCP, MCPBuilder}; // Create MCP client for memory server let mcp = MCP::new() .name("memory") .server("npx", &["-y", "@anthropic/mcp-server-memory"]) .build()?; // Connect to the server mcp.connect().await?; // List available tools let tools = mcp.list_tools().await?; - HTTP Transport
rust use praisonai::{MCP, MCPBuilder}; // Connect to remote MCP server let mcp = MCP::new() .name("remote") .http("https://api.example.com/mcp") .build()?; mcp.connect().await?; - WebSocket Transport
rust use praisonai::{MCP, MCPBuilder}; // Real-time MCP connection let mcp = MCP::new() .name("realtime") .websocket("wss://live.example.com/mcp") .build()?; mcp.connect().await?;
How It Works
Transport Types
Choose how to connect to MCP servers:
| Transport | Use Case | Example |
|---|---|---|
Stdio | Local subprocess | npx @anthropic/mcp-server-* |
HTTP | Remote API | https://api.example.com/mcp |
WebSocket | Realtime connection | wss://live.example.com/mcp |
Configuration Options
MCPBuilder Methods
| Method | Signature | Description |
|---|---|---|
name(n) | `fn name(impl Into |
) -> Self | Set server name | | server(cmd, args) | fn server(impl Into
, &[&str]) -> Self | Stdio transport | | http(url) | fn http(impl Into
) -> Self | HTTP transport | | websocket(url) | fn websocket(impl Into
) -> Self | WebSocket transport | | config(cfg) | fn config(MCPConfig) -> Self | Set full config | | security(sec) | fn security(SecurityConfig) -> Self | Set security | | build() | fn build(self) -> Result
` | Build client |
MCP Methods
| Method | Signature | Description |
|---|---|---|
connect() | async fn connect(&mut self) -> Result<()> | Connect to server |
disconnect() | async fn disconnect(&mut self) -> Result<()> | Disconnect |
is_connected() | fn is_connected(&self) -> bool | Check connection |
list_tools() | `async fn list_tools(&self) -> Result<Vec |
` | List available tools |
| list_resources() | `async fn list_resources(&self) -> Result<Vec
` | List resources |
| list_prompts() | `async fn list_prompts(&self) -> Result<Vec
` | List prompts |
| call_tool(call) | `async fn call_tool(&self, MCPCall) -> Result
| Execute tool | | read_resource(uri) | async fn read_resource(&self, &str) -> Result
` | Read resource |
Popular MCP Servers
| Server | Purpose | Command |
|---|---|---|
| Memory | Persistent memory | @anthropic/mcp-server-memory |
| Filesystem | File operations | @anthropic/mcp-server-filesystem |
| Fetch | HTTP requests | @anthropic/mcp-server-fetch |
| GitHub | GitHub API | @anthropic/mcp-server-github |
Best Practices
Use Stdio for local tools
Stdio transport is simplest and most reliable for local MCP servers.
Set appropriate timeouts
Increase timeout for slow-starting servers or remote connections.
Combine multiple servers
Chain servers for rich capabilities – memory + filesystem + web.