pub struct Server { /* private fields */ }Expand description
Builds an MCP server binary from services. See the module documentation.
Implementations§
Source§impl Server
impl Server
Sourcepub fn new(name: &'static str, version: &'static str) -> Self
pub fn new(name: &'static str, version: &'static str) -> Self
A server called name (used in logs, traces and the combined endpoint’s serverInfo) at
version. Its environment prefix defaults to MCP and its tracing target to name with
- replaced by _; people sign in with the owner’s password unless you choose otherwise.
Sourcepub fn env_prefix(self, prefix: &str) -> Self
pub fn env_prefix(self, prefix: &str) -> Self
The prefix of this server’s own variables: <PREFIX>_SERVICES, <PREFIX>_COMBINED and
<PREFIX>_READ_ONLY.
Sourcepub fn crate_target(self, target: &str) -> Self
pub fn crate_target(self, target: &str) -> Self
The tracing target prefix of your crates, which DEBUG raises to debug. With
mcp_weather, mcp_weather_api::client is covered too.
Sourcepub fn service(self, name: &'static str, factory: ServiceFactory) -> Self
pub fn service(self, name: &'static str, factory: ServiceFactory) -> Self
Registers a service, mounted at /<name>. Services are mounted, and their tools listed on
/mcp, in registration order, or in the order <PREFIX>_SERVICES names them when it is
set.
§Panics
If name is not lowercase letters, digits and -, is mcp, or is already registered.
Sourcepub fn services(self, services: &[(&'static str, ServiceFactory)]) -> Self
pub fn services(self, services: &[(&'static str, ServiceFactory)]) -> Self
Registers several services; see service.
Sourcepub fn sign_in(self, sign_in: SignIn) -> Self
pub fn sign_in(self, sign_in: SignIn) -> Self
How people sign in. Defaults to SignIn::OwnerPassword.
Sourcepub fn icon(self, png: &'static [u8], svg: &'static str) -> Self
pub fn icon(self, png: &'static [u8], svg: &'static str) -> Self
The server’s icon: a 128x128 PNG, served as /favicon.ico and in the combined endpoint’s
serverInfo, and an SVG.
Sourcepub fn wrap_router(self, wrap: fn(Router) -> Router) -> Self
pub fn wrap_router(self, wrap: fn(Router) -> Router) -> Self
Wraps the whole application in your own layers, for example a request rate limiter or extra
routes. They sit outside every built-in layer except the security headers. Routes added
here, like /favicon.ico, are outside the body limit, the request metrics and the request
span:
use mcp_server_core::axum::{Router, routing::get};
fn extras(app: Router) -> Router {
app.route("/version", get(|| async { env!("CARGO_PKG_VERSION") }))
}
let server = Server::new("mcp-example", "1.0.0").wrap_router(extras);Sourcepub fn docs_url(self, url: &'static str) -> Self
pub fn docs_url(self, url: &'static str) -> Self
Where the configuration is documented, for --help.
Sourcepub fn registered(&self) -> Vec<&'static str>
pub fn registered(&self) -> Vec<&'static str>
The registered services’ names, in order.
Sourcepub fn load(&self, env: &mut ServiceEnv) -> Option<Loaded>
pub fn load(&self, env: &mut ServiceEnv) -> Option<Loaded>
Reads the configuration and builds every selected service. Every problem is recorded in
env.errors (each once); None means the server cannot start. Unselected services never
read their configuration.
Sourcepub fn router(&self, loaded: &Loaded, ctx: &ServiceContext) -> Router
pub fn router(&self, loaded: &Loaded, ctx: &ServiceContext) -> Router
The whole HTTP application: /healthz, the OAuth routes, each service at /<name> (its
own OAuth protected resource, under its read-only rule and audit log), /favicon.ico when
there is an icon and, when loaded.combined, every service’s tools together at /mcp,
passed through wrap_router. Every response, the wrapped routes’
too, sends X-Content-Type-Options: nosniff, and Strict-Transport-Security when the
server serves certificate files (TLS_CERT_PATH).
Sourcepub fn combined_tool_names(services: &[Arc<dyn Service>]) -> Vec<String>
pub fn combined_tool_names(services: &[Arc<dyn Service>]) -> Vec<String>
The tool names /mcp offers, in order.
Auto Trait Implementations§
impl Forget for Server
impl Freeze for Server
impl RefUnwindSafe for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl UnsafeUnpin for Server
impl UnwindSafe for Server
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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> ⓘ
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> ⓘ
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