Skip to content

The MCP server (for external agents)

xdfem2D can be driven by an AI agent such as Claude Code or Claude Desktop, through the Model Context Protocol (MCP). The agent builds a model with the same command language the Assistant writes, analyses it, designs it, reads the results and writes files, calling tools instead of clicking menus.

It is not the Assistant. The Assistant is a panel inside the application, meant for the small models that run on your computer. The MCP server is for an agent that you already use (a capable cloud model works best), which then has xdfem2D as one more tool.

The server is part of the application: the same program that opens the window starts it when it is given --mcp. Nothing else has to be installed.

What it is, and what it is not

  • One model in memory, separate from the window. The server keeps its own model, its results and an undo list. It does not see the model open in the application, and the application does not see the agent's. The two meet through .x2d files: the agent saves, you open; you save, the agent loads. If both edit the same file, whoever saves last wins.
  • Edits drop the results. Results belong to the model they were computed from. After any edit the agent runs the analysis again before asking for forces.
  • Nothing is lost silently. new_model and load_model refuse to throw away edits that were not saved (force=true discards them), and undo brings back the last edit.
  • It writes files where the agent says, unless you give it a folder (--root, below). save_model, export_file and export_figure take any path, and the agent chooses it.

Work on the model that is open in the window

--mcp gives the agent a model of its own. The other way is to let it work on the model you have open, from the Agent tab of the application: you see what it does as it does it, you can edit in between, and it sees what you did. That tab, its agents (Claude Code, Ollama's cloud models), its options and what to know about it are in The Agent tab. It uses the same tools as this page, plus ui_action, which only works in the window.

Register it with your agent

First, open xdfem2D once and accept the notice. The server will not start before that, and it cannot show the notice itself. It also checks, as the window does, that the version has not expired; if it refuses, it says why on its standard error (the agent's log).

The program to register is the application's own executable, with --mcp:

System Program
macOS /Applications/xdfem2D.app/Contents/MacOS/xdfem2D
Windows C:\Program Files\xdfem2D\xdfem2D.exe (the folder the installer used)
Linux /usr/bin/xdfem2D after the .deb, or xdfem2D in the folder you unpacked it in

Claude Code (macOS shown):

claude mcp add xdfem2d -- /Applications/xdfem2D.app/Contents/MacOS/xdfem2D --mcp

Add --scope user after the name to have it in every project. claude mcp list shows whether it connected. Open a new session: the tools appear when it starts.

Claude Desktop, in claude_desktop_config.json:

{
  "mcpServers": {
    "xdfem2d": {
      "command": "/Applications/xdfem2D.app/Contents/MacOS/xdfem2D",
      "args": ["--mcp"]
    }
  }
}

Any other MCP client works the same way: the server speaks MCP over standard input and output.

From a source checkout

If you run xdfem2D from its source, install the environment (uv sync, which includes the mcp package) and register the Python module instead:

claude mcp add xdfem2d -- /path/to/project/.venv/bin/python -m xdfem2d_app.mcp_server

python -m xdfem2d_app.gui --mcp does the same as the executable, notice and expiry check included; python -m xdfem2d_app.mcp_server skips both, since a checkout has neither.

Check that it works on your machine

/Applications/xdfem2D.app/Contents/MacOS/xdfem2D --mcp-check

starts the server as an agent would, talks to it, and tries what an agent does: it builds a beam, analyses it, reads a reaction, designs it, writes a DXF, an Excel file and a Word report, draws a figure (which makes the server start the program a second time) and tries a path outside --root. Every step is reported as ok or FAIL with the reason, on the screen and in a file, ~/xdfem2d_mcp_check.txt (--log FILE chooses another). The file is what to look at, and to send if something fails: a Windows build has no console, and nothing it prints is seen.

The check refuses, like the server, if the notice has not been accepted in the window (exit code 2), and says so. The code is 0 when every step passes and 1 when one fails.

Keep the agent's files in one folder

--root FOLDER (after --mcp) is the only folder the agent may read or write files in:

claude mcp add xdfem2d -- /Applications/xdfem2D.app/Contents/MacOS/xdfem2D --mcp --root ~/Structures

A relative path (beam.x2d, reports/beam.docx) is relative to that folder, and the folders it needs are created inside it. A path that leaves it (../x.x2d, ~/Desktop/x.docx, an absolute path elsewhere, or a link that points out) is refused, with a message that names the folder. The folder must exist; if it does not, the server says so and does not start. Without --root the agent can use any path. Use it for an agent you do not follow step by step, or one other people share.

summary tells the agent which folder it is limited to.

How much the server tells the agent

--instructions short|grammar|full (after --mcp) sets what the server says when a client connects:

Level What the agent receives
short A line that points to the reference tool
grammar The command language and its rules
full (default) The above, and to read the model with summary before editing one that already has things

Models that do not read the documentation on their own do much better with full. Put it in the registration if you want another: ... xdfem2D --mcp --instructions grammar.

The tools

Tool What it does
reference The command language: one line per verb and object, with an example
summary What is loaded: the model (nodes with coordinates, bars, supports, sections, cases), the names get understands for its domain, variants, sequences, punching columns
new_model An empty model. domain is plane (frames and walls) or plate (slabs and grillages) and cannot change afterwards
load_model, save_model Open and save a .x2d file, with its results and design settings
commands Edit the model with the command language, one per line. All or nothing: on an error the model is untouched and the answer names the line
check Try commands on a copy and report the problems
get Read the model and its results: reactions, displacements, forces, design, lists. The word get may be left out. variant=ID reads a variant
undo Undo the last edit
ui_action Only in the window: change what it shows (a view, the layers, the colours of the results, the grid, the zoom), as the Display panel and the View menu do. It never changes the model. With no action it lists them
lock_model Lock the model against changes (commands, undo, design settings, a new or another model are refused; reading and analysing go on), or unlock it. Unlocking discards the results, so it is refused while there are some unless force=true. In the window it is the Lock of the toolbar, and you can unlock it there
auto_combinations The EN 1990 combinations (ULS, SLS-K, SLS-FR, SLS-QP) of the model's cases
run_analysis Analyse. scope="all" also solves the variants and their combinations
set_design Design preferences (γc, γs, αcc, the code editions, the crack-width limit ...), the combinations to design for and those for the crack width (SLS)
run_design Design: concrete (beams and columns), bars, areas (slabs and walls), crack, punching, steel, timber
beam_bars The bars proposed for each beam by zone, a page at a time
add_punch_column A column for the punching check of a slab
add_variant A variant: elements switched off, a support taken away, or other supports
add_variant_combination A combination across variants
set_stages, add_sequence Construction stages of the elements, and a sequence made from them
remove_overlay Remove a variant, a combination across variants, a sequence or a punching column
export_file A Word report (with figures if asked), the tables in Excel, a step-by-step design report (design-concrete, design-steel or design-timber, as .docx or .html), a DXF
export_figure A view of the model as the window draws it. In the window it shows the view there, and writes a picture file (PNG, PDF or SVG) if you give a path; with --mcp it writes the file, so the path is needed

Copying and transforming

Beyond the commands the Assistant knows, the agent has the Edit menu as commands (reference lists them): copy, array (rectangular or circular), rotate, scale, mirror and divide. They work on nodes, and on bars, slabs and walls through the nodes they are made of; a copy brings the bars, slabs and walls made of the copied nodes, and their loads if you add loads. The answer names the new ids (A_c2, E1_c2 ...), so that the next line can use them.

copy bar E1 by 0 3 loads
array nodes A,B rect 1 0 3 3        # three storeys, 3 m apart
mirror nodes all about x=6 copy
rotate nodes all about 0 0 by 90

Dynamics and second order

The agent can also set up the seismic and second-order analyses, which the Assistant does not:

add analysis M mass = 1 G + 0.3 Q                 # the mass of the loads (kN / 9.81)
add mass B,C mx 2 my 2 case M                     # a concentrated mass, in tonnes
add analysis Modes modal mass M modes 6           # the vibration modes: get modal
add spectrum EC8 ec8 ag 1.5 S 1.2 TB 0.15 TC 0.5 TD 2 [q 3]
add spectrum SP points 0 1  0.5 2.5  2 1          # or a spectrum of your own
add analysis Sx spectrum modal Modes function EC8 direction X rule CQC
add analysis P pdelta = 1.35 G + 1.5 Q beams 0.8 columns 0.8

Run the analysis, then read them with get modal, get spectrum case Sx, or get max ux on nodes all case Sx. A case that cannot be solved (for instance a modal case whose mass case has no mass) does not stop the run: the answer of run_analysis lists it in case_errors. P-Delta is for plane models.

Reading results

get takes the same questions as the command language. A few:

get sum reaction fy on nodes all case ULS
get max M on bars all case C1
get absmax uy on nodes all case C1
get design concrete bars longitudinal
get design concrete areas punching worst 3
get list bars

The summary tool lists the names a model understands (a plate has other reactions and displacements than a frame). Results are read per case or combination; a design is computed per combination, never per analysis case.

Variants and construction sequences

add_variant makes a variant of the model with its own supports or with some elements off, and run_analysis with scope="all" solves it; get ... variant=ID reads it, and the base model is read without variant. A construction sequence is set up from stages: set_stages({"1": ["E1"], "2": ["E2"]}), then add_sequence("SEQ", {"1": ["G"]}), and the phases are cases named seq__SEQ__Stage1, seq__SEQ__Stage2 ...

Figures

export_figure and the figures of a report are drawn by the application's own canvas, so they look as they do in the window. Writing a file takes a few seconds, because the canvas is opened off screen, in a process of its own. In the window, export_figure also shows the view there, as ui_action does.

The views are structure, loads, deformed, displacements, reactions, bending, shear and axial (the result ones need an analysis first). After a design, reinforcement (and shear_reinf), crack, tri_reinf (slabs and walls), steel_design, timber_design and column_design; and stress, fields, modal and constraints when the model has them. case is the load case, analysis case or combination (empty is the first). A view the model does not have is refused with the list of the ones it has.

An example

A conversation with an agent could go like this (the tool the agent chose is in brackets):

You: A simply supported concrete beam of 6 m, section 0.3 × 0.5, dead load 12 kN/m and live load 5 kN/m. Design it and write a report with the drawings to ~/Desktop/beam.docx.

  1. reference, summary (empty model)
  2. commands: add material ..., add section ..., nodes, bar, supports, cases, loads
  3. auto_combinations, run_analysis
  4. run_design concrete, run_design crack, run_design bars, beam_bars
  5. export_file report ... figures=true

What to know

  • Big models are read in pages. An answer has a size limit: a longer list is cut to its first items, with a note (rows_cut: first 100 of 2000) that says how to ask for less, and beam_bars returns a page at a time (offset, limit).
  • Not everything is covered. The diagrams of the bars of a combination across variants cannot be read with get (reactions and displacements can). A beam's bars are a proposal: the detail stored in the model is not changed, as the menu does.
  • Design preferences. A model loaded from a file brings the design settings saved in it. A new model uses the engine's defaults, which are the application's.
  • Optional packages. Word and Excel files need python-docx and openpyxl, DXF needs ezdxf, and the figures need the interface (pyside6). They come with the application's dependencies. If one is missing, the answer says which. A pandoc on the path is used for the design reports, when there is one.

If something does not work

What you see Why
The server is listed but fails to connect Run xdfem2D --mcp-check: it says which step fails and why. Or run the registered command in a terminal: it prints why on standard error (the notice not accepted, an expired version, a wrong path)
From a checkout: No module named 'mcp' The environment lacks the package: uv sync
A file is refused as "outside the folder this server may use" The server was started with --root: use a path inside it, or a relative one
The agent does not use the tools The session was open before the registration: start a new one
The agent writes commands the server refuses Use --instructions full, and ask it to call reference
An export says a package is not installed Install what the answer names
A figure is refused The view needs results (run the analysis) or a design that has not been run