Crate mocopr_client

Source
Expand description

§MoCoPr Client

A high-level MCP client implementation for connecting to MCP servers.

This crate provides a convenient, async API for building MCP clients that can connect to any MCP server and perform operations like listing tools/resources, calling tools, reading resources, and more.

§Quick Start

use mocopr_client::McpClient;
use mocopr_core::prelude::*;
use serde_json::json;

#[tokio::main]
async fn main() -> Result<()> {
    // Connect to an MCP server via stdio
    let client = McpClient::connect_stdio(
        "python",
        &["server.py"],
        Implementation {
            name: "My Client".to_string(),
            version: "1.0.0".to_string(),
        },
        ClientCapabilities::default(),
    ).await?;

    // List available tools
    let tools = client.list_tools().await?;
    println!("Available tools: {:?}", tools);

    // Call a tool
    let result = client.call_tool("example_tool".to_string(), Some(json!({}))).await?;
    println!("Tool result: {:?}", result);

    Ok(())
}

§Transport Support

The client supports multiple transport mechanisms:

  • Stdio: For process-based communication with MCP servers
  • WebSocket: For real-time communication over the network
  • HTTP: For stateless request/response interactions

§Features

  • Async/await based API
  • Multiple transport support
  • Automatic capability negotiation
  • Type-safe API for MCP operations
  • Built-in error handling and retry logic
  • Comprehensive logging and debugging support

Modules§

prelude
Prelude for MCP client development

Structs§

McpClient
High-level MCP client for connecting to and interacting with MCP servers.
McpClientBuilder
Builder for creating MCP clients