Skip to main content

Server

Struct Server 

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

A registered MCP server.

Registrations live in BTreeMaps so tools/list comes back in a stable order — an agent that re-reads the list should not see it shuffle.

Implementations§

Source§

impl Server

Source

pub fn new(name: impl Into<String>, version: impl Into<String>) -> Self

Source

pub fn instructions(self, instructions: impl Into<String>) -> Self

Advice shown to the model once, at the start of a session.

Source

pub fn tool(self, tool: Tool) -> Self

Source

pub fn resource(self, resource: Resource) -> Self

Source

pub fn prompt(self, prompt: Prompt) -> Self

Source

pub fn name(&self) -> &str

Source

pub fn tool_names(&self) -> Vec<&str>

Source

pub fn capabilities(&self) -> Json

What this server advertises during the handshake.

Only the capabilities that are actually backed by a registration are announced: a client that sees tools and gets an empty list has been told something untrue.

Source

pub async fn handle_text(&self, text: &str) -> Option<String>

Handle one complete transport frame, batches included.

None means there is nothing to send back — the frame held only notifications, which JSON-RPC answers with silence.

Source

pub async fn handle_value(&self, value: &Json) -> Option<Json>

Handle one decoded message, returning the answer it deserves.

Source

pub async fn dispatch( &self, method: &str, params: Json, ) -> Result<Json, RpcError>

Route one method to its handler.

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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