Skip to main content

Server

Struct Server 

Source
pub struct Server { /* private fields */ }
Expand description

Builds an MCP server binary from services. See the module documentation.

Implementations§

Source§

impl Server

Source

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.

Source

pub fn env_prefix(self, prefix: &str) -> Self

The prefix of this server’s own variables: <PREFIX>_SERVICES, <PREFIX>_COMBINED and <PREFIX>_READ_ONLY.

Source

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.

Source

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.

Source

pub fn services(self, services: &[(&'static str, ServiceFactory)]) -> Self

Registers several services; see service.

Source

pub fn sign_in(self, sign_in: SignIn) -> Self

How people sign in. Defaults to SignIn::OwnerPassword.

Source

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.

Source

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);
Source

pub fn docs_url(self, url: &'static str) -> Self

Where the configuration is documented, for --help.

Source

pub fn name(&self) -> &'static str

The server’s name.

Source

pub fn version(&self) -> &'static str

The server’s version.

Source

pub fn registered(&self) -> Vec<&'static str>

The registered services’ names, in order.

Source

pub fn var(&self, suffix: &str) -> String

<PREFIX>_<suffix>.

Source

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.

Source

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).

Source

pub fn log_caps(services: &[Arc<dyn Service>]) -> Vec<&'static str>

Every service’s log caps.

Source

pub fn combined_tool_names(services: &[Arc<dyn Service>]) -> Vec<String>

The tool names /mcp offers, in order.

Source

pub async fn run(&self, loaded: Loaded) -> Result<()>

Starts logging and serves loaded until Ctrl-C or SIGTERM.

Source

pub async fn main(self) -> ExitCode

Everything main does: handles --version, --help and --healthcheck, reads the configuration from the process environment (printing every error), then runs.

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> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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