pub struct ServerCoreBuilder { /* private fields */ }Expand description
Builder for constructing a ServerCore instance.
This builder provides a fluent API for configuring all aspects of the server
before creating the final ServerCore instance.
§Examples
use pmcp::server::builder::ServerCoreBuilder;
use pmcp::server::core::ServerCore;
use pmcp::{ToolHandler, ServerCapabilities};
use async_trait::async_trait;
use serde_json::Value;
struct MyTool;
#[async_trait]
impl ToolHandler for MyTool {
async fn handle(&self, args: Value, _extra: pmcp::RequestHandlerExtra) -> pmcp::Result<Value> {
Ok(serde_json::json!({"result": "success"}))
}
}
let server = ServerCoreBuilder::new()
.name("my-server")
.version("1.0.0")
.tool("my-tool", MyTool)
.capabilities(ServerCapabilities::tools_only())
.build()?;Implementations§
Source§impl ServerCoreBuilder
impl ServerCoreBuilder
Sourcepub fn name(self, name: impl Into<String>) -> Self
pub fn name(self, name: impl Into<String>) -> Self
Set the server name.
This is a required field that identifies the server implementation.
Sourcepub fn version(self, version: impl Into<String>) -> Self
pub fn version(self, version: impl Into<String>) -> Self
Set the server version.
This is a required field that identifies the server version.
Sourcepub fn capabilities(self, capabilities: ServerCapabilities) -> Self
pub fn capabilities(self, capabilities: ServerCapabilities) -> Self
Set the server capabilities.
Defines what features this server supports.
Sourcepub fn tool(
self,
name: impl Into<String>,
handler: impl ToolHandler + 'static,
) -> Self
pub fn tool( self, name: impl Into<String>, handler: impl ToolHandler + 'static, ) -> Self
Add a tool handler.
Tools are functions that can be called by the client.
Sourcepub fn tool_arc(
self,
name: impl Into<String>,
handler: Arc<dyn ToolHandler>,
) -> Self
pub fn tool_arc( self, name: impl Into<String>, handler: Arc<dyn ToolHandler>, ) -> Self
Add a tool handler with an Arc.
This variant is useful when you need to share the handler across multiple servers.
Sourcepub fn prompt(
self,
name: impl Into<String>,
handler: impl PromptHandler + 'static,
) -> Self
pub fn prompt( self, name: impl Into<String>, handler: impl PromptHandler + 'static, ) -> Self
Add a prompt handler.
Prompts are templates that generate messages for the client.
Sourcepub fn prompt_arc(
self,
name: impl Into<String>,
handler: Arc<dyn PromptHandler>,
) -> Self
pub fn prompt_arc( self, name: impl Into<String>, handler: Arc<dyn PromptHandler>, ) -> Self
Add a prompt handler with an Arc.
This variant is useful when you need to share the handler across multiple servers.
Sourcepub fn resources(self, handler: impl ResourceHandler + 'static) -> Self
pub fn resources(self, handler: impl ResourceHandler + 'static) -> Self
Set the resource handler.
Resources provide access to data that the client can read.
Sourcepub fn resources_arc(self, handler: Arc<dyn ResourceHandler>) -> Self
pub fn resources_arc(self, handler: Arc<dyn ResourceHandler>) -> Self
Set the resource handler with an Arc.
This variant is useful when you need to share the handler across multiple servers.
Sourcepub fn sampling(self, handler: impl SamplingHandler + 'static) -> Self
pub fn sampling(self, handler: impl SamplingHandler + 'static) -> Self
Set the sampling handler.
Sampling provides LLM capabilities for message generation.
Sourcepub fn sampling_arc(self, handler: Arc<dyn SamplingHandler>) -> Self
pub fn sampling_arc(self, handler: Arc<dyn SamplingHandler>) -> Self
Set the sampling handler with an Arc.
This variant is useful when you need to share the handler across multiple servers.
Sourcepub fn auth_provider(self, provider: impl AuthProvider + 'static) -> Self
pub fn auth_provider(self, provider: impl AuthProvider + 'static) -> Self
Set the authentication provider.
The auth provider validates client authentication.
Sourcepub fn auth_provider_arc(self, provider: Arc<dyn AuthProvider>) -> Self
pub fn auth_provider_arc(self, provider: Arc<dyn AuthProvider>) -> Self
Set the authentication provider with an Arc.
This variant is useful when you need to share the provider across multiple servers.
Set the tool authorizer.
The tool authorizer provides fine-grained access control for tools.
Set the tool authorizer with an Arc.
This variant is useful when you need to share the authorizer across multiple servers.
Sourcepub fn build(self) -> Result<ServerCore>
pub fn build(self) -> Result<ServerCore>
Build the ServerCore instance.
Returns an error if required fields (name, version) are not set.