mcpkit_client/lib.rs
1//! Client implementation for the MCP SDK.
2//!
3//! This crate provides the client-side implementation for the Model Context
4//! Protocol. It includes a fluent client API, server discovery, and connection
5//! management.
6//!
7//! # Overview
8//!
9//! The MCP client allows AI applications to:
10//!
11//! - Connect to MCP servers via various transports
12//! - Discover and invoke tools
13//! - Read resources
14//! - Get prompts
15//! - Track long-running tasks
16//!
17//! # Example
18//!
19//! ```no_run
20//! use mcpkit_client::{Client, ClientBuilder};
21//! use mcpkit_transport::SpawnedTransport;
22//!
23//! #[tokio::main]
24//! async fn main() -> Result<(), mcpkit_core::error::McpError> {
25//! // Spawn an MCP server as a subprocess and connect via stdio
26//! let transport = SpawnedTransport::spawn("my-mcp-server", &[] as &[&str]).await?;
27//!
28//! let client = ClientBuilder::new()
29//! .name("my-client")
30//! .version("1.0.0")
31//! .build(transport)
32//! .await?;
33//!
34//! // List available tools
35//! let tools = client.list_tools().await?;
36//! for tool in &tools {
37//! println!("Tool: {}", tool.name);
38//! }
39//!
40//! // Call a tool
41//! let result = client.call_tool("add", serde_json::json!({
42//! "a": 1,
43//! "b": 2
44//! })).await?;
45//!
46//! Ok(())
47//! }
48//! ```
49//!
50//! # Client Handler
51//!
52//! For handling server-initiated requests (sampling, elicitation), implement
53//! the [`ClientHandler`] trait:
54//!
55//! ```rust
56//! use mcpkit_client::ClientHandler;
57//! use mcpkit_core::types::{CreateMessageRequest, CreateMessageResult};
58//! use mcpkit_core::error::McpError;
59//!
60//! struct MyHandler;
61//!
62//! impl ClientHandler for MyHandler {
63//! // Override default methods as needed
64//! }
65//! ```
66
67#![deny(missing_docs)]
68
69pub mod builder;
70pub mod client;
71pub mod discovery;
72pub mod handler;
73pub mod pool;
74
75// Re-export commonly used types
76pub use builder::ClientBuilder;
77pub use client::Client;
78pub use discovery::{DiscoveredServer, ServerDiscovery};
79pub use handler::ClientHandler;
80pub use pool::{ClientPool, ClientPoolBuilder, PoolConfig, PoolStats};
81
82/// Prelude module for convenient imports.
83pub mod prelude {
84 pub use crate::builder::ClientBuilder;
85 pub use crate::client::Client;
86 pub use crate::discovery::{DiscoveredServer, ServerDiscovery};
87 pub use crate::handler::ClientHandler;
88 pub use crate::pool::{ClientPool, ClientPoolBuilder, PoolConfig, PoolStats};
89}