pulseengine_mcp_client/
lib.rs

1//! MCP Client Implementation
2//!
3//! This crate provides a client for connecting to MCP (Model Context Protocol) servers.
4//! It enables programmatic interaction with MCP servers for testing, proxying, and
5//! building multi-hop MCP architectures.
6//!
7//! # Quick Start
8//!
9//! ```rust,ignore
10//! use pulseengine_mcp_client::{McpClient, StdioClientTransport};
11//! use tokio::process::Command;
12//!
13//! #[tokio::main]
14//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
15//!     // Spawn an MCP server as a child process
16//!     let mut child = Command::new("my-mcp-server")
17//!         .stdin(std::process::Stdio::piped())
18//!         .stdout(std::process::Stdio::piped())
19//!         .spawn()?;
20//!
21//!     // Create transport from child process streams
22//!     let stdin = child.stdin.take().unwrap();
23//!     let stdout = child.stdout.take().unwrap();
24//!     let transport = StdioClientTransport::new(stdin, stdout);
25//!
26//!     // Create and initialize client
27//!     let mut client = McpClient::new(transport);
28//!     let server_info = client.initialize("my-client", "1.0.0").await?;
29//!     println!("Connected to: {}", server_info.server_info.name);
30//!
31//!     // Use the server
32//!     let tools = client.list_tools().await?;
33//!     for tool in tools.tools {
34//!         println!("Tool: {}", tool.name);
35//!     }
36//!
37//!     Ok(())
38//! }
39//! ```
40
41mod client;
42mod error;
43mod transport;
44
45#[cfg(test)]
46mod client_tests;
47#[cfg(test)]
48mod transport_tests;
49
50pub use client::McpClient;
51pub use error::{ClientError, ClientResult};
52pub use transport::{ClientTransport, StdioClientTransport};
53
54// Re-export protocol types for convenience
55pub use pulseengine_mcp_protocol::{
56    // Tools
57    CallToolRequestParam,
58    CallToolResult,
59    // Completions
60    CompleteRequestParam,
61    CompleteResult,
62    // Prompts
63    GetPromptRequestParam,
64    GetPromptResult,
65    // Core types
66    Implementation,
67    InitializeResult,
68    ListPromptsResult,
69    // Resources
70    ListResourceTemplatesResult,
71    ListResourcesResult,
72    ListToolsResult,
73    Prompt,
74    ReadResourceRequestParam,
75    ReadResourceResult,
76    Resource,
77    ResourceTemplate,
78    // Capabilities
79    ServerCapabilities,
80    Tool,
81};