mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-26 10:47:11 -06:00
The server read stdio lines and remote replies without any byte bound, answered batches of any size, and command_batch kept every step result: one faulty peer or batch could allocate and work without bound. Request lines are now read in bounded chunks (16 MiB; longer lines get a -32600 reply, are skipped, and framing continues), protocol batches hold at most 64 messages, control-channel replies past 256 MiB drop the connection with the usual uncertainty error, command_batch takes at most 256 steps and keeps at most 8 MiB of step results (past that the batch stops with the reason, still closing its atomic undo group). Eight new tests cover the line/batch/step/result caps and the atomic-group close; docs/mcp.md and the command_batch tool text document them. cargo test -p vectorcraft-mcp passes.
65 lines
1.8 KiB
Rust
65 lines
1.8 KiB
Rust
//! VectorCraft's MCP server.
|
|
//!
|
|
//! [Model Context Protocol](https://modelcontextprotocol.io) over stdio: newline-delimited
|
|
//! JSON-RPC 2.0, hand-written (no async runtime). The server exposes VectorCraft as a set of MCP
|
|
//! tools and resources and forwards everything to a [`Backend`]:
|
|
//!
|
|
//! - [`Remote`] talks to a running desktop app through its loopback JSON-lines control channel
|
|
//! (`vectorcraft --control 7979`): one `{"id","method","params"}` line in, one
|
|
//! `{"id","ok","result"|"error"}` line out.
|
|
//! - [`Headless`] hosts an in-process [`vectorcraft_engine::Session`] and implements the same
|
|
//! control-channel method names itself (rendering screenshots with `vectorcraft-render`), so agents
|
|
//! can draw and look at the result without a window.
|
|
//!
|
|
//! Entry points: [`Server::serve`] (stdio loop) and [`Server::handle_line`] (one message).
|
|
#![forbid(unsafe_code)]
|
|
|
|
mod backend;
|
|
mod headless;
|
|
pub mod logging;
|
|
mod prompts;
|
|
mod resources;
|
|
mod server;
|
|
mod tools;
|
|
|
|
pub use backend::{Backend, Remote};
|
|
pub use headless::Headless;
|
|
pub use prompts::{PROMPTS, PromptArg, PromptDef};
|
|
pub use resources::{DOC_JSON_URI, DOC_URI, TEMPLATES};
|
|
pub use server::{PROTOCOL_VERSION, Server};
|
|
pub use tools::{ToolResult, call_tool, tool_definitions};
|
|
|
|
/// Default control-channel address of the desktop app.
|
|
pub const DEFAULT_ADDR: &str = "127.0.0.1:7979";
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|
|
#[cfg(test)]
|
|
mod tests_conventions;
|
|
#[cfg(test)]
|
|
mod tests_distortkeys;
|
|
#[cfg(test)]
|
|
mod tests_exportas;
|
|
#[cfg(test)]
|
|
mod tests_fileio;
|
|
#[cfg(test)]
|
|
mod tests_freeform;
|
|
#[cfg(test)]
|
|
mod tests_gradient;
|
|
#[cfg(test)]
|
|
mod tests_limits;
|
|
#[cfg(test)]
|
|
mod tests_links;
|
|
#[cfg(test)]
|
|
mod tests_liquify;
|
|
#[cfg(test)]
|
|
mod tests_pen;
|
|
#[cfg(test)]
|
|
mod tests_persp;
|
|
#[cfg(test)]
|
|
mod tests_place;
|
|
#[cfg(test)]
|
|
mod tests_protocol;
|
|
#[cfg(test)]
|
|
mod tests_svg;
|