pub struct ServerBuilder { /* private fields */ }Expand description
Fluent builder for Server
Implementations§
Source§impl ServerBuilder
impl ServerBuilder
Sourcepub fn new(name: impl Into<String>, version: impl Into<String>) -> Self
pub fn new(name: impl Into<String>, version: impl Into<String>) -> Self
Create new server builder
Sourcepub fn with_capabilities(self, capabilities: ServerCapabilities) -> Self
pub fn with_capabilities(self, capabilities: ServerCapabilities) -> Self
Set server capabilities
Sourcepub fn with_instructions(self, instructions: impl Into<String>) -> Self
pub fn with_instructions(self, instructions: impl Into<String>) -> Self
Set server instructions for LLMs
Instructions help LLMs understand how to use the server’s tools, resources, and prompts. They are sent during initialization and can be thought of as hints added to the system prompt.
§Example
use mcp_host::prelude::*;
let server = server("my-server", "1.0.0")
.with_instructions("Use the data tools for queries. Verify IDs before updates.")
.build();Sourcepub fn with_tools(self, list_changed: bool) -> Self
pub fn with_tools(self, list_changed: bool) -> Self
Enable tools capability
Sourcepub fn with_resources(self, list_changed: bool, subscribe: bool) -> Self
pub fn with_resources(self, list_changed: bool, subscribe: bool) -> Self
Enable resources capability
Sourcepub fn with_resource_templates(self) -> Self
pub fn with_resource_templates(self) -> Self
Enable resource templates capability
Sourcepub fn with_prompts(self, list_changed: bool) -> Self
pub fn with_prompts(self, list_changed: bool) -> Self
Enable prompts capability
Sourcepub fn with_logging(self) -> Self
pub fn with_logging(self) -> Self
Enable logging capability
Sourcepub fn with_tasks(self, list: bool, cancel: bool) -> Self
pub fn with_tasks(self, list: bool, cancel: bool) -> Self
Enable tasks capability
Sourcepub fn add_middleware(self, middleware: MiddlewareFn) -> Self
pub fn add_middleware(self, middleware: MiddlewareFn) -> Self
Add middleware to the server
Sourcepub fn with_logging_middleware(self) -> Self
pub fn with_logging_middleware(self) -> Self
Add logging middleware
Sourcepub fn with_validation_middleware(self) -> Self
pub fn with_validation_middleware(self) -> Self
Add validation middleware
Sourcepub fn with_circuit_breaker(self, config: ToolBreakerConfig) -> Self
pub fn with_circuit_breaker(self, config: ToolBreakerConfig) -> Self
Configure circuit breakers for tools
Circuit breakers protect against cascading failures by temporarily disabling tools that are failing repeatedly.
§Example
use mcp_host::prelude::*;
let server = server("my-server", "1.0.0")
.with_circuit_breaker(ToolBreakerConfig {
failure_threshold: 3,
failure_window_secs: 30.0,
half_open_timeout_secs: 15.0,
success_threshold: 1,
})
.build();Sourcepub fn with_retry(self, config: ResourceRetryConfig) -> Self
pub fn with_retry(self, config: ResourceRetryConfig) -> Self
Configure retry behavior for resources
Resources will retry failed reads using exponential backoff with jitter.
§Example
use mcp_host::prelude::*;
let server = server("my-server", "1.0.0")
.with_retry(ResourceRetryConfig {
max_attempts: 5,
base_delay_ms: 200,
multiplier: 2.0,
max_delay_ms: 5000,
jitter_factor: 1.0,
})
.build();Sourcepub fn with_rate_limit(
self,
requests_per_second: f64,
burst_capacity: usize,
) -> Self
pub fn with_rate_limit( self, requests_per_second: f64, burst_capacity: usize, ) -> Self
Add rate limiting middleware
Rate limits requests using the GCRA (Generic Cell Rate Algorithm).
§Arguments
requests_per_second- Maximum requests allowed per secondburst_capacity- Number of requests that can burst instantly
§Example
use mcp_host::prelude::*;
let server = server("my-server", "1.0.0")
.with_rate_limit(100.0, 20) // 100 req/s with burst of 20
.build();Sourcepub fn with_rate_limiter(self, limiter: Arc<RateLimiter>) -> Self
pub fn with_rate_limiter(self, limiter: Arc<RateLimiter>) -> Self
Add rate limiting with custom configuration