Inkscape (inksmcp)

v0.3.0
io.github.bhanutpt/inksmcp Checked 2 days ago Published 1 month ago

Create, edit and export SVG graphics with Inkscape: measured layout, templates, export.

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

inkscape_info

Inkscape version and location, server version, and open documents.

document_create

Create a new blank document and make it current. The viewBox matches width/height, so coordinates are in `unit`. `background` (e.g. '#ffffff') adds a full-page rect with id 'background'.

ParameterTypeDescription
height *number
width *number
background
unitstring

document_open

Open an existing SVG (.svg or .svgz) and make it current. Returns its outline, and `notes` when the file was normalised for editing without changing how it renders: a page whose viewBox doesn't match its width/height (or uses %), fill/stroke set on the root (new elements would inherit them), ids given to elements that had none.

ParameterTypeDescription
path *string

document_save

Save the document as Inkscape SVG (to `path`, or where it was opened/last saved).

ParameterTypeDescription
doc_id
path

inspect

Outline of the document: layers, groups and elements with ids, fill/stroke as rendered (style, attributes or inherited), text, `use` targets (href) and real visual bounding boxes [x, y, width, height] in user units (measured by Inkscape). Layers/groups with more than `max_children` children are summarised (counts per type, first/last ids, bbox). To list one of them, pass `layer` (layer name or group id) and a larger max_children. find: a flat list of matching elements instead of the tree, e.g. {"fill": "#99cc32"} (colours compared in any notation), {"type": "text", "text": "total"}, {"type": "…

ParameterTypeDescription
bboxboolean
doc_id
find
layer
max_childreninteger

add_elements

Add one or more elements in a single call. Returns the new ids. Element spec keys — common: type, id, label, layer (name; created if missing), parent (group id), transform, style (css string or dict). Style shorthands: fill, stroke, stroke_width, opacity, fill_opacity, stroke_opacity, stroke_dasharray, stroke_linecap, stroke_linejoin, font_size, font_family, font_weight, font_style, text_anchor. Geometry per type: rect: x, y, width, height, rx, ry, fit_to, fit_padding, fit; circle: cx, cy, r; ellipse: cx, cy, rx, ry; line: x1, y1, x2, y2, marker_start, marker_end; polyline: points, marker_st…

ParameterTypeDescription
defaults
doc_id
elements
elements_path
previewboolean

repeat

Stamp a block of elements once per data row — timelines, card grids, tables, legends, map symbols — in one call. template: element specs as for add_elements, drawn for the FIRST row. "{key}" in any string is replaced from the row ("{year}"; a value that is exactly "{w}" keeps the row's number), in geometry and style alike ("fill": "{colour}"); "{n}" is the row number (1-based) and "{i}" the index, so rows can't use the keys n and i. Ids are local names: "card" becomes card-1, card-2, ... A "parent" may name another template element (e.g. a group holding a card and its texts); fit_to and cl…

ParameterTypeDescription
step *array
template *array
cell
columns
defaults
doc_id
id_prefixstring
layer
mirror
orderstring
previewboolean
rows
rows_path

import_file

Place a file into the current document. An SVG (e.g. geometry a script generated) becomes one group scaled to this document's units, its top-left at `at` (default 0,0); width or height scales it (both: stretch). Its layers become labelled groups, its defs join ours, clashing ids get "<id>-" in front. An image (png/jpg/gif/webp/bmp) becomes an image element: natural size at 96 dpi unless width/height (one keeps the ratio), linked by default (embed: true stores the pixels in the SVG), object_fit contain|cover|fill for a given box. Relative paths start at the document's folder. For whole document…

ParameterTypeDescription
path *string
at
doc_id
embedboolean
height
id
layer
object_fit
parent
previewboolean
width

split

Divide a region into named cells — comic panels, dashboard tiles, poster columns, table grids — without computing any positions. region: "page", an element id (its measured box) or [x, y, w, h]; margin insets it (one number, [vertical, horizontal] or [top, right, bottom, left]). rows: one entry per row, either a number of equal columns or a list of column ratios, e.g. [[2, 1], [1, 1], [1, 2]]; heights: row ratios (default equal); gutter: space between cells (number or [horizontal, vertical]). Creates one rect per cell, <id_prefix>-1, -2, ... row by row, in `layer` — invisible unless `sty…

ParameterTypeDescription
rows *array
doc_id
gutter
heights
id_prefixstring
layerstring
margin
previewboolean
region
style

update_elements

Change existing elements. Each update is {"id": ..., <any element-spec keys>}; only the given keys change. Style shorthands merge into the existing style. Set transform to "" to clear it.

ParameterTypeDescription
updates *array
doc_id
previewboolean

delete_elements

Delete elements (and their children) by id. Connectors attached to them and their labels are deleted too; all removed ids are returned. Defs only they used (symbols of an imported library, gradients, clip paths) go too: `defs_removed` counts them.

ParameterTypeDescription
ids *array
doc_id

connect

Draw arrows/lines between elements that stay attached when things move (align/layout/ update_elements/page_fit). Default: native Inkscape connectors — clipped to the real shape (circles etc.) and still live in the Inkscape GUI. With from_side/to_side/via you control the route (e.g. a loop diagram: {"from": "condenser", "to": "valve", "from_side": "left", "to_side": "top", "routing": "elbow"}); those attach at the middle of the chosen side of the bounding box, as do connectors with start_gap/end_gap. Returns the connector ids, their layers, label ids and warnings.

ParameterTypeDescription
connections *array
doc_id
previewboolean

layout

Arrange items in a row, column or grid with a gap — no coordinate maths needed. An item is an id or a list of ids that move together, e.g. ["box1", "box1_label"], or {"ids": [...], "anchor": "fig1-border"} to arrange by that member's box (plot frames line up even when their tick labels differ in width); the rest moves along. `gap` is a number or [horizontal, vertical]. `align` places items on the cross axis (grid: within cells). The block stays where the first item is, or its top-left goes to `at` [x, y], or it is aligned to `to` ('page' or an element id) using horizontal/vertical/margin. Co…

ParameterTypeDescription
items *array
alignstring
at
columns
directionstring
doc_id
gap
horizontal
marginnumber
previewboolean
to
vertical

path_operation

Geometry operations performed by Inkscape on the given ids. For difference, the top-most (later in document order) object is subtracted from the bottom one. to_path converts shapes and text into paths. union/intersection/exclusion/difference keep the BOTTOM object's id, style and layer; combine keeps the TOP object's (E22). `result` lists the ids that hold the outcome.

ParameterTypeDescription
ids *array
operation *string
doc_id
previewboolean

run_actions

Escape hatch: run raw Inkscape actions (e.g. "object-align:left last", "transform-rotate:30") after selecting `select` ids. File, export, window and quit actions are blocked. Extensions (org.inkscape.*) always act on the whole document, so they can't be combined with select.

ParameterTypeDescription
actions *array
doc_id
previewboolean
select

page_fit

Resize the page to fit the drawing (or only `ids`) plus `margin` (one number, [vertical, horizontal] or [top, right, bottom, left], user units). All content moves together so the page keeps its 0,0 top-left; full-page background rects are resized, connectors follow.

ParameterTypeDescription
doc_id
ids
margin
previewboolean

page_resize

Set the page size in user units (e.g. 210 x 297 for A4 in a mm document). anchor='center' keeps the drawing centred on the new page; 'top-left'/'none' leave content where it is. Backgrounds are resized.

ParameterTypeDescription
height *number
width *number
anchorstring
doc_id
previewboolean

grid

Draw a grid / graph paper inside rect [x, y, w, h] — linear or logarithmic per axis — without computing any line positions. Axis specs: linear: {"scale": "linear", "major": 10, "medium": 5, "minor": 1, "label_start": 0, "label_step": 1} (spacings in user units, each a whole multiple of the finest; labels on major lines) log: {"scale": "log", "cycles": 3, "subdivisions": "standard" | "fine" | "integers", "start": 10} (decades major, 2..9 medium, subdivisions minor; "start" = value at the origin (default 1); "labels": "decades" (start, start*10, ...; defa…

ParameterTypeDescription
rect *array
border
colorstring
doc_id
id_prefixstring
labels
layer_prefixstring
previewboolean
weights
x
y

plot

Plot data on a grid made with the `grid` tool, in DATA values — no coordinate maths. grid: that grid's id_prefix. Each series: {"points": [[x, y], ...], "line": true, "stroke": "#1f77b4", "stroke_width", "stroke_dasharray", "marker": "circle"|"square"|"diamond"|"none", "marker_size", "marker_fill" (default white), "point_labels": ["", "COP 3.2", ...] (one per point, null/"" to skip), "label_offset": [dx, dy], "label_anchor": "start"|"middle"|"end", "label_halo": "#ffffff"|"none", "label_font_size", "label_color", "font_family", "id", "layer"}. Labels: label_offset is from the point to the la…

ParameterTypeDescription
series *array
doc_id
gridstring
previewboolean

z_order

Change stacking order (what is drawn on top). front/back: top/bottom within the element's own layer or group. forward/backward: one step past the next object it overlaps (visible change). above/below: directly above/below `target`, moving into target's layer/group if needed while keeping the visual position. Several ids keep their relative order. Returns each id's position.

ParameterTypeDescription
ids *array
operation *string
doc_id
previewboolean
target

move_to_layer

Move elements into a layer (by name; created on top if missing) or into a group/layer by id, at its top or bottom. They keep their relative order and stay visually where they were.

ParameterTypeDescription
ids *array
layer *string
doc_id
positionstring
previewboolean

align

Align elements to the page, to each other, or inside another element — e.g. centre a label in a box: {"ids": ["label"], "to": "box", "horizontal": "center", "vertical": "middle"}. Operations run in order, each seeing the previous moves. Returns the moves [dx, dy] and new bboxes in user units.

ParameterTypeDescription
operations *array
doc_id
previewboolean

export

Export via Inkscape. Format defaults to the file extension. What is exported: `region` [x, y, w, h] (user units, everything visible); or `ids` — only those objects cropped to them (only_ids=true, default) or the area around them with everything visible (only_ids=false); otherwise area 'page' or 'drawing'. For PNG set dpi or width/height (px); background e.g. '#ffffff' (default transparent).

ParameterTypeDescription
path *string
areastring
background
doc_id
dpi
format
height
ids
only_idsboolean
region
text_to_pathboolean
width

render_preview

Render to a PNG image you can look at (white background, longest side = max_size px). Zoom in with `region` [x, y, w, h] in user units, or with `ids` (the area around them, everything still visible). only_ids=true draws just those objects.

ParameterTypeDescription
areastring
doc_id
ids
max_sizeinteger
only_idsboolean
region