pub struct Server { /* private fields */ }Expand description
An MCP server instance.
Servers are built using ServerBuilder and can run on various
transports (stdio, SSE, WebSocket).
Implementations§
Source§impl Server
impl Server
Sourcepub fn new(name: impl Into<String>, version: impl Into<String>) -> ServerBuilder
pub fn new(name: impl Into<String>, version: impl Into<String>) -> ServerBuilder
Creates a new server builder.
Sourcepub fn info(&self) -> &ServerInfo
pub fn info(&self) -> &ServerInfo
Returns the server info.
Sourcepub fn capabilities(&self) -> &ServerCapabilities
pub fn capabilities(&self) -> &ServerCapabilities
Returns the server capabilities.
Sourcepub fn resource_templates(&self) -> Vec<ResourceTemplate>
pub fn resource_templates(&self) -> Vec<ResourceTemplate>
Lists all registered resource templates.
Sourcepub fn task_manager(&self) -> Option<&SharedTaskManager>
pub fn task_manager(&self) -> Option<&SharedTaskManager>
Returns the task manager, if configured.
Returns None if background tasks are not enabled.
Sourcepub fn into_router(self) -> Router
pub fn into_router(self) -> Router
Consumes the server and returns its router.
This is used for mounting one server’s components into another.
Sourcepub fn has_tools(&self) -> bool
pub fn has_tools(&self) -> bool
Returns the capabilities this server provides.
This is useful when determining what components a server has before mounting.
Sourcepub fn has_resources(&self) -> bool
pub fn has_resources(&self) -> bool
Returns whether this server has resources.
Sourcepub fn has_prompts(&self) -> bool
pub fn has_prompts(&self) -> bool
Returns whether this server has prompts.
Sourcepub fn stats(&self) -> Option<StatsSnapshot>
pub fn stats(&self) -> Option<StatsSnapshot>
Returns a point-in-time snapshot of server statistics.
Returns None if statistics collection is disabled.
Sourcepub fn stats_collector(&self) -> Option<&ServerStats>
pub fn stats_collector(&self) -> Option<&ServerStats>
Returns the raw statistics collector.
Useful for advanced scenarios where you need direct access.
Returns None if statistics collection is disabled.
Sourcepub fn display_stats(&self)
pub fn display_stats(&self)
Renders a stats panel to stderr, if stats are enabled.
Sourcepub fn console_config(&self) -> &ConsoleConfig
pub fn console_config(&self) -> &ConsoleConfig
Returns the console configuration.
Sourcepub fn run_stdio(self) -> !
pub fn run_stdio(self) -> !
Runs the server on stdio transport.
This is the primary way to run MCP servers as subprocesses. Creates a request-scoped Cx and runs the server loop.
Sourcepub fn run_stdio_with_cx(self, cx: &Cx) -> !
pub fn run_stdio_with_cx(self, cx: &Cx) -> !
Runs the server on stdio with a provided Cx.
This allows integration with a real asupersync runtime.
Sourcepub fn run_transport<T>(self, transport: T) -> !
pub fn run_transport<T>(self, transport: T) -> !
Runs the server on a custom transport with a request-scoped Cx.
This is useful for SSE/WebSocket integrations where the transport is provided by an external server framework.
Sourcepub fn run_transport_with_cx<T>(self, cx: &Cx, transport: T) -> !
pub fn run_transport_with_cx<T>(self, cx: &Cx, transport: T) -> !
Runs the server on a custom transport with a provided Cx.
This allows integration with a real asupersync runtime.
Sourcepub fn run_transport_returning_with_cx<T>(self, cx: &Cx, transport: T)
pub fn run_transport_returning_with_cx<T>(self, cx: &Cx, transport: T)
Runs the server on a custom transport and returns when the transport closes or the Cx is cancelled.
Unlike run_transport_with_cx, this does not call
std::process::exit on shutdown. This is useful for tests and embedding where you need
the server loop to be joinable.
Sourcepub fn run_transport_returning<T>(self, transport: T)
pub fn run_transport_returning<T>(self, transport: T)
Runs the server on a custom transport and returns when the transport closes.
This uses a request-scoped Cx, but unlike run_transport it does
not exit the process.
Sourcepub fn run_sse<W, R>(
self,
writer: W,
request_source: R,
endpoint_url: impl Into<String>,
) -> !
pub fn run_sse<W, R>( self, writer: W, request_source: R, endpoint_url: impl Into<String>, ) -> !
Runs the server using SSE transport with a testing Cx.
This is a convenience wrapper around SseServerTransport.
Sourcepub fn run_sse_with_cx<W, R>(
self,
cx: &Cx,
writer: W,
request_source: R,
endpoint_url: impl Into<String>,
) -> !
pub fn run_sse_with_cx<W, R>( self, cx: &Cx, writer: W, request_source: R, endpoint_url: impl Into<String>, ) -> !
Runs the server using SSE transport with a provided Cx.
Sourcepub fn run_websocket<R, W>(self, reader: R, writer: W) -> !
pub fn run_websocket<R, W>(self, reader: R, writer: W) -> !
Runs the server using WebSocket transport with a testing Cx.
This is a convenience wrapper around WsTransport.