Metadata-Version: 2.5
Name: dlubal-mcp
Version: 1.0.28
Summary: MCP server enabling AI tools to interact with running Dlubal structural analysis applications (RFEM 6, RSTAB 9, RSECTION 1)
Project-URL: Documentation, https://apidocs.dlubal.com/installation_mcp.html
Project-URL: API Reference, https://apidocs.dlubal.com/
Project-URL: Homepage, https://www.dlubal.com
Author-email: Dlubal Software <api@dlubal.com>
Keywords: dlubal,fem,mcp,rfem,rsection,rstab,structural-analysis
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: Microsoft :: Windows
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.11
Requires-Dist: fastmcp<3,>=2.13.0.2
Requires-Dist: pydantic-settings<3,>=2.0
Requires-Dist: pydantic<3,>=2.11.7
Requires-Dist: starlette>=0.40
Requires-Dist: uvicorn[standard]>=0.30
Provides-Extra: dev
Requires-Dist: grpcio; extra == 'dev'
Requires-Dist: protobuf>=5; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Description-Content-Type: text/markdown

# dlubal-mcp

`dlubal-mcp` lets an AI assistant such as Claude, GitHub Copilot or Codex work
with **RFEM 6, RSTAB 9 and RSECTION 1** running on your PC: inspect and create
models, run the calculation and read results. It is an
[MCP](https://modelcontextprotocol.io) server built on the
[dlubal.api](https://pypi.org/project/dlubal.api/) client.

Step-by-step setup with screenshots for each AI client:
**[MCP Server installation guide](https://apidocs.dlubal.com/installation_mcp.html)**.

## Before You Start

- **The application is open and its API server is switched on**
  ([Starting Server](https://apidocs.dlubal.com/starting_server.html)).
  `dlubal-mcp` works with the running application; it does not start it.
- **Your Dlubal API key is saved on the PC**
  ([Authentication](https://apidocs.dlubal.com/access_control.html)). No key
  goes into the MCP configuration.
- **API requests count toward your subscription**, also those made by the AI.
- **You know your application version**, for example from its installation
  folder `C:\Program Files\Dlubal\RFEM 6.16`. It decides the `dlubal.api`
  version: the second number is the same.

  | Application | `dlubal.api` |
  |---|---|
  | RFEM 6.16, RSTAB 9.16, RSECTION 1.16 | `2.16.*` |
  | RFEM 6.15, RSTAB 9.15, RSECTION 1.15 | `2.15.*` |

## Setup

1. **Install [uv](https://docs.astral.sh/uv/getting-started/installation/)**
   once, then restart your AI client so it finds the `uvx` command:

   ```bash
   winget install --id=astral-sh.uv -e
   ```

2. **Add the server to your AI client.** Replace `2.16.*` with your version
   from the table above. For Claude Code (`.mcp.json`), Claude Desktop and
   Cursor:

   ```json
   {
     "mcpServers": {
       "dlubal-mcp": {
         "command": "uvx",
         "args": ["--python", "3.12", "--with", "dlubal.api==2.16.*",
                  "dlubal-mcp", "--transport", "stdio"]
       }
     }
   }
   ```

   GitHub Copilot (`.vscode/mcp.json`) uses `"servers"` instead of
   `"mcpServers"`. In a terminal, Claude Code can add it for all folders:

   ```bash
   claude mcp add --scope user dlubal-mcp -- uvx --python 3.12 --with "dlubal.api==2.16.*" dlubal-mcp --transport stdio
   ```

3. **Check the connection.** Ask the assistant: *"Check the connection to RFEM
   with dlubal-mcp."* It calls `get_rfem_application_info`, which answers
   `"status": "ok"` and the RFEM version.

`uvx` keeps Python and the packages in its own cache, apart from the
application's Python and your project environments. The first start downloads
them and can exceed the client's startup timeout; running the command once in a
terminal with `--help` instead of `--transport stdio` avoids that.

**Updates.** After an application update, change the `dlubal.api` version in
the configuration and restart the client. For a new `dlubal-mcp` release, close
the client and run `uv cache clean dlubal-mcp`.

### Without uv

Install into a virtual environment of its own, with Python 3.11–3.14. In a
Command Prompt (`%USERPROFILE%` does not work in PowerShell):

```bash
py -3.12 -m venv %USERPROFILE%\dlubal-mcp
%USERPROFILE%\dlubal-mcp\Scripts\python.exe -m pip install dlubal-mcp "dlubal.api==2.16.*"
```

`dlubal-mcp` does not install `dlubal.api` itself, because it must be your
application's version, not the newest. In the configuration, use this
`python.exe` as the command, with backslashes doubled in JSON:

```json
"command": "C:\\Users\\<username>\\dlubal-mcp\\Scripts\\python.exe",
"args": ["-m", "dlubal_mcp", "--transport", "stdio"]
```

## Tools

| Tool | What it does |
|---|---|
| `health_check` | Lists installed and running applications, client version and available tools |
| `get_rfem_application_info` | Checks the connection to RFEM and reads its version |
| `inspect_rfem_api` | Looks up exact RFEM API names: objects, fields, enum values, methods |
| `write_rfem_model` | Creates a new RFEM model from typed objects, without Python |
| `calculate_rfem_model` | Runs the calculation |
| `read_rfem_results` | Reads selected results without changing the model (see below) |
| `run_rfem_script` | Runs a Python script against the open RFEM model |
| `get_rfem_execution` | Shows the status and output of an earlier script or model operation |
| `get_rstab_application_info`, `inspect_rstab_api`, `run_rstab_script`, `get_rstab_execution` | The same for RSTAB 9 |
| `get_rsection_application_info`, `inspect_rsection_api`, `run_rsection_script`, `get_rsection_execution` | The same for RSECTION 1 |

**For AI assistants:**

- Check the connection first with `get_<product>_application_info`.
- Prefer the typed tools (`write_rfem_model`, `calculate_rfem_model`,
  `read_rfem_results`) to scripts.
- Before writing a script, look up names with `inspect_<product>_api` and
  follow the [Dlubal API documentation](https://apidocs.dlubal.com/). The
  server runs the script as given; its correctness is the caller's
  responsibility.
- If an operation fails or times out, read its outcome with
  `get_<product>_execution` and inspect the model. Never re-run it blindly.

### Reading results

`read_rfem_results` reads five result types: calculation status, member internal
forces, node deformations, stability critical load factors and steel member
design ratios. It takes object numbers and loadings (e.g. `LC1`, `CO2`), checks
every returned row against them, and returns at most 100 rows of numbers with
units. It never calculates, writes, opens, saves or switches a model.

Each answer carries the model GUID, the RFEM version, a fingerprint of the model
input and a hash of the result. The model is fingerprinted before and after the
read; if it changed in between, the answer is `unavailable`. `no_results` and `unavailable` are not successful checks. Model
paths, object names and free-form messages are never returned.

### When a script fails

- After a write in a script fails, the script can only read. Catching the
  exception does not change that, and the tool reports the original failure.
- Changes made before the failure are **not rolled back**. Check the model
  before continuing.
- If the outcome is uncertain, for example the connection broke during a
  write, the operation is recorded as unknown and new scripts are refused.
  Reading still works. Check the model, then close RFEM: the block is released
  once the RFEM session that ran the operation has ended.

## Configuration

Set these as environment variables, for example in an `env` block next to
`args` in the client configuration.

| Variable | Default | Purpose |
|---|---|---|
| `RFEM_API_PORT`, `RSTAB_API_PORT`, `RSECTION_API_PORT` | `9000`, `9001`, `9002` | API server port of the application |
| `RFEM_URL`, `RSTAB_URL`, `RSECTION_URL` | `127.0.0.1` | API server address |
| `DLUBAL_MCP_PRODUCTS` | `rfem,rstab,rsection` | Applications this server offers |
| `DLUBAL_MCP_ALLOW_SCRIPTS` | `true` on stdio, `false` on HTTP | `false` withholds the script tools |
| `RFEM_API_KEY`, `RSTAB_API_KEY`, `RSECTION_API_KEY` | from `config.ini` | API key, only if it is not saved on the PC |

**Applications of different versions.** One server uses one `dlubal.api`, and a
client of the wrong version can return wrong values without an error. With, for
example, RFEM 6.16 and RSTAB 9.15, add two servers: one with `dlubal.api==2.16.*`
and `DLUBAL_MCP_PRODUCTS=rfem`, one with `dlubal.api==2.15.*` and
`DLUBAL_MCP_PRODUCTS=rstab`.

## HTTP Transport and Dlubal CALC

AI clients start `dlubal-mcp` themselves over **stdio**: no port, no access
token. The server's default transport is HTTP, so the configuration must pass
`--transport stdio`.

The HTTP transport serves clients that cannot start a process, such as Dlubal
CALC in the browser. CALC reaches your PC through the **Dlubal Connector**
(`DlubalConnect.exe`), which installs, starts and updates its own copy of
`dlubal-mcp` in `%LOCALAPPDATA%\Dlubal\Connector\mcp-runtimes`. That copy is
independent of the one you configure for your AI client.

- **Both at once.** Both servers share the execution journal in
  `%LOCALAPPDATA%\DlubalMCP`. While one runs a script or model operation, the
  other refuses new ones with `busy`, and RFEM accepts only one API client at a
  time. Retry, or use one at a time. Do not point `RFEM_EXECUTION_STATE_FILE`
  (or its RSTAB/RSECTION equivalents) at another file, or this protection is
  lost.
- **Access protection.** An HTTP server binds to a numeric loopback address and
  requires a bearer token (`DLUBAL_MCP_ALLOWED_API_KEYS`, sent as
  `Authorization: Bearer <token>`), separate from the Dlubal API key. The
  Connector sets this up for its own server. Details are in
  `docs/http-authentication.md` in the source distribution.

## Related

- [MCP Server installation guide](https://apidocs.dlubal.com/installation_mcp.html)
- [Dlubal API documentation](https://apidocs.dlubal.com/)
- [dlubal.api](https://pypi.org/project/dlubal.api/)
- [Dlubal Software](https://www.dlubal.com)
