On this page
MCP command registry for PixelWeaver.
#server.src.pixelweaver.mcp_registry
#server.src.pixelweaver.mcp_registry
MCP command registry for PixelWeaver.
Maps MCP tool names to internal state mutations and read operations. Each tool handler receives validated arguments and returns a result dict.
Tools are split into three categories: - Raw command tools: one per drawing/layer/frame/project/canvas/history/export command - Curated high-level tools: combine multiple raw tools behind a friendlier API - Read/introspection tools: return data without mutating state
#ToolDef
Lightweight descriptor for an MCP tool.
#MCPCommandRegistry
Registry that maps MCP tool names to command dispatch.
#execute_tool
async def execute_tool(self, tool_name: str, arguments: dict[str, Any]) -> dict[str, Any]Execute an MCP tool and return the result.
#get_tool_definitions
def get_tool_definitions(self) -> list[dict[str, Any]]Return MCP-compatible tool definitions for all registered tools.
#get_tool_def
def get_tool_def(self, name: str) -> ToolDef | NoneGet a single tool definition by name.
#_register
def _register(self, tool_def: ToolDef, handler: Any) -> NoneRegister a tool definition and its async handler.
#_register_all
def _register_all(self) -> NoneRegister every tool via domain modules.
#_get_active_canvas_thumbnail
def _get_active_canvas_thumbnail(self) -> str | NoneGet a thumbnail of the first canvas in the active project.
#_make_command
def _make_command(self, cmd_type: str, params: dict[str, Any], *, plugin: str='mcp') -> dict[str, Any]Build a command dict matching the protocol format.
#_dispatch_command
async def _dispatch_command(self, cmd_type: str, params: dict[str, Any], *, plugin: str='mcp', undo_record: dict[str, Any] | None=None) -> dict[str, Any]Create a command, store in history, and broadcast to WebSocket clients.
undo_record is the before/after revert snapshot produced by a bespoke structural/metadata/dimension/character handler (via structural_ops / metadata_ops / character_ops / the undo_history record constructors). When supplied it rides the history entry under UNDO_KEY so MCP undo/redo can revert the change -- mirroring how the WebSocket path attaches the record apply_*_command returns. Drawing/role commands pass None and have their pixel/role record computed here instead.
#_apply_with_undo
def _apply_with_undo(canvas: Any, cmd: dict[str, Any], cmd_type: str) -> dict[str, Any] | NoneApply a drawing/role command and return its before/after undo record.
#_broadcast_full_state
async def _broadcast_full_state(self) -> NoneBroadcast a full-state patch for the active project to all clients.
Hoisted from mcp_frame_tools so manifest/part-set/role tools reuse the one implementation. No-op when no project is active.
#_validate_shade_args
def _validate_shade_args(self, name: str, args: dict[str, Any], canvas: Any, project: Any) -> dict[str, Any] | NoneValidate shade params (role/role0/role1) for a role tool.
Every shade must be an integer in [0, 254]; the sentinel is never a legal paint value. When the target layer and manifest class resolve, shades must additionally be < the class ramp length. Returns a structured failure dict, or None when all shades are legal.
#_require_active_project
def _require_active_project(self) -> dict[str, Any] | NoneReturn an error dict if no project is active, else None.
#_register_drawing_tool
def _register_drawing_tool(self, name: str, description: str, schema: dict[str, Any], *, layer_kind: str='rgba') -> NoneRegister a single drawing tool that dispatches a command.
Automatically injects an optional frame_index parameter so MCP clients can target a specific animation frame. When provided, the server sets canvas.current_frame_index before dispatching the command (so the frontend draws on the correct frame) and includes frame_index in the dispatched params for future frontend-side routing.
layer_kind is the layer kind this tool operates on (default "rgba"). The capability guard blocks the tool when a named layer_id targets a layer whose kind differs (mirrors the frontend dispatcher's CommandDefinition.supports).