Struct McpClientBuilder

Source
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

Source

pub fn new() -> Self

Creates a new McpClient

Source

pub fn with_handler( self, sampling_handler: impl McpClientHandler + Send + Sync + 'static, ) -> Self

Creates a McpClientBuilder with a specified McpClientHandler

Source

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.

Source

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

Source

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

Source

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

Source

pub async fn build_with_server( self, server: impl McpServer, ) -> SessionResult<McpClient>

Builds a McpClient client that communicates with the specified McpServer

The specified McpServer will be owned by the returned McpClient.

Source

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§

Source§

impl Default for McpClientBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoResult<T> for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,