fontpr
fontpr
Overview
FontLab MCP tools for embedded Python.
fontpr exposes the tools of FontLab's MCP server as ordinary functions inside
FontLab's own Python. A script can call the same focused, validated operations
that an external MCP client uses, without a network connection or a token.
Calling convention:
- Every tool function takes keyword arguments only. Positional arguments are
ignored, so
fontpr.list_glyphs(font_id=1)works andfontpr.list_glyphs(1)does not passfont_id. fontpr.call(name, **kwargs)calls a tool by its MCP name;namemust be a string (otherwiseTypeError), for examplefontpr.call("list_glyphs", font_id=1).fontpr.available()returns True once the MCP tools are ready. Before then every call raisesfontpr.Error("MCP tools are not available yet.").fontpr.list_tools()returns a list of tool metadata dicts (name,description,inputSchemaand the other MCP fields) for the running build. Blocked tools are left out, and the list is empty when tools are unavailable. Treat it as authoritative: the functions documented here come from one build and one specification.run_pythonandget_python_outputare blocked: calling them throughfontprraisesfontpr.Error, because a script is already running Python.
Results:
- A tool error (
isError) raisesfontpr.Errorwith the tool's message. - Otherwise the first text result is parsed as JSON and returned as a
dictorlist; text that is not JSON is returned asstr. - Inspect payload fields such as
success,status,changed,appliedandpersisted. A returned value does not by itself mean that the font changed.
Targeting:
font: Use font_id from list_fonts.fonts[].id or new_font.font.id. IDs are in-memory session IDs, not persistent file identifiers. font_id takes precedence; invalid ID errors rather than falling back.font_name: First case-insensitive substring match against full, family or PostScript name. Ambiguous matches are not rejected; use IDs for writes.default_font: Active package when selectors are omitted. Selection is shared with the GUI and every client.glyph: Use exact glyph_name, not a character/code point; @ is glyph at. Some internal handlers fall back to current glyph, but advertised required glyph_name should always be supplied.actions: Prefer explicit nonempty glyph_names for glyph actions. Omitted glyph_names uses current GUI selection only if every glyph belongs to the requested font; empty or malformed arrays fail rather than falling back.layers: layer_name (get_glyph construction/build_glyph/anchors) is an exact layer name. layer_mode (run_actions) is active/visible/masters. master_name (font info/kerning) is a separate selector; never substitute these for one another.units: Geometry, widths, sidebearings, anchors and kerning are font units, not pixels. Angles are degrees. Use get_font_metrics for UPM and master names.examples: Numeric ID 101 and names H, A, V, Regular are illustrative. Replace with discovered IDs and names before executing examples.
Working rules:
- Discover tools and open fonts first; collect an explicit target ID and relevant glyph/layer/master names.
- Use explain for UI, preference and action meaning; list_actions for actual action IDs.
- Prefer focused getters/setters and construction tools. Use run_actions for whole glyphs; run_python/fontpr for explicitly requested Python or edits not expressible by focused tools.
- Use basic glyph summaries first. Page results and filter exactly; do not request full VFJ merely to count contours.
- Read before replacing; get_glyph full VFJ must be preserved except intended edits when passed to set_glyph.
- Use build_glyph dry_run when a staged preview is needed to assess the result. Only set replace:true after inspecting the target.
- Re-read affected state after every mutation. Do not reuse cached read evidence after writes.
- Use explicit output paths and default overwrite:false for batch copies. Verify the destination, then close only fonts owned by the batch.
- No global transaction or universal MCP undo tool exists. Keep backups for destructive workflows. Preserve failed fonts for inspection.
- Never invent tool names such as save_font_as, new_glyph, export_font, select_master, undo or redo. They are not currently advertised.
- Distinguish MCP behavior from built-in Chat policy: Chat enables Python with /python on or an explicit request such as allow Python; authorization lasts until /python off or clearing the chat. It keeps native tools available and adds confirmation/budgeting; external MCP does not add those prompts.
Known limitations:
- non-atomic: run_actions and arbitrary Python can change state before an error. The contour-loss check in run_actions detects loss after execution and does not undo it. Inputs for a kerning-class membership patch are validated before changing side flags, but there is no general transaction guarantee.
- save-copy: Explicit saves preserve source location and dirty state. After saving a new font to a copy path, save_font without path and close_font(save=true) still have no original save location. After verifying the copy, close_font(save=false). Existing VFJP directories cannot be overwritten.
- blocking: Python tracing (5 seconds by default, configurable with set_mcp_settings) is cooperative and cannot interrupt a blocked C++/extension call. A bridge timeout does not prove an operation stopped.
Source: FontLab MCP specification
Functions
| Function | Signature | Summary |
|---|---|---|
available |
(*args: Any, **kwargs: Any) -> Any |
Return True when MCP tools are ready. |
build_glyph |
(*, glyph_name: str, recipe: str, font_id: int | None=None, font_name: str | None=None, direction: str | None… |
Build a glyph from a bounded explicit recipe using FontLab's construction engine. |
call |
(name: str, /, **kwargs: Any) -> Any |
Invoke an MCP tool. |
close_font |
(*, font_id: int | None=None, font_name: str | None=None, save: bool | None=None) -> Any |
Close the active or requested font without prompting, discarding unsaved changes by default. |
compile_features |
(*, revision: str, font_id: int | None=None, font_name: str | None=None, dry_run: bool | None=None) -> Any |
Compile current Features text with Classes panel data, then publish GSUB/GPOS/GDEF as one undoable change. |
delete_all_kerning_classes |
(*, font_id: int | None=None, font_name: str | None=None, master_name: str | None=None, all_masters: bool | N… |
Delete all kerning classes from one or more font masters. |
delete_all_kerning_pairs |
(*, font_id: int | None=None, font_name: str | None=None, master_name: str | None=None, all_masters: bool | N… |
Delete all kerning pairs from one or more font masters. |
delete_kerning_class |
(*, class_name: str, font_id: int | None=None, font_name: str | None=None, master_name: str | None=None, undo… |
Delete a kerning class from a font master by class name. |
delete_kerning_pair |
(*, left: str, right: str, font_id: int | None=None, font_name: str | None=None, master_name: str | None=None… |
Delete a kerning pair from a font master. |
edit_glyph_components |
(*, glyph_name: str, layer_name: str, operations: list[dict[str, Any]], font_id: int | None=None, font_name: … |
Atomically add, set_transform or remove live component elements on one existing non-Auto unlocked layer, with Undo. |
edit_glyph_nodes |
(*, glyph_name: str, operations: list[dict[str, Any]], font_id: int | None=None, font_name: str | None=None, … |
Apply 1..256 sequential native node/curve edits to one existing non-Auto layer, atomically with Undo. |
edit_layer_hints |
(*, glyph_name: str, operations: list[dict[str, Any]], font_id: int | None=None, font_name: str | None=None, … |
Atomically add, set, move or delete stored PostScript hints in one existing non-Auto glyph layer with Undo. |
explain |
(*, query: str | None=None, id: str | None=None, section: str | None=None, limit: int | None=None, max_chars:… |
Search FontLab Quick Help content loaded in the current workspace. |
geometry |
(*, op: str, a: dict[str, Any] | None=None, b: dict[str, Any] | None=None, points: list[dict[str, Any]] | Non… |
Pure geometry calculations, no font mutation. vector returns b-a, distance, unit vector, perpendicular and angle in degrees. curve evaluates/splits a line, quadratic or cubic Bezier at t and returns… |
get_active_font |
() -> Any |
Return the active font. |
get_active_glyphs |
() -> Any |
Deprecated alias for get_current_glyphs. |
get_current_glyphs |
() -> Any |
Return current glyphs using flWorkspace::instance().getSelectedGlyphs(glyphs): the active glyph when a glyph window is active, or selected glyphs when a font window is active. |
get_features |
(*, font_id: int | None=None, font_name: str | None=None, output_path: str | None=None, format: str | None=No… |
Read Features panel source as data:{text:string}, with a revision covering source, shared classes and glyph order. |
get_font_hinting |
(*, font_id: int | None=None, font_name: str | None=None, master_name: str | None=None, kind: str | None=None… |
Read font-level alignment zones and standard stems directly, without glyphs, kerning, features or Python. |
get_font_info |
(*, font_id: int | None=None, font_name: str | None=None, detail: str | None=None, master_name: str | None=No… |
Return package-level font info JSON without glyph outlines. |
get_font_metrics |
(*, font_id: int | None=None, font_name: str | None=None) -> Any |
Return font-level metrics for the active or requested font: UPM, ascender, descender, x-height, cap height, line gap, italic angle, weight, and width. |
get_glyph |
(*, glyph_name: str, detail: str | None=None, layer_name: str | None=None, mark_glyph: str | None=None, compo… |
Read one glyph. detail=construction returns compact layer names, anchors, component identities/transforms and width. |
get_glyph_metrics |
(*, glyph_name: str, font_id: int | None=None, font_name: str | None=None) -> Any |
Return glyph metrics: advance width, LSB, RSB, and metrics expressions for the active or requested glyph. |
get_glyph_nodes |
(*, glyph_name: str, font_id: int | None=None, font_name: str | None=None, layer_name: str | None=None, shape… |
Inspect indexed nodes in one glyph layer without full VFJ. |
get_kerning_pair |
(*, left: str, right: str, font_id: int | None=None, font_name: str | None=None, master_name: str | None=None… |
Return the kerning value for a left/right pair on a font master. |
get_layer_hints |
(*, glyph_name: str, font_id: int | None=None, font_name: str | None=None, layer_name: str | None=None, offse… |
Read stored PostScript stem/ghost hints on one glyph layer without outlines or whole-glyph JSON. |
get_lookups |
(*, font_id: int | None=None, font_name: str | None=None, output_path: str | None=None, overwrite: bool | Non… |
Read the editable Lookups panel document as versioned JSON, including glyph classifications, classes, scripts/features, lookup rules, flags and anchors. |
get_mcp_settings |
() -> Any |
Read global MCP Python execution settings, allowed ranges, defaults, and read-only transport settings. |
get_opentype_tables |
(*, font_id: int | None=None, font_name: str | None=None, tags: list[Any] | None=None, include_data: bool | N… |
Inspect stored OpenType table bytes: tags, byte counts and SHA-256 hashes. |
get_preferences |
(*, query: str | None=None, keys: list[str] | None=None, offset: int | None=None, limit: int | None=None) -> … |
Read FontLab application preferences without an open font. |
get_vfj_schema |
(*, topic: str | None=None, include_examples: bool | None=None, include_dependencies: bool | None=None) -> Any |
Reference for VFJ inspection or authoring; tools with self-contained argument schemas do not require this lookup. |
list_actions |
(*, query: str | None=None) -> Any |
Discover unresolved FontLab action ids for run_actions. |
list_aidus_files |
(*, root: str | None=None, path: str | None=None, offset: int | None=None, limit: int | None=None) -> Any |
Discover or list the two allowed file folders under FontLab's user data folder: aidus=Aidus, scripts=Scripts/Aidus. |
list_fonts |
() -> Any |
List open fonts. |
list_glyphs |
(*, font_id: int | None=None, font_name: str | None=None, detail: str | None=None, query: str | None=None, li… |
List glyphs. |
list_kerning_classes |
(*, font_id: int | None=None, font_name: str | None=None, master_name: str | None=None) -> Any |
List kerning classes for a font master, including member glyph names. |
list_kerning_pairs |
(*, font_id: int | None=None, font_name: str | None=None, master_name: str | None=None, left: str | None=None… |
List kerning pairs for a font master. |
list_tools |
() -> Any |
Return MCP tool metadata. |
new_font |
(*, family_name: str | None=None, style_name: str | None=None, encoding: str | None=None) -> Any |
Create a new FontLab font containing .notdef only. |
open_font |
(*, path: str) -> Any |
Open a font file in FontLab 9. |
read_aidus_file |
(*, root: str, path: str, offset: int | None=None, limit: int | None=None) -> Any |
Read a UTF-8 text file only inside Aidus or Scripts/Aidus under FontLab's user data folder. |
rename_kerning_class |
(*, class_name: str, new_name: str, font_id: int | None=None, font_name: str | None=None, master_name: str | … |
Rename a kerning class on a font master. |
run_actions |
(*, actions: list[Any], glyph_names: list[Any] | None=None, layer_mode: str | None=None, undo: bool | None=No… |
Run FontLab actions on explicit glyph names or the current glyph selection. |
save_font |
(*, font_id: int | None=None, font_name: str | None=None, path: str | None=None, format: str | None=None, ove… |
Save a font synchronously without dialogs. |
set_active_font |
(*, font_id: int | None=None, font_name: str | None=None) -> Any |
Activate an open font by id or name. |
set_active_glyph |
(*, glyph_name: str, font_id: int | None=None, font_name: str | None=None) -> Any |
Set the active package and internal current-glyph reference. |
set_features |
(*, version: int, revision: str, font_id: int | None=None, font_name: str | None=None, data: dict[str, Any] |… |
Replace Features text from data:{text:string} or a local JSON/.fea file. |
set_font_info |
(*, font_id: int | None=None, font_name: str | None=None, font_info: dict[str, Any] | None=None, master_name:… |
Patch FontInfo metadata on the active or requested font using FontInfo/Python-style field names. |
set_font_metrics |
(*, font_id: int | None=None, font_name: str | None=None, ascender: float | None=None, descender: float | Non… |
Set one or more font-level metrics on the active or requested font. |
set_glyph |
(*, glyph_name: str, glyph_data: dict[str, Any], create: bool | None=None, dry_run: bool | None=None, font_id… |
Whole-glyph replacement or creation. |
set_glyph_anchors |
(*, glyph_name: str, anchors: list[dict[str, Any]], font_id: int | None=None, font_name: str | None=None, lay… |
Patch named anchors on one existing non-Auto layer. |
set_glyph_metrics |
(*, glyph_name: str, lsb: float | None=None, rsb: float | None=None, advance_width: float | None=None, metric… |
Set glyph metrics on the active or requested glyph. |
set_kerning_class |
(*, class_name: str, glyph_names: list[Any] | None=None, add_glyph_names: list[Any] | None=None, remove_glyph… |
Create or update a kerning class on a font master. |
set_kerning_pair |
(*, left: str, right: str, value: float, font_id: int | None=None, font_name: str | None=None, master_name: s… |
Set the kerning value for a left/right pair on a font master. |
set_lookups |
(*, version: int, revision: str, font_id: int | None=None, font_name: str | None=None, data_path: str | None=… |
Replace the editable Lookups document with JSON from get_lookups. |
set_mcp_settings |
(*, patch: dict[str, Any]) -> Any |
Validate and persist a partial patch of global MCP settings. |
set_notepad_content |
(*, text: str | None=None, document: dict[str, Any] | None=None) -> Any |
Replace the active font's Notepad content directly, without Python. |
set_preferences |
(*, patch: dict[str, Any]) -> Any |
Patch FontLab application preferences using exact keys and value types from get_preferences. |
write_aidus_file |
(*, root: str, path: str, content: str, overwrite: bool | None=None) -> Any |
Create or replace a UTF-8 text file only in Aidus or Scripts/Aidus under FontLab's user data folder. |
Classes
| Class | Summary |
|---|---|
Error |
Common base class for all non-exit exceptions. |