pub struct McpServer<S>{ /* private fields */ }Expand description
MCP server that dispatches JSON-RPC requests to the appropriate handler
Generic over S — the project-specific server state type.
Owns the shared state and tool registry. Transport layers feed parsed
requests into handle_request and send the returned responses.
Implementations§
Source§impl<S> McpServer<S>
impl<S> McpServer<S>
Sourcepub fn new(
name: impl Into<String>,
version: impl Into<String>,
tools: ToolRegistry<S>,
state: Arc<RwLock<S>>,
) -> McpServer<S>
pub fn new( name: impl Into<String>, version: impl Into<String>, tools: ToolRegistry<S>, state: Arc<RwLock<S>>, ) -> McpServer<S>
Create a server with the given name, version, tool registry, and shared state
Sourcepub async fn handle_raw(&self, raw: &str) -> Option<JsonRpcResponse>
pub async fn handle_raw(&self, raw: &str) -> Option<JsonRpcResponse>
Route a raw JSON string to the appropriate MCP handler
Parses the string as a JsonRpcRequest, dispatches it, and returns
the serialized response. Returns None for notifications.
Sourcepub async fn handle_request(
&self,
request: JsonRpcRequest,
) -> Option<JsonRpcResponse>
pub async fn handle_request( &self, request: JsonRpcRequest, ) -> Option<JsonRpcResponse>
Route a parsed JSON-RPC request to the appropriate MCP handler
Returns None for notifications (requests without an id).
Auto Trait Implementations§
impl<S> Freeze for McpServer<S>
impl<S> !RefUnwindSafe for McpServer<S>
impl<S> Send for McpServer<S>
impl<S> Sync for McpServer<S>
impl<S> Unpin for McpServer<S>
impl<S> UnsafeUnpin for McpServer<S>
impl<S> !UnwindSafe for McpServer<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more