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.

Diagram

MCP Integration

🤖 Agent

🔌 MCP

📁 Files

🌐 Web

💾 Memory

Quick Start

  1. 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?;
  2. 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?;
  3. 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

Diagram
ServerMCPAgentUserServerMCPAgentUser“Save this note”list_tools()Get available tools[save_note, read_note]call_tool(“save_note”, args)Execute toolResultTool result“Note saved!”

Transport Types

Choose how to connect to MCP servers:

Diagram

Choose Transport

Local subprocess

Remote API

Realtime

🖥️ Stdio

Local Tools

🌐 HTTP

Remote Services

🔌 WebSocket

Live Updates

TransportUse CaseExample
StdioLocal subprocessnpx @anthropic/mcp-server-*
HTTPRemote APIhttps://api.example.com/mcp
WebSocketRealtime connectionwss://live.example.com/mcp

Configuration Options

MCPBuilder Methods

MethodSignatureDescription
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

MethodSignatureDescription
connect()async fn connect(&mut self) -> Result<()>Connect to server
disconnect()async fn disconnect(&mut self) -> Result<()>Disconnect
is_connected()fn is_connected(&self) -> boolCheck 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

ServerPurposeCommand
MemoryPersistent memory@anthropic/mcp-server-memory
FilesystemFile operations@anthropic/mcp-server-filesystem
FetchHTTP requests@anthropic/mcp-server-fetch
GitHubGitHub 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.


Related