Skip to main content

McpServerBuilder

Struct McpServerBuilder 

Source
pub struct McpServerBuilder { /* private fields */ }
Expand description

Builder for composing generated MCP server registrars.

Implementations§

Source§

impl McpServerBuilder

Source

pub fn new( server_name: impl Into<Cow<'static, str>>, server_version: impl Into<Cow<'static, str>>, ) -> Self

Create a builder with advertised server metadata.

Source

pub fn register<Register>(self, register: Register) -> Self
where Register: FnOnce(&mut McpServer) -> Result<(), McpToolError>,

Runs a registrar against the server being built.

Source

pub fn tool<Call>(self, definition: ToolDefinition, call: Call) -> Self
where Call: Fn(McpToolCall) -> ToolCallResult + Send + Sync + 'static,

Add a synchronous MCP tool to the server being built.

Source

pub fn typed_tool<Input, Call>( self, definition: McpTypedTool<Input>, call: Call, ) -> Self
where Input: McpToolInput, Call: Fn(Input) -> ToolCallResult + Send + Sync + 'static,

Add a synchronous typed MCP tool to the server being built.

Source

pub fn tool_async<Call, Fut>( self, definition: ToolDefinition, call: Call, ) -> Self
where Call: Fn(McpToolCall) -> Fut + Send + Sync + 'static, Fut: Future<Output = ToolCallResult> + Send + 'static,

Add an async MCP tool to the server being built.

Source

pub fn typed_tool_async<Input, Call, Fut>( self, definition: McpTypedTool<Input>, call: Call, ) -> Self
where Input: McpToolInput, Call: Fn(Input) -> Fut + Send + Sync + 'static, Fut: Future<Output = ToolCallResult> + Send + 'static,

Add an async typed MCP tool to the server being built.

Source

pub fn resource<Read>(self, definition: ResourceDefinition, read: Read) -> Self
where Read: Fn() -> ReadResourceResult + Send + Sync + 'static,

Add a static MCP resource to the server being built.

Source

pub fn resource_async<Read, Fut>( self, definition: ResourceDefinition, read: Read, ) -> Self
where Read: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<ReadResourceResult, ErrorData>> + Send + 'static,

Add an async MCP resource to the server being built.

Source

pub fn resource_template(self, definition: ResourceTemplateDefinition) -> Self

Add an MCP resource template to the server being built.

Source

pub fn prompt<Get>(self, definition: PromptDefinition, get: Get) -> Self
where Get: Fn(Option<JsonObject>) -> GetPromptResult + Send + Sync + 'static,

Add a static MCP prompt to the server being built.

Source

pub fn prompt_async<Get, Fut>( self, definition: PromptDefinition, get: Get, ) -> Self
where Get: Fn(Option<JsonObject>) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<GetPromptResult, ErrorData>> + Send + 'static,

Add an async MCP prompt to the server being built.

Source

pub fn build(self) -> Result<McpServer, McpToolError>

Finish the builder and return the composed server.

§Errors

Returns the first McpToolError produced by a builder registrar.

Source

pub async fn serve_stdio(self) -> ServeStdioResult

Build and serve this server over stdin/stdout using the MCP stdio transport.

§Errors

Returns an error when a builder registrar fails, stdio serving fails, or the service task fails.

Source

pub fn serve_stdio_blocking(self) -> ServeStdioResult

Build and serve this server over stdin/stdout on a new Tokio runtime.

§Errors

Returns an error when a builder registrar fails, the Tokio runtime cannot be created, stdio serving fails, or the service task fails.

Trait Implementations§

Source§

impl Clone for McpServerBuilder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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