Skip to content
nodemode-ai edited this page Dec 6, 2026 · 7 revisions

Agents

FormChem's engine is an MCP server (backend/app/routers/mcp.py), over HTTP at http://127.0.0.1:8220/mcp and over stdio with ./formchem mcp (setup/mcp_stdio.py, which starts the engine when needed). An agent works in the same window you see. From 0.8.0 it draws there directly: it makes and opens drawings, draws structures and reaction schemes from SMILES or molfiles, edits them atom by atom by id, reads them back in machine form and checks its work with a picture drawn by the window's own renderer. From 0.9.0 it also draws from chemical names and names what is drawn, predicts 1H and 13C NMR spectra, and opens JCAMP-DX spectra, picks their peaks and integrates them. From 0.10.0 it builds structures in 3D, searches conformers, minimises, scans dihedrals and measures, opens PDB, mmCIF and 3D SD files, extracts ligands and writes 3D files. From 0.11.0 it creates and opens structure databases, imports into them, searches them, registers and updates records, exports them, and adds and finds lab notebook entries. From 0.12.0 it keeps structures in the shared structure library, hands out live structure objects for sibling Form apps, draws peptides and nucleic acids from HELM, and runs xtb and CREST when you have installed them. Every change is one undo step, every call is listed in Agent Activity, and you can stop an agent from the title bar.

The full reference, with every tool's arguments and result shape and the recorded examples, is docs/AGENTS.md.

Setup

Client How
All at once ./formchem agents install writes .mcp.json (its HTTP entry carries the agent token), .codex/config.toml and .cursor/mcp.json, adds FormChem to Antigravity's ~/.gemini/config/mcp_config.json and installs the skills
Claude Code claude mcp add --transport http formchem http://127.0.0.1:8220/mcp --header "Authorization: Bearer <token>"
Codex [mcp_servers.formchem] with url = "http://127.0.0.1:8220/mcp" and http_headers = { "Authorization" = "Bearer <token>" } in ~/.codex/config.toml
Cursor {"mcpServers": {"formchem": {"url": "http://127.0.0.1:8220/mcp", "headers": {"Authorization": "Bearer <token>"}}}} in ~/.cursor/mcp.json
Claude Desktop and any stdio client ./formchem mcp (full path to your FormChem folder): no token to set, the transport reads it

<token> is the agent token (below); the Agents dialog (Window > Agents and MCP) shows these lines with the token filled in. An agent that connected to 0.7.0 over HTTP needs the token from 0.8.0 on: run ./formchem agents install again, or add the header yourself.

./formchem agents sync regenerates the tools reference of the harness skill from the server, mirrors .claude/skills into .agents/skills and writes agents/manifest.json; sync --check fails on drift.

Tools

104 tools (27 of them new in 0.14.0). Reading never asks you; a tool that changes something asks you in the window the first time (Consent, below).

Group Tools Kind
Context get_context, list_open_documents read
Documents (0.8.0) new_document, open_document, save_document, close_document change
Drawing (0.8.0) draw_from_smiles (also reaction SMILES), draw_from_molfile, add_reaction change
Checking (0.8.0) render, get_structure, validate, compute_properties read
Editing by id (0.8.0) get_atoms (read); add_atom, add_bond, set_charge, set_atom, set_stereo, replace_substructure, delete, move, scale, align, clean_layout, add_arrow, add_text change
Converting (0.8.0) convert, batch_convert change only when they write outside the temporary folder
Names (0.9.0) draw_from_name (change); name_structure (read)
NMR prediction (0.9.0) predict_nmr (read); predict_spectrum (change)
Spectra (0.9.0) open_spectrum, spectrum_pick_peaks, spectrum_integrate (change); spectrum_data, spectrum_peaks, spectrum_export (read)
3D (0.10.0) build_3d, conformers_3d, minimise_3d, open_3d_structure, extract_ligand (change); measure_3d (read); scan_dihedral (change only with store); export_3d (change only when it writes outside the temporary folder)
Databases (0.11.0) db_create, db_open, db_add_record, db_update_record (change); db_list, db_search, db_get_record (read); db_import (change unless dry_run); db_export (change only when it writes outside the temporary folder)
Notebook (0.11.0) nb_add_entry (change); nb_search (read)
Library (0.12.0) library_add (change); library_list, live_structure_object (read)
HELM (0.12.0) draw_from_helm change
xtb and CREST (0.12.0) xtb_optimise, crest_conformers (need the programs installed) change
Window and extensions list_commands, extensions_list (read); run_command, extension_command (change)
Handoff handoff change with a state
Reactions (0.5.0) perceive_reactions, map_reaction (change); export_reaction, reaction_stoichiometry (read)
Analysis (0.6.0) properties, check_structure, stereo, substructure read
Pages and objects (0.14.0) add_page, delete_page, set_page, fit_page_to_drawing (change); list_pages, list_objects (read)
Agent undo (0.14.0) undo_agent_changes change only with step
Drawing gestures (0.14.0) fuse_ring, attach_template (need the window) change
Reaction layout (0.14.0) space_reaction, fit_arrows_to_conditions, conditions_as_footnotes change
Chemistry as tools (0.14.0) standardise, balance_reaction (change only with apply); isotope_pattern, export_helm, predict_ir_bands, predict_ms_fragments (read)
Abbreviations (0.14.0) abbreviation_define, abbreviation_remove (change); abbreviation_list (read)
3D (0.14.0) rotate_bond_3d, repair_hydrogens_3d, fetch_pdb (change); compute_surface, energy_terms_3d, render_3d (read; render_3d needs the window)
Tool What it does
get_context version, window, agent access, the open drawings, catalogue size, your last handoff
list_open_documents the open drawings (id, title, path, unsaved changes, revision, fragments, formula) and which one the window shows
new_document {title?} an empty drawing, shown in the window
open_document {path} a .fchem, a chemistry file or a picture with its drawing inside, shown in the window
save_document {doc?, path?} saves to the drawing's file, to path, or to a new name in the Drawings folder; never over another file
close_document {doc?} closes a drawing without unsaved changes
draw_from_smiles {smiles, doc?, x?, y?, name?} lays a structure out and places it in free space; reaction SMILES draws a whole scheme
draw_from_molfile {molfile, doc?, x?, y?} the same from a V2000 or V3000 molfile or SD text, keeping its coordinates
add_reaction {reaction_smiles, doc?, x?, y?, page?} a reaction scheme with its step and roles
render {doc?, scope?, ids?, format?, width?, height?, dpi?} a PNG or SVG of objects, your selection or the page, drawn by the window's renderer (by the engine when no window is open)
get_structure {doc?, object?, selection?} SMILES, CXSMILES, InChI, InChIKey, a molfile, formula, masses and elemental analysis per fragment
validate {doc?, object?} the structure check with valid
compute_properties {doc?, object?} the Analysis panel's properties with their methods
get_atoms {doc?, object?} every atom and bond with its id, position, charge, hydrogens and CIP label
add_atom, add_bond, set_charge, set_atom build and change atoms and bonds by id
set_stereo {atom or bond, label} R or S on a centre (rewrites its wedges), E or Z on a chain double bond
replace_substructure {smarts, replacement, object?, all?} swaps a SMARTS match for a SMILES group, keeping the rest in place
delete, move, scale, align, clean_layout arrange and tidy by id, without a window
add_arrow, add_text arrows (anchored to atoms and bonds for electron pushing) and text or captions
convert, batch_convert files and folders, with the same code and output as ./formchem convert and batch
draw_from_name {name, doc?, x?, y?, label?} reads a common or systematic name offline and draws it like draw_from_smiles, saying how it was read (method, confidence, engine, version); an unread name is refused with where reading stopped (Names)
name_structure {smiles? or doc?, object?, selection?} the common name and the round-trip-checked systematic name of each structure, or the reason there is none
predict_nmr {doc?, object? or smiles, nucleus?, frequency?} predicted 1H, 13C or both: signals with shift, multiplicity, J, count, confidence and uncertainty, a journal line and warnings (Spectra and NMR)
predict_spectrum {object, doc?, nucleus?, frequency?, x?, y?} adds a predicted spectrum beside the structure, linked to its atoms, as one undo step
open_spectrum {text, base64 or path, name?} opens a JCAMP-DX file as a new drawing with one spectrum per block, shown in the window
spectrum_data {doc?, object?, from?, to?, points?, y_mode?} a spectrum's points (at most 2000), axes, direction, frequency and method
spectrum_peaks {doc?, object?, detect?, from?, to?} the stored peaks, integrals and multiplets with their atom links; detect lists what the picker finds without adding it
spectrum_pick_peaks, spectrum_integrate add peaks, or add and renormalise NMR integrals, as one undo step each
spectrum_export {doc?, object?, format?, original?} the spectrum as JCAMP-DX or CSV text, or the original file
build_3d {doc?, object?, minimise?, method?} a 3D conformer from the drawing (ETKDGv3, then MMFF94, MMFF94s or UFF) as one undo step, with the energy, method and version and whether every stereo label was kept (3D)
conformers_3d {doc?, object?, n?, window?, keep?, method?} a conformer ensemble kept within an energy window, with relative energies and populations
minimise_3d {doc?, object?, conformer?, method?} minimises a conformer and reports the energy before and after and whether it converged
scan_dihedral {atoms, doc?, object?, start?, end?, step?, method?, store?} a relaxed dihedral scan: angle against relative energy, minimum and barrier; store keeps the points as conformers
measure_3d {atoms, doc?, object?, conformer?} a distance, angle or dihedral of a conformer
open_3d_structure {path, doc?, as?, x?, y?} a PDB or mmCIF file as a 3D object (cartoon, ligand in focus, the file kept as it is), or SD and MOL records as structures with their file coordinates
extract_ligand {doc?, object?, ligand?} a ligand of a PDB or mmCIF model as a structure beside it, with its SMILES and whether its bond orders were inferred
export_3d {doc?, object?, format?, conformer?, output?} MOL, SD, PDB or XYZ text with every hydrogen, or a new file
db_list, db_create {title, path?}, db_open {path} the open and known databases; make or open an .fcdb file and get its handle, record count, fields and whether it is read-only (Databases)
db_import {path, db?, format?, mode?, key?, mapping?, dry_run?, wait?} SD, RD, SMILES, CSV, TSV or .fchem records as a job: added, updated and failed, with each failed record's number and reason
db_search {db?, smiles?, mode?, threshold?, smarts?, query?, within?, name?, limit?} substructure, similarity (with scores), exact or a full query; the hit list with its first rows, which you also see in the window
db_get_record {uid, db?} one record with its molfile, keys, field values and files
db_add_record {smiles or molfile, db?, values?, on_duplicate?} registers a structure; a duplicate is refused with the matches until the agent chooses existing, batch or new
db_update_record {uid, db?, smiles?, molfile?, values?} changes a record's structure or field values
db_export {format, db?, path?, hitlist?, uids?, fields?, v3000?, structure_as?} SD, SMILES or CSV of a hit list, some records or the whole database
nb_add_entry {db, title, template?, date?, author?, procedure?, observations?, tags?, products?, reaction? or doc?} an open (unsigned) notebook entry with its scheme and the stoichiometry computed from it (Lab Notebook)
nb_search {db, query?, substructure?, limit?} notebook entries by words or by a substructure of their scheme, newest first
library_list {kind?} the shared structure library's items (Live Structures)
library_add {smiles or doc, ids?, name?, kinds?} adds a structure as a favourite, template, recent or live item, with pictures that keep the drawing inside
live_structure_object {id} the JSON a sibling Form app stores for a live structure
draw_from_helm {helm, doc?, x?, y?, name?} a peptide or nucleic acid from HELM as atoms, one undo step (Biopolymers)
xtb_optimise {object?, method?, charge?, uhf?, solvent?, single_point?, level?, limit?} an xtb optimisation or single point stored as the structure's conformer, with the energy in hartree and kcal/mol (3D)
crest_conformers {object?, method?, solvent?, ewin?, keep?, limit?} a CREST conformer ensemble with populations
list_commands, run_command the window's command catalogue, the same commands as the menus
extensions_list, extension_command Form extensions and their commands
handoff {state?, note?} working, ready or question, with a note the person sees
perceive_reactions, map_reaction, export_reaction, reaction_stoichiometry reaction steps, atom mapping, reaction SMILES and RXN, amounts and yields (Reactions)
properties, check_structure, stereo, substructure the 0.6.0 analysis tools (Analysis, Stereo and Queries)
list_pages {doc?}, add_page {after?, paper?, orientation?}, delete_page {page}, set_page {page?, width?, height?, paper?, orientation?, auto?, margins?, header?, footer?, name?, all?}, fit_page_to_drawing {page?} pages, their setup and headers and footers (Printing and pages)
list_objects {doc?, page?, kind?} every object on a page with its bounding box in points, to check a layout
undo_agent_changes {doc?, step?} lists the agent steps on the undo stack; with step, goes back to before it (your steps in between included, counted), each an ordinary undo you can redo
fuse_ring {bond, size?, benzene?}, attach_template {id, atom?, bond?, x?, y?} the ring and Template tool gestures, through the window (Templates)
space_reaction {page?, reaction?, wrap?, wrap_mode?, stretch?}, fit_arrows_to_conditions {page?, step?}, conditions_as_footnotes {page?, reaction?} Space Reaction, arrows stretched to their conditions, step letters and footnotes (Reactions)
standardise {smiles or doc, objects?, steps?, apply?}, balance_reaction {smiles or doc, reaction?, step?, coefficients?, apply?} Standardise and Balance Reaction; they preview unless apply is true
isotope_pattern {formula or smiles or doc}, export_helm {smiles or molfile or doc}, predict_ir_bands, predict_ms_fragments the isotope pattern, HELM text, IR bands and EI fragments
abbreviation_list {label?, filter?}, abbreviation_define {label, smiles, ...}, abbreviation_remove {label} the abbreviation library and your own entries
compute_surface, energy_terms_3d, rotate_bond_3d, repair_hydrogens_3d, render_3d, fetch_pdb {id} 3D surfaces and volumes, energy terms, bond rotation, hydrogen repair, a PNG of the 3D View, a PDB entry by id (3D)

Drawing directly

A typical session: get_context, then draw_from_smiles {smiles: "CC(=O)Oc1ccccc1C(=O)O", name: "aspirin"}. With no drawing open it makes one and shows it in the window. The structure is laid out with the scored 2D layout and placed in free space, right of what is on the page or below it, never on top of it and never after a reaction arrow, where it would read as a product.

Every change an agent makes is one transaction and one undo step, labelled with the tool's name in Edit > Undo (Undo Draw from SMILES, Undo Add atom). Calls never merge with each other or with your edits.

Every change answers with the structure it now holds and a picture: a text line per touched object (id, formula, SMILES, InChIKey, atom count, warnings), a PNG drawn by the window, and the same as structuredContent (doc, rev, changed, undo: "one step", objects, image). An agent checks further with render (what you see, arrows and text included), get_structure (the machine form, with a V2000 molfile, or V3000 when the structure needs it) and validate.

To build or change a structure by id: get_atoms lists the ids, add_atom {element, bond_to} adds an atom at the bond length in the freest direction (a zigzag for chains), add_bond {atom1, atom2, order} bonds two atoms or changes an existing bond, set_charge, set_atom and set_stereo change one atom or bond, and replace_substructure swaps a group. move, scale, align and clean_layout arrange; add_arrow, add_text and add_reaction build schemes. They all work without a window.

From 0.9.0: draw_from_name {name: "ethyl ethanoate"} draws a name exactly as draw_from_smiles would, and its answer starts with how the name was read ("by dictionary" or "by systematic parser", the confidence, "formchem names 0.9.0"); a name it cannot read is refused before any drawing is made. name_structure names what is drawn. predict_nmr {object, nucleus: "both"} gives predicted shifts and a journal line without changing anything, and predict_spectrum {object} puts the predicted spectrum beside the structure as one undo step. open_spectrum opens a JCAMP-DX file, and the spectrum tools read its points, pick peaks and integrate. Every name and predicted value carries its method and version, so an agent quotes them rather than presenting them as measured.

From 0.10.0: build_3d {object} builds a conformer and says whether every drawn stereocentre was kept ("all 11 stereo labels kept" for Taxol), so an agent checks that line before using the geometry; measure_3d {atoms: [C, O]} then reads ethanol's C-O as 1.42 Å with the method. conformers_3d, minimise_3d and scan_dihedral give energies with their force field and engine version; a scan stores nothing unless store is true. open_3d_structure {path} opens a PDB or mmCIF file as a 3D object and lists its chains, ligands and waters, extract_ligand turns one ligand into a structure (saying when its bond orders were inferred), and export_3d returns MOL, SD, PDB or XYZ text. An edit to a structure's atoms or bonds removes its conformers, so build again after editing. Styles, surfaces and the PNG and glTF exports of the 3D View are window commands (style-ballstick, surface-vdw, export-gltf and the rest) for run_command.

From 0.11.0: db_open {path} (or db_create {title}) gives a database handle; with one database open the other db_ tools can leave db out. db_import {path, dry_run: true} counts what would be added and failed before the real import, and a bad record never stops it. db_search {smiles: "c1ccccc1"} answers the hit list, its count, the time and the method, and the hit list appears in your window too. db_add_record refuses a duplicate and lists the matches until the agent chooses on_duplicate. nb_add_entry writes an open entry from reaction SMILES or a drawing; only you sign entries. Every write is recorded with the agent's name in the database's log and in Agent Activity.

From 0.12.0: library_add {smiles: "Oc1ccccc1", name: "Phenol"} adds a structure to the shared library (asking you the first time), library_list lists it and live_structure_object {id} returns the object a sibling app stores. draw_from_helm {helm: "PEPTIDE1{G.G}$$$$"} draws glycylglycine; bad HELM is refused with the character where reading stopped. xtb_optimise and crest_conformers wait for xtb or CREST and store the result as conformers in one undo step; when the programs are not installed they say where to get them, because FormChem never includes or downloads them.

Which drawing: doc when given; else the only open drawing; else the drawing the window shows; else the tool asks for doc. Coordinates are points, x right and y down; the default bond length is 14.4 points.

get_context lists every drawing open, oldest first, as text and in structuredContent.documents:

Documents: 1 open (draw on them with draw_from_smiles and draw_from_molfile, edit them by id with get_atoms and the edit tools, check them with render, get_structure and validate, write reactions with perceive_reactions and map_reaction, read them with export_reaction, reaction_stoichiometry, compute_properties, stereo and substructure)
- d4n2k8q0z "Untitled" (unsaved changes) · rev 1 · 1 fragment · C6H6O · not saved yet

Each entry has id, title, path, dirty, rev, fragments and formula (from the engine's derived cache, or null while the engine is still working out the latest revision).

The window's commands

Commands reach what the drawing tools do not, and every change is still one undo step you can see. One command catalogue feeds the menus, Find a Command, the keyboard map, ./formchem cli list|describe|run|batch and run_command, so anything you can click an agent can run.

Goal Call
A structure into the view's centre, selected run_command {id: "insert-smiles", params: {smiles}} (the drawing tools place in free space instead)
A template run_command {id: "insert-template", params: {id: "benzene"}}; GET /api/templates lists the ids
Import a file into the drawing run_command {id: "import", params: {path}}: in free space, selected, one undo step
Export and print export-png, export-svg, export-pdf, export-eps, export-cdxml, export-mol, export-smiles, export-picture, print (you pick where to save in the desktop app; use convert or get_structure for text the agent reads)
Clipboard copy, cut, paste, the copy-* commands, paste-special
Standardise standardise {steps: ["salts", "neutralise"]} on the selection or the page
Stereo, hydrogens, abbreviations, queries, R-groups assign-wedges, the stereo group commands, add-hydrogens, remove-hydrogens, expand-abbreviation, contract-abbreviation, set-atom-list, the set-query-bond- commands, define-rgroup, enumerate-markush
Reaction roles set-reaction-roles {role, objects}
Page and grid dark-page {on}, show-grid {on}, snap-to-grid {on}, grid-type {type}, grid-spacing {value, unit}, grid-settings {...}, each with scope: "default" for the default
Undo, save undo, redo, save

The window tells the engine within about 120 ms which commands are on after every edit, and a command that is off answers why ("X is not available right now: ..."). Form extensions with the document permission read a drawing (with its derived SMILES, InChIKey and valence errors) and apply transactions to it by id. The engine's HTTP routes for reactions, analysis, templates, formats and media are in docs/REACTIONS.md, docs/ANALYSIS.md, docs/TEMPLATES.md, docs/FORMATS.md and docs/FORMAT.md.

Consent and Stop

Agents can always read. When an outside agent first asks to change something, the window asks: Deny, Allow once (that call), or Always allow. The app's own command line counts as an outside agent; FormChem's own Claude Code, Codex, Cursor and Antigravity tabs are trusted and never asked. Only the FormChem window can change the choice, and the engine seals the saved value with a key in the system keychain, so a change made outside the window reads as asking again. convert asks only when it writes outside the temporary folder and batch_convert unless its output folder is there; neither writes over an existing file. save_document never writes over another file and close_document never closes a drawing with unsaved changes: those choices stay yours, in the window.

While an agent changes the drawing you are looking at, the title bar shows "[agent] is editing" and Stop. Stop refuses every further call of that agent, reads included, and withdraws Always allow, so every outside agent asks again on its next change. A call already running finishes. Allow again in Agent Activity lets the agent back in.

The agent token

From 0.8.0 the HTTP endpoint (POST /mcp, also DELETE /mcp) answers only a request that carries one of: Authorization: Bearer <agent token>, the token of one of FormChem's own agent tabs (x-formchem-inapp), or the window key. Anything else gets 401 with WWW-Authenticate: Bearer realm="FormChem" and a JSON-RPC error (code -32001) saying where the token is. The engine still listens on loopback only, and the origin check is unchanged.

The token is one line in agent-token in the data folder (~/formchem, or FORMCHEM_DATA_DIR), created by the engine at start or by ./formchem agents install, whichever runs first, readable by the owner only. ./formchem agents token prints it. To change it, delete the file and restart the engine, then run ./formchem agents install again. The stdio transport (./formchem mcp) and ./formchem cli read the file themselves, so stdio clients need no change. The .mcp.json files that install writes hold the token: keep them out of version control (FormChem's own .gitignore does). The chat panel's copied prompt tells an outside agent how to send it, without putting the token itself on the clipboard.

$ curl -s -o /dev/null -w '%{http_code}\n' -X POST http://127.0.0.1:8220/mcp -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"ping"}'
401
$ curl -s -X POST http://127.0.0.1:8220/mcp -H "Authorization: Bearer $(./formchem agents token)" -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"ping"}'
{"jsonrpc": "2.0", "id": 1, "result": {}}

Agent activity

Every tool call, from any transport or from the window's own chat, is logged by the engine and listed in Window > Agent Activity, with undo for the call that is still the latest step of its drawing. Agent Activity describes the panel, the editing chip, the call log files and the /api/agents routes.

Skills

formchem-harness (using FormChem: drawing with the tools, checking with render and get_structure, names, NMR prediction and spectra, 3D and xtb, databases and the notebook, the structure library and HELM, commands, reactions, analysis, handoff) and formchem-skillset (developing FormChem), in .claude/skills and mirrored to .agents/skills. The harness's references/tools.md is generated from the server and lists every argument of all 104 tools.

Clone this wiki locally