Skip to main content

Module host

Module host 

Source
Available on crate feature mcp and non-WebAssembly only.
Expand description

The world side of the MCP server.

A World is not Send, and the work that reads it must happen on the thread that owns it. The MCP transport, on the other hand, runs on a tokio thread. The two meet at a command channel: a tool builds an McpCommand holding a closure and the WorldId of the world it should run against, the thread that owns that world resolves the id and calls McpCommand::dispatch, and the Output travels back on the command’s reply channel.

Nothing here assumes how many worlds there are or what a world contains. A crate that defines tools of its own submits a ToolSource and keeps its tool bodies next to the types they read; this module carries only the contract every tool shares.

Re-exportsΒ§

use std::panic::AssertUnwindSafe; πŸ”’
use std::path::Path; πŸ”’
use schemars::JsonSchema; πŸ”’
use schemars::JsonSchema; πŸ”’
use serde::Deserialize; πŸ”’
use serde::Deserialize; πŸ”’
use serde_json::Value; πŸ”’
use crate::Entity; πŸ”’
use crate::World; πŸ”’
pub use crate::naming::extension_of;
pub use crate::naming::with_extension;

StructsΒ§

Despawned
What a despawn removed.
EncodedAudio
A sound the transport sends as an audio content block.
EncodedImage
An image the transport sends as an image content block.
McpCommand
A request together with the channel its result is sent back on.
SavedFile
A file a save tool wrote.
SpawnedEntity
A spawned entity, as the tools report it.
WorldEntry
One world a host reports, with the name it was spawned under.

EnumsΒ§

Output
What a finished job produced.
Request πŸ”’
What a command asks the host to do.
WorldId
Which world a tool or a command runs against.

FunctionsΒ§

catch_job πŸ”’
Run one tool job, catching a panic into an error reply.
generated_name πŸ”’
The name a save writes when its caller named none: stem with a fresh random id, so a save never overwrites the file an earlier one wrote.
panic_message πŸ”’
The message a panic payload carries, with a fallback for foreign payloads.
saved_name
The name a save writes: the caller’s own, given extension when it carries none, or a fresh stem name when the caller named none.
to_value
Serialise a value through the reflection it derives.
write_file
Write bytes to directory/file_name, creating the directory.

Type AliasesΒ§

Job
A unit of work for the thread that owns a world.