Skip to main content

Module server

Module server 

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

The MCP service: the tool router, the shared argument types and the transport.

Each tool turns its JSON arguments into a McpCommand and sends it to the thread that owns the world. The tool then awaits the result: structured JSON for most tools, an image or audio content block for the ones that read pixels or samples back inline, and a written path for the ones that save to a file. A tool that fails returns a tool-level error result rather than a protocol error, so a model sees the message instead of a transport failure.

The router starts empty and the engine crates fill it in: a crate submits a ToolSource whose extend registers the tools that crate defines. The server therefore carries tools this crate knows nothing about, and a tool whose types live elsewhere still runs against the world through the same command channel.

Re-exportsΒ§

use std::error::Error; πŸ”’
use std::future::Future; πŸ”’
use std::sync::Arc; πŸ”’
use rmcp::handler::server::tool::schema_for_input; πŸ”’
use rmcp::handler::server::wrapper::Parameters; πŸ”’
use rmcp::model::CallToolResponse; πŸ”’
use rmcp::model::CallToolResult; πŸ”’
use rmcp::model::ContentBlock; πŸ”’
use rmcp::model::ServerCapabilities; πŸ”’
use rmcp::model::ServerConfig; πŸ”’
use rmcp::model::Tool; πŸ”’
use rmcp::ErrorData; πŸ”’
use rmcp::ServerHandler; πŸ”’
use rmcp::tool_handler; πŸ”’
use schemars::JsonSchema; πŸ”’
use schemars::JsonSchema; πŸ”’
use serde::Deserialize; πŸ”’
use serde::Deserialize; πŸ”’
use serde::de::DeserializeOwned; πŸ”’
use serde_json::Value; πŸ”’
use crate::mcp::host::McpCommand; πŸ”’
use crate::mcp::host::Output; πŸ”’
use crate::mcp::host::WorldId; πŸ”’
use crate::Entity; πŸ”’
use crate::World; πŸ”’

StructsΒ§

ContextArg
Which world and render context a GPU tool runs against.
CreateMesh
Arguments for creating a mesh.
EntityArg
Arguments for one entity in a world.
GetComponent
Arguments for reading one component.
HandleArg
Which world and resource a handle tool runs against.
InputArg
Arguments for reading or sending input.
ListEntities
Arguments for listing entities.
LoadGltf
Arguments for load_gltf.
McpServer
The MCP server driving one or more worlds.
MeshTransform
A transform as JSON.
NoArgs
No arguments.
ReadBuffer
Arguments for reading a buffer.
RendererArg
Arguments for rendering a frame.
SaveBuffer
Arguments for saving a buffer to a file.
SaveScreenshot
Arguments for saving a screenshot as an image.
SaveTexture
Arguments for saving a texture as an image.
Screenshot
Arguments for taking a screenshot.
SendInput
Arguments for sending input events.
SetComponent
Arguments for writing one component.
SpawnEntity
Arguments for spawning an entity.
ToolRoute
ToolRouter
ToolSource
A crate’s contribution to the server’s tool set.
WorldArg
Which world a tool runs against.

FunctionsΒ§

command
Send a job to the world world names and await its JSON result.
default_limit πŸ”’
entity
An entity handle from the u64 bits a JSON argument carries.
identity4 πŸ”’
one3 πŸ”’
run
Send a job to the world world names and await its output.
send
Send a job to the world world names and await what it answered.
serve_stdio_with
Serve MCP over stdio, handing every command to sink.
serve_with
Serve MCP over any transport, handing every command to sink.
tool
A tool route from a name, a description and an asynchronous handler.
zero3 πŸ”’

Type AliasesΒ§

CommandSender
The channel a tool sends its commands over.
ToolResult
What a tool handler answers with.