pub struct McpClientBuilder { /* private fields */ }
Expand description
Builder for creating McpClient
§Example
use mcp_attr::client::McpClientBuilder;
use mcp_attr::schema::Root;
use mcp_attr::server::{McpServer, mcp_server};
struct MyServer;
#[mcp_server]
impl McpServer for MyServer {}
let server = MyServer;
let roots = vec![Root {
name: Some("my_root".to_string()),
uri: "/path/to/root".to_string(),
}];
let client = McpClientBuilder::new()
.with_expose_internals(true)
.with_roots(roots)
.build_with_server(server)
.await?;
Implementations§
Source§impl McpClientBuilder
impl McpClientBuilder
Sourcepub fn with_handler(
self,
sampling_handler: impl McpClientHandler + Send + Sync + 'static,
) -> Self
pub fn with_handler( self, sampling_handler: impl McpClientHandler + Send + Sync + 'static, ) -> Self
Creates a McpClientBuilder
with a specified McpClientHandler
Sourcepub fn with_roots(self, roots: Vec<Root>) -> Self
pub fn with_roots(self, roots: Vec<Root>) -> Self
Specifies the values to be returned by roots/list
Also sets the roots capabilities that the MCP client will return.
Sourcepub fn with_expose_internals(self, expose_internals: bool) -> Self
pub fn with_expose_internals(self, expose_internals: bool) -> Self
Sets whether to expose internal information in errors
See Error
for details about internal information
Sourcepub async fn build(
self,
reader: impl AsyncBufRead + Send + Sync + 'static,
writer: impl AsyncWrite + Send + Sync + 'static,
) -> SessionResult<McpClient>
pub async fn build( self, reader: impl AsyncBufRead + Send + Sync + 'static, writer: impl AsyncWrite + Send + Sync + 'static, ) -> SessionResult<McpClient>
Builds a McpClient
client using the specified reader and writer
Sourcepub async fn build_with_command(
self,
command: &mut Command,
) -> SessionResult<McpClient>
pub async fn build_with_command( self, command: &mut Command, ) -> SessionResult<McpClient>
Launches a MCP server process with the specified command and builds McpClient
that communicates with it using stdio transport
Sourcepub async fn build_with_server(
self,
server: impl McpServer,
) -> SessionResult<McpClient>
pub async fn build_with_server( self, server: impl McpServer, ) -> SessionResult<McpClient>
Sourcepub fn build_raw(
self,
) -> (impl Handler, SessionOptions, InitializeRequestParams)
pub fn build_raw( self, ) -> (impl Handler, SessionOptions, InitializeRequestParams)
Builds a McpClient
using a custom method
This method returns the values needed for McpClient::initialize
.
It is provided for using transports that cannot be handled by build
, build_with_command
, or build_with_server
.
§Example
use mcp_attr::client::{McpClientBuilder, McpClient};
use tokio::process::Command;
use jsoncall::Session;
let mut command = Command::new("cargo");
command.args(&["run", "--bin", "mcp-attr", "--example", "char_count"]);
let builder = McpClientBuilder::new();
let (handler, options, initialize_params) = builder.build_raw();
let client = McpClient::initialize(Session::from_command(handler, &mut command, &options)?, initialize_params).await?;
Trait Implementations§
Auto Trait Implementations§
impl Freeze for McpClientBuilder
impl !RefUnwindSafe for McpClientBuilder
impl Send for McpClientBuilder
impl Sync for McpClientBuilder
impl Unpin for McpClientBuilder
impl !UnwindSafe for McpClientBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more