Skip to main content

Module client

Module client 

Source
Expand description

Client implementation for the Model Context Protocol (MCP).

The MCP client provides a synchronous interface for interacting with MCP servers, supporting operations like:

  • Tool execution
  • Prompt management
  • Resource handling
  • Server capability detection

§Usage

Basic usage with stdio transport:

use sovran_mcp::{McpClient, transport::StdioTransport};

// Create and start client
let transport = StdioTransport::new("npx", &["-y", "@modelcontextprotocol/server-everything"])?;
let mut client = McpClient::new(transport, None, None);
client.start()?;

// Use MCP features
if client.supports_tools() {
    let tools = client.list_tools()?;
    println!("Available tools: {}", tools.tools.len());
}

// Clean up
client.stop()?;

§Error Handling

The client uses McpError for error handling, which covers:

  • Transport errors (I/O, connection issues)
  • Protocol errors (JSON-RPC, serialization)
  • Capability errors (unsupported features)
  • Request timeouts
  • Command failures

§Thread Safety

The client spawns a message handling thread for processing responses and notifications. This thread is properly managed through the start() and stop() methods.

Structs§

McpClient
A client implementation of the Model Context Protocol (MCP).