Skip to main content

McpCommand

Struct McpCommand 

Source
pub struct McpCommand {
    request: Request,
    reply: Sender<Result<Output, String>>,
    world: WorldId,
}
Available on crate feature mcp and non-WebAssembly only.
Expand description

A request together with the channel its result is sent back on.

Fields§

§request: Request§reply: Sender<Result<Output, String>>§world: WorldId

The world a Request::Job runs against.

Implementations§

Source§

impl McpCommand

Source

pub fn new( job: impl FnOnce(&mut World) -> Result<Output, String> + Send + 'static, ) -> (Self, Receiver<Result<Output, String>>)

Build a command that runs a job, and the receiver its result will arrive on.

The command starts out aimed at the world the receiving thread owns directly; redirect it with with_world.

Source

pub fn list_worlds() -> (Self, Receiver<Result<Output, String>>)

Build the command the list_worlds tool sends.

The host answers it with answer_worlds; the server holds no world list of its own.

Source

fn build(request: Request) -> (Self, Receiver<Result<Output, String>>)

Source

pub fn with_world(self, world: WorldId) -> Self

Direct the command at world.

Source

pub const fn world(&self) -> WorldId

The world a job runs against.

Source

pub const fn wants_worlds(&self) -> bool

Whether this is the list_worlds request, which the host answers with answer_worlds instead of dispatching a job.

Source

pub fn answer_worlds(self, worlds: Vec<WorldEntry>)

Answer the list_worlds request with the worlds the host carries.

The host names every world a tool can reach — the host world itself and each world it routes commands to, including ones on other threads — each with the name it was spawned under.

Source

pub fn fail(self, message: String)

Answer the command with an error without running it.

The host calls this when the world cannot be resolved, so the tool call still gets a readable message rather than a dropped channel.

Source

pub fn dispatch(self, world: &mut World)

Run the command’s job against world and send its result back.

A list_worlds request has no job; the host is expected to answer it with answer_worlds after checking wants_worlds.

A job that panics is caught and answered as an error: a world usually shares its thread with others — the host’s own, or sibling sub-worlds — and an unwind out of a job would kill them all with it. The world the job died in may still be inconsistent; the error says so.

The send is best-effort: a tool call that has already been cancelled has no receiver left, and the result is simply dropped.

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> Component for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more