pub struct ServerCore { /* private fields */ }Expand description
Core server implementation without transport dependencies.
This struct contains all the business logic for an MCP server without any coupling to specific transport mechanisms. It can be used with various transport adapters to deploy to different environments.
Implementations§
Source§impl ServerCore
impl ServerCore
Sourcepub fn new(
info: Implementation,
capabilities: ServerCapabilities,
tools: HashMap<String, Arc<dyn ToolHandler>>,
prompts: HashMap<String, Arc<dyn PromptHandler>>,
tool_infos: HashMap<String, ToolInfo>,
prompt_infos: HashMap<String, PromptInfo>,
resources: Option<Arc<dyn ResourceHandler>>,
sampling: Option<Arc<dyn SamplingHandler>>,
auth_provider: Option<Arc<dyn AuthProvider>>,
tool_authorizer: Option<Arc<dyn ToolAuthorizer>>,
protocol_middleware: Arc<RwLock<EnhancedMiddlewareChain>>,
tool_middleware: Arc<RwLock<ToolMiddlewareChain>>,
task_router: Option<Arc<dyn TaskRouter>>,
task_store: Option<Arc<dyn TaskStore>>,
stateless_mode: bool,
payload_limits: PayloadLimits,
) -> Self
pub fn new( info: Implementation, capabilities: ServerCapabilities, tools: HashMap<String, Arc<dyn ToolHandler>>, prompts: HashMap<String, Arc<dyn PromptHandler>>, tool_infos: HashMap<String, ToolInfo>, prompt_infos: HashMap<String, PromptInfo>, resources: Option<Arc<dyn ResourceHandler>>, sampling: Option<Arc<dyn SamplingHandler>>, auth_provider: Option<Arc<dyn AuthProvider>>, tool_authorizer: Option<Arc<dyn ToolAuthorizer>>, protocol_middleware: Arc<RwLock<EnhancedMiddlewareChain>>, tool_middleware: Arc<RwLock<ToolMiddlewareChain>>, task_router: Option<Arc<dyn TaskRouter>>, task_store: Option<Arc<dyn TaskStore>>, stateless_mode: bool, payload_limits: PayloadLimits, ) -> Self
Create a new ServerCore with the given configuration.
Sourcepub fn with_server_request_dispatcher(
self,
dispatcher: Arc<ServerRequestDispatcher>,
) -> Self
pub fn with_server_request_dispatcher( self, dispatcher: Arc<ServerRequestDispatcher>, ) -> Self
Attach a server-to-client request dispatcher.
The dispatcher is the outbound-plus-correlation layer consumed at
handler dispatch sites so tool handlers can invoke
extra.peer()?.sample(...) mid-execution. Calling this is optional —
when absent, existing behaviour (no peer handle) is preserved.
Also constructs and caches a reusable Arc<dyn PeerHandle> so
per-request dispatch only clones the Arc (refcount bump), not
allocating a new DispatchPeerHandle each time.
Sourcepub fn with_suppress_double_wrap(self, suppress: HashSet<String>) -> Self
pub fn with_suppress_double_wrap(self, suppress: HashSet<String>) -> Self
Carry the per-tool TOUT-02 double-wrap tripwire opt-out set (D-08) from
the builder into the running ServerCore.
Threaded from ServerCoreBuilder::build so the tripwire at the Payload
wrap tail consults the SAME suppression set the high-level Server uses —
the two dispatchers can never drift on which tools are suppressed. An
empty set (the default) preserves the tripwire for every tool.
Sourcepub fn with_completions(
self,
provider: Option<Arc<dyn CompletionProviderTrait>>,
) -> Self
pub fn with_completions( self, provider: Option<Arc<dyn CompletionProviderTrait>>, ) -> Self
Carry the completion/complete provider (Phase 118.1-04, CONF-05) from
the builder into the running ServerCore.
Threaded from
ServerCoreBuilder::completions
rather than added to ServerCore::new’s already-eighteen-argument
signature, matching Self::with_suppress_double_wrap and
Self::with_server_request_dispatcher. None (the default) still
answers the spec CompleteResult shape with an empty values array.
Sourcepub fn payload_limits(&self) -> &PayloadLimits
pub fn payload_limits(&self) -> &PayloadLimits
Get the configured payload limits.
Sourcepub async fn is_initialized(&self) -> bool
pub async fn is_initialized(&self) -> bool
Check if the server is initialized.
Sourcepub async fn get_client_capabilities(&self) -> Option<ClientCapabilities>
pub async fn get_client_capabilities(&self) -> Option<ClientCapabilities>
Get client capabilities if available.