feat: add canvas export to PNG via File menu, Cmd+Shift+E, and MCP tool
This commit is contained in:
@@ -203,6 +203,18 @@ pub struct RenderMermaidParam {
|
||||
pub height: Option<f32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, schemars::JsonSchema)]
|
||||
pub struct ExportCanvasParam {
|
||||
#[schemars(description = "Session ID to target. If omitted, uses the active session.")]
|
||||
pub session_id: Option<String>,
|
||||
#[schemars(description = "File path to save the PNG export to")]
|
||||
pub path: String,
|
||||
#[schemars(description = "Scale factor for the export (default 2.0 for high DPI)")]
|
||||
pub scale: Option<f32>,
|
||||
#[schemars(description = "Background color as hex e.g. '#1a1a2e' (default dark canvas color)")]
|
||||
pub background: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, schemars::JsonSchema)]
|
||||
pub struct BatchParam {
|
||||
#[schemars(
|
||||
@@ -565,6 +577,29 @@ impl AgCanvasServer {
|
||||
self.call_agcanvas(&request).await
|
||||
}
|
||||
|
||||
#[tool(
|
||||
description = "Export the canvas as a PNG image. Renders all layers (SVG, drawing elements) into a single image file."
|
||||
)]
|
||||
async fn export_canvas(
|
||||
&self,
|
||||
Parameters(params): Parameters<ExportCanvasParam>,
|
||||
) -> Result<CallToolResult, McpError> {
|
||||
let mut request = serde_json::json!({
|
||||
"type": "ExportCanvas",
|
||||
"path": params.path,
|
||||
});
|
||||
if let Some(sid) = params.session_id {
|
||||
request["session_id"] = serde_json::Value::String(sid);
|
||||
}
|
||||
if let Some(s) = params.scale {
|
||||
request["scale"] = serde_json::json!(s);
|
||||
}
|
||||
if let Some(bg) = params.background {
|
||||
request["background"] = serde_json::Value::String(bg);
|
||||
}
|
||||
self.call_agcanvas(&request).await
|
||||
}
|
||||
|
||||
#[tool(
|
||||
description = "Send multiple Augmented Canvas operations in one request. Accepts a JSON array of request objects and returns one response per operation in a BatchResult."
|
||||
)]
|
||||
|
||||
Reference in New Issue
Block a user