Expand description
MCP Client Implementation
This crate provides a client for connecting to MCP (Model Context Protocol) servers. It enables programmatic interaction with MCP servers for testing, proxying, and building multi-hop MCP architectures.
§Quick Start
ⓘ
use pulseengine_mcp_client::{McpClient, StdioClientTransport};
use tokio::process::Command;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Spawn an MCP server as a child process
let mut child = Command::new("my-mcp-server")
.stdin(std::process::Stdio::piped())
.stdout(std::process::Stdio::piped())
.spawn()?;
// Create transport from child process streams
let stdin = child.stdin.take().unwrap();
let stdout = child.stdout.take().unwrap();
let transport = StdioClientTransport::new(stdin, stdout);
// Create and initialize client
let mut client = McpClient::new(transport);
let server_info = client.initialize("my-client", "1.0.0").await?;
println!("Connected to: {}", server_info.server_info.name);
// Use the server
let tools = client.list_tools().await?;
for tool in tools.tools {
println!("Tool: {}", tool.name);
}
Ok(())
}Structs§
- Call
Tool Request Param - Tool call parameters
- Call
Tool Result - Tool call result
- Complete
Request Param - Completion request parameters
- Complete
Result - Complete result
- GetPrompt
Request Param - Get prompt parameters
- GetPrompt
Result - Get prompt result
- Implementation
- Server implementation information
- Initialize
Result - Initialize result
- List
Prompts Result - List prompts result
- List
Resource Templates Result - List resource templates result
- List
Resources Result - List resources result
- List
Tools Result - List tools result
- McpClient
- MCP Client for connecting to MCP servers
- Prompt
- Prompt definition
- Read
Resource Request Param - Read resource parameters
- Read
Resource Result - Read resource result
- Resource
- Resource definition
- Resource
Template - Resource template definition
- Server
Capabilities - Server capabilities configuration
- Stdio
Client Transport - Standard I/O transport for MCP client
- Tool
- Tool definition
Enums§
- Client
Error - Errors that can occur during MCP client operations
Traits§
- Client
Transport - Trait for client-side MCP transport
Type Aliases§
- Client
Result - Result type alias for client operations