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#![warn(clippy::all)]
69#![warn(clippy::pedantic)]
70#![warn(clippy::unwrap_used)]
71#![warn(clippy::must_use_candidate)]
72#![allow(clippy::module_name_repetitions)]
73
74pub mod builder;
75pub mod client;
76pub mod discovery;
77pub mod handler;
78pub mod pool;
79
80// Re-export commonly used types
81pub use builder::ClientBuilder;
82pub use client::Client;
83pub use discovery::{DiscoveredServer, ServerDiscovery};
84pub use handler::ClientHandler;
85pub use pool::{ClientPool, ClientPoolBuilder, PoolConfig, PoolStats};
86
87/// Prelude module for convenient imports.
88pub mod prelude {
89 pub use crate::builder::ClientBuilder;
90 pub use crate::client::Client;
91 pub use crate::discovery::{DiscoveredServer, ServerDiscovery};
92 pub use crate::handler::ClientHandler;
93 pub use crate::pool::{ClientPool, ClientPoolBuilder, PoolConfig, PoolStats};
94}