Module mcp

Source
Expand description

MCP server so AI agents (Claude Code etc.) can co-edit live: Streamable HTTP transport (JSON-RPC 2.0 over HTTP POST /mcp on 127.0.0.1:, no external crates — a tiny HTTP/1.1 parser on std TcpListener), toggled in Settings. The server thread handles initialize, ping, tools/list, tools/call, resources/list, resources/read (project json, style summary, notes) and answers JSON (no SSE stream needed for request/response). Tool calls are forwarded to the UI thread as ToolCalls (the App executes them on the next frame against the live project, with undo, and replies through the oneshot sender); ctx.request_repaint() wakes the UI. Tool definitions (names, descriptions, JSON schemas) live in tools.rs — the App matches on the same names.

Connect from Claude Code: claude mcp add --transport http simple-editor http://127.0.0.1:7337/mcp

Modules§

tools
The MCP tool catalogue — the single source of truth for tool names/arguments. mcp/mod.rs serves it (tools/list with JSON schemas built from ARGS); ui/app.rs executes calls by name with exactly these arguments (unknown tool → error “unknown tool”). Keep both in sync with this table.

Structs§

Server
ToolCall
One tool invocation forwarded to the UI thread; reply with Ok(result json) or Err(message).

Constants§

CRC_TABLE 🔒
MAX_BODY 🔒
MAX_CONNS 🔒
READ_TIMEOUT 🔒

Functions§

adler32 🔒
call_tool 🔒
Forward one tool call to the UI thread and wait for the reply.
claude_code_command
The claude mcp add command line shown in the settings UI.
crc32 🔒
dispatch 🔒
One JSON-RPC request → response (None for notifications).
handle_connection 🔒
handle_post 🔒
Handle a POST body (single request or batch). None = nothing to send back (notifications only) → 202.
origin_ok 🔒
png_encode
Encode an RGBA frame as PNG (store-only zlib) for the render.frame tool.
rpc_err 🔒
session_id 🔒
write_chunk 🔒
write_response 🔒