pub struct McpServerBuilder { /* private fields */ }Expand description
Builder for composing generated MCP server registrars.
Implementations§
Source§impl McpServerBuilder
impl McpServerBuilder
Sourcepub fn new(
server_name: impl Into<Cow<'static, str>>,
server_version: impl Into<Cow<'static, str>>,
) -> Self
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.
Sourcepub fn register<Register>(self, register: Register) -> Self
pub fn register<Register>(self, register: Register) -> Self
Runs a registrar against the server being built.
Sourcepub fn tool<Call>(self, definition: ToolDefinition, call: Call) -> Self
pub fn tool<Call>(self, definition: ToolDefinition, call: Call) -> Self
Add a synchronous MCP tool to the server being built.
Sourcepub fn typed_tool<Input, Call>(
self,
definition: McpTypedTool<Input>,
call: Call,
) -> Self
pub fn typed_tool<Input, Call>( self, definition: McpTypedTool<Input>, call: Call, ) -> Self
Add a synchronous typed MCP tool to the server being built.
Sourcepub fn tool_async<Call, Fut>(
self,
definition: ToolDefinition,
call: Call,
) -> Selfwhere
Call: Fn(McpToolCall) -> Fut + Send + Sync + 'static,
Fut: Future<Output = ToolCallResult> + Send + 'static,
pub fn tool_async<Call, Fut>(
self,
definition: ToolDefinition,
call: Call,
) -> Selfwhere
Call: Fn(McpToolCall) -> Fut + Send + Sync + 'static,
Fut: Future<Output = ToolCallResult> + Send + 'static,
Add an async MCP tool to the server being built.
Sourcepub fn typed_tool_async<Input, Call, Fut>(
self,
definition: McpTypedTool<Input>,
call: Call,
) -> Selfwhere
Input: McpToolInput,
Call: Fn(Input) -> Fut + Send + Sync + 'static,
Fut: Future<Output = ToolCallResult> + Send + 'static,
pub fn typed_tool_async<Input, Call, Fut>(
self,
definition: McpTypedTool<Input>,
call: Call,
) -> Selfwhere
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.
Sourcepub fn resource<Read>(self, definition: ResourceDefinition, read: Read) -> Self
pub fn resource<Read>(self, definition: ResourceDefinition, read: Read) -> Self
Add a static MCP resource to the server being built.
Sourcepub fn resource_async<Read, Fut>(
self,
definition: ResourceDefinition,
read: Read,
) -> Self
pub fn resource_async<Read, Fut>( self, definition: ResourceDefinition, read: Read, ) -> Self
Add an async MCP resource to the server being built.
Sourcepub fn resource_template(self, definition: ResourceTemplateDefinition) -> Self
pub fn resource_template(self, definition: ResourceTemplateDefinition) -> Self
Add an MCP resource template to the server being built.
Sourcepub fn prompt<Get>(self, definition: PromptDefinition, get: Get) -> Self
pub fn prompt<Get>(self, definition: PromptDefinition, get: Get) -> Self
Add a static MCP prompt to the server being built.
Sourcepub fn prompt_async<Get, Fut>(
self,
definition: PromptDefinition,
get: Get,
) -> Selfwhere
Get: Fn(Option<JsonObject>) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<GetPromptResult, ErrorData>> + Send + 'static,
pub fn prompt_async<Get, Fut>(
self,
definition: PromptDefinition,
get: Get,
) -> Selfwhere
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.
Sourcepub fn build(self) -> Result<McpServer, McpToolError>
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.
Sourcepub async fn serve_stdio(self) -> ServeStdioResult
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.
Sourcepub fn serve_stdio_blocking(self) -> ServeStdioResult
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.