Skip to main content

ServerCore

Struct ServerCore 

Source
pub struct ServerCore { /* private fields */ }
Available on non-WebAssembly only.
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn payload_limits(&self) -> &PayloadLimits

Get the configured payload limits.

Source

pub async fn is_initialized(&self) -> bool

Check if the server is initialized.

Source

pub async fn get_client_capabilities(&self) -> Option<ClientCapabilities>

Get client capabilities if available.

Trait Implementations§

Source§

impl MiddlewareExecutor for ServerCore

Source§

fn execute_tool_with_middleware<'life0, 'life1, 'async_trait>( &'life0 self, tool_name: &'life1 str, args: Value, extra: RequestHandlerExtra, ) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute a tool with full middleware chain processing. Read more
Source§

impl ProtocolHandler for ServerCore

Source§

fn handle_request<'life0, 'async_trait>( &'life0 self, id: RequestId, request: Request, auth_context: Option<AuthContext>, ) -> Pin<Box<dyn Future<Output = JSONRPCResponse> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle a single request and return a response. Read more
Source§

fn handle_notification<'life0, 'async_trait>( &'life0 self, notification: Notification, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle a notification (no response expected). Read more
Source§

fn capabilities(&self) -> &ServerCapabilities

Get server capabilities. Read more
Source§

fn info(&self) -> &Implementation

Get server information. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more