pub struct McpServerBuilder { /* private fields */ }Expand description
Builder for McpServer — the main entry point for configuring your server.
Implementations§
Source§impl McpServerBuilder
impl McpServerBuilder
pub fn new() -> Self
Sourcepub fn name(self, name: impl Into<String>) -> Self
pub fn name(self, name: impl Into<String>) -> Self
Set the server name (shown to clients during handshake)
Sourcepub fn instructions(self, instructions: impl Into<String>) -> Self
pub fn instructions(self, instructions: impl Into<String>) -> Self
Human-readable instructions for how to use this server
Sourcepub fn auth(self, provider: DynAuthProvider) -> Self
pub fn auth(self, provider: DynAuthProvider) -> Self
Require authentication on all requests using the given provider.
Requests with no or invalid credentials receive HTTP 401 on SSE/HTTP transports. Stdio transport is unaffected (it relies on process-level access control).
§Example
use mcp_kit::prelude::*;
use mcp_kit::auth::BearerTokenProvider;
use std::sync::Arc;
McpServer::builder()
.name("my-server")
.version("1.0")
.auth(Arc::new(BearerTokenProvider::new(["secret"])))
.build();Sourcepub fn optional_auth(self, provider: DynAuthProvider) -> Self
pub fn optional_auth(self, provider: DynAuthProvider) -> Self
Accept an auth provider but allow unauthenticated requests through.
Authenticated requests have an identity available via Auth; unauthenticated
requests have no identity and may reach handlers with None.
Sourcepub fn tool<M>(self, tool: Tool, handler: impl ToolHandler<M>) -> Self
pub fn tool<M>(self, tool: Tool, handler: impl ToolHandler<M>) -> Self
Register a tool with an explicit Tool descriptor and a handler function.
Sourcepub fn tool_def(self, def: ToolDef) -> Self
pub fn tool_def(self, def: ToolDef) -> Self
Register a tool using a pre-built ToolDef (from the #[tool] macro).
Sourcepub fn tool_fn<M>(
self,
name: impl Into<String>,
description: impl Into<String>,
handler: impl ToolHandler<M>,
) -> Self
pub fn tool_fn<M>( self, name: impl Into<String>, description: impl Into<String>, handler: impl ToolHandler<M>, ) -> Self
Convenience: register a no-parameter tool.
Sourcepub fn resource<M>(
self,
resource: Resource,
handler: impl ResourceHandler<M>,
) -> Self
pub fn resource<M>( self, resource: Resource, handler: impl ResourceHandler<M>, ) -> Self
Register a static resource (exact URI match).
Sourcepub fn resource_template<M>(
self,
template: ResourceTemplate,
handler: impl ResourceHandler<M>,
) -> Self
pub fn resource_template<M>( self, template: ResourceTemplate, handler: impl ResourceHandler<M>, ) -> Self
Register a URI-template resource (e.g. "file://{path}").
Sourcepub fn resource_def(self, def: ResourceDef) -> Self
pub fn resource_def(self, def: ResourceDef) -> Self
Register a resource using a pre-built ResourceDef (from the #[resource] macro).
Sourcepub fn prompt<M>(self, prompt: Prompt, handler: impl PromptHandler<M>) -> Self
pub fn prompt<M>(self, prompt: Prompt, handler: impl PromptHandler<M>) -> Self
Register a prompt template.
Sourcepub fn prompt_def(self, def: PromptDef) -> Self
pub fn prompt_def(self, def: PromptDef) -> Self
Register a prompt using a pre-built PromptDef (from the #[prompt] macro).