pub struct McpCommand {
request: Request,
reply: Sender<Result<Output, String>>,
world: WorldId,
}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: WorldIdThe world a Request::Job runs against.
Implementations§
Source§impl McpCommand
impl McpCommand
Sourcepub fn new(
job: impl FnOnce(&mut World) -> Result<Output, String> + Send + 'static,
) -> (Self, Receiver<Result<Output, String>>)
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.
Sourcepub fn list_worlds() -> (Self, Receiver<Result<Output, String>>)
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.
fn build(request: Request) -> (Self, Receiver<Result<Output, String>>)
Sourcepub fn with_world(self, world: WorldId) -> Self
pub fn with_world(self, world: WorldId) -> Self
Direct the command at world.
Sourcepub const fn wants_worlds(&self) -> bool
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.
Sourcepub fn answer_worlds(self, worlds: Vec<WorldEntry>)
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.
Sourcepub fn fail(self, message: String)
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.
Sourcepub fn dispatch(self, world: &mut World)
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.