Skip to main content

serve_stdio_with

Function serve_stdio_with 

Source
pub fn serve_stdio_with(
    sink: impl Fn(McpCommand) -> bool + Send + 'static,
) -> Result<(), Box<dyn Error + Send + Sync>>
Available on crate feature mcp and non-WebAssembly only.
Expand description

Serve MCP over stdio, handing every command to sink.

sink is how a command reaches the thread that owns the world its WorldId names: a host sends it to its own render thread, or a windowed host posts it to its event loop, where it resolves the id to a world and calls McpCommand::dispatch. Returning false means the command could not be delivered - the event loop is gone, say - and the waiting tool call is answered with an internal error rather than left hanging.

The host answers the list_worlds tool itself: when a command’s wants_worlds is true, it names every world it carries - with the name each was spawned under - through answer_worlds instead of dispatching a job. This crate keeps no list of its own, because the worlds on other threads are not types it can recognise.

§Errors

Fails when the tokio runtime cannot be built or the transport cannot start.