Metadata-Version: 2.4
Name: roiko-mcp
Version: 0.2.0
Summary: MCP server for ROIKO: build, analyse and check structural models through the ROIKO API from Claude, Cursor and other MCP clients.
Author: ROIKO
License-Expression: LicenseRef-Proprietary
Project-URL: Homepage, https://roiko.ai
Project-URL: App, https://app.roiko.ai
Keywords: mcp,model-context-protocol,structural-engineering,eurocode,fea,roiko
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Classifier: Typing :: Typed
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: mcp<3,>=2.3
Requires-Dist: httpx<1,>=0.28
Requires-Dist: pydantic>=2
Requires-Dist: starlette>=0.48
Requires-Dist: uvicorn>=0.31.1
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: respx; extra == "dev"
Requires-Dist: httpx2; extra == "dev"
Dynamic: license-file

# ROIKO MCP server

This server connects an MCP client to the ROIKO API. Create a key in ROIKO settings and keep it private. Until publication, replace the path below with the absolute path to this `mcp_server` folder.

```json
{"mcpServers":{"roiko":{"command":"uvx","args":["--from","C:/path/to/Roiko/mcp_server","roiko-mcp"],"env":{"ROIKO_API_KEY":"your key here"}}}}
```

Add this to Claude Desktop's configuration and restart it. Call `roiko_whoami` to check the connection. `ROIKO_API_URL` selects another API endpoint. Once the package is on PyPI the `--from` part goes and the command is `uvx roiko-mcp`.

mcp-name: ai.roiko/mcp

## Remote server — after the server is switched on

The same server runs at `https://app.roiko.ai/mcp` (Streamable HTTP). Nothing to install: send your key as a bearer. This recipe works only once ROIKO has switched the remote server on; until then the local recipe above is the one to use.

```
claude mcp add --transport http roiko https://app.roiko.ai/mcp --header "Authorization: Bearer rk_live_…"
```

Cursor and VS Code take the same URL and header in their `mcp.json`:

```json
{"mcpServers":{"roiko":{"url":"https://app.roiko.ai/mcp","headers":{"Authorization":"Bearer ${env:ROIKO_API_KEY}"}}}}
```

Each request is checked against your key (a revoked key stops working within 30 s). A request without a key, or with a key ROIKO does not know, gets a 401. The remote server never sees anything but your own key, and every call it makes to ROIKO is made with that key, so you see exactly what the key sees. Read-only mode is per server, not per request: use a key with only the `read` scope for an autonomous agent.

### Running the remote server yourself

`roiko-mcp --transport http` listens on `ROIKO_MCP_HOST:ROIKO_MCP_PORT` (default `127.0.0.1:8001`) at `/mcp`, behind a reverse proxy that sets `Host`, `X-Real-IP` and `X-Forwarded-For` and does not buffer `text/event-stream`. It refuses to start if `ROIKO_API_KEY` is set (the key comes with each request). Variables: `ROIKO_API_URL` (the API it calls, HTTPS or HTTP on loopback), `ROIKO_MCP_ALLOWED_HOSTS` (comma list of accepted `Host` values; default the resource URL's host plus `host:port`), `ROIKO_MCP_RESOURCE_URL` (default `https://app.roiko.ai/mcp`), `ROIKO_MCP_STATE_KEYS` (one or more 32+ character secrets that seal multi-step request state across restarts; without it a fresh key is made at every start), `ROIKO_MCP_READ_ONLY`.

## Tools

Read tools (any key): `roiko_whoami`, `roiko_list_projects`, `roiko_list_models`, `roiko_get_model_summary`, `roiko_get_model`, `roiko_get_job`, `roiko_get_results`, `roiko_get_checks`, `roiko_search_catalogue`, plus the resources `roiko://projects`, `roiko://projects/{id}/models`, `roiko://models/{id}`, `roiko://models/{id}/results`, `roiko://models/{id}/report` (markdown) and `roiko://catalogue/{name}`.

Write tools (the key needs the `write` scope; `roiko_create_model_from_text` also needs `run`):

- `roiko_create_project` — makes a new project (name, optional country, location, description, client, project number) and returns its id, to use as `project_id` below. Needs the `write` scope and an author seat.
- `roiko_create_model_from_text` — plain English in, a saved model out. Without `model_id` it creates a model (in `project_id`, else the personal workspace) and generates into it; with `model_id` it changes that model by prompt. `dry_run: true` previews without saving. Each saved version is of kind `ai`.
  - When ROIKO needs more detail it asks back. A client that supports MCP elicitation gets a form and the call finishes on its own; any other client receives `status: "question"` with a `thread`, and the assistant calls again with the same `prompt` and `model_id` plus `answer` and that `thread`.
  - A big model may come back `status: "partial"`: what was built is saved, the tool continues once with the API's `thread`, and if the model is still incomplete it says what is missing.
  - A generation that outruns the API's 85 s budget is reported as an error that says nothing was saved; the model created for it can be reused with `model_id`.
- `roiko_edit_model` — precise, bounded edits by id (`add_member`, `update_member`, `remove_member`, `add_foundation`, `remove_foundation`, `add_surface`, `update_surface`, `remove_surface`, `set_release`, `set_support`, `upsert_load_case`, `remove_load_case`, `set_levels`, `set_grids`, `replace_structure`), 1 to 50 operations applied together or not at all. The server reads the full structure, applies the patch and saves with `expected_version_id` (the model's current version when none is given), so every key the assistant never named survives. If the model changed meanwhile the API answers a version conflict, nothing is saved, and the tool says to read the model again and retry. A refused structure names the element, the field and the reason. Each saved version is of kind `api`.
  - **Bulk operations** — for repeating, mirroring and group edits, so the text tool is not needed. Each counts as one of the 50 operations. Limits: 2,000 rows a table, 5,000 elements created and 5,000 loads added a call, 20,000 elements a model; a call with a bulk operation may take up to 90 s. The full fields are in the tool's own input schema. One example each:
    - `add_members_table` / `add_foundations_table`: `{"op": "add_members_table", "kind": "beam", "defaults": {"profile": {"profile_type": "IPE", "size": "300"}, "material": "S355"}, "columns": ["id", "x1", "y1", "z1", "x2", "y2", "z2"], "rows": [["B1", 0, 0, 6, 6, 0, 6], ["B2", 6, 0, 6, 12, 0, 6]]}`
    - `copy_transform` (move, mirror, rotate about a vertical axis, polar array; loads, releases and supports only when named in `include`): `{"op": "copy_transform", "select": {"id_suffix": "-b0"}, "transform": {"rotate": {"axis_point": [0, 0], "angle_deg": 7.5, "count": 47}}, "id_rename": {"replace": ["-b0", "-b{n}"]}, "include": ["members", "foundations", "surfaces", "supports", "releases"]}`
    - `update_members`: `{"op": "update_members", "select": {"kinds": ["beam"], "id_prefix": "SB"}, "set": {"cardinal_point": 1}}`
    - `update_surfaces` (thickness in metres): `{"op": "update_surfaces", "select": {"kinds": ["slab"]}, "set": {"thickness": 0.22}}`
    - `add_loads`: `{"op": "add_loads", "load_case_id": "G", "select": {"kinds": ["beam"], "id_prefix": "SB"}, "load": {"kind": "distributed", "qz": -8}}`; inside `upsert_load_case` a load may carry `select` in place of `element_ref` or `surface_ref`.
  - A selector (`select`) takes `ids`, `id_prefix`, `id_suffix`, `kinds`, `profile`, `section`, `level_z` and `box`; every condition given must hold, and matching nothing is an error.
  - `remove_member` keeps the loads that name the member, as a delete in the app does, and says how many; `remove_surface` removes the area loads that name it.

Both model tools return the model summary and a `resource_link` to `roiko://models/{id}`, never the structure JSON.

## Analysis tools

- `roiko_run_analysis` (a write tool; the key needs the `run` scope) — runs the analysis and code checks on the model's latest saved version, or on `version_id`. Optional: `national_annex` (two letters), `second_order`, `include_self_weight`, `consequence_class`. It asks the API to answer at once (`Prefer: respond-async`), then checks the job every 2 s (every 3 s after 20 s) for up to `wait_seconds` (default 45, at most 60; one call never waits past 90 s). A finished run returns the results summary: the verdict line, the highest utilisations per family, the worst deflection, the reactions and the stability check. A run still going returns its `job_id` and says to call `roiko_get_job` a few seconds later. A cached result comes back at once. Each run spends the user's analysis allowance, and the API saves the result as a version of kind `analysis`.
- `roiko_get_job` — checks a job (waits up to `wait_seconds`, default 20) and returns the same summary when it is done. A failed or cancelled job is an error that says why.
- `roiko_get_results` — the saved result in slices: `kind` `summary`, `checks`, `deflections` (mm, limit, utilisation) or `reactions` (kN, kN·m, ruling combination only), with `member_ids`, `min_utilisation`, `combination`, `sort`, `limit` (up to 50) and `cursor`.
- `roiko_get_checks` — the API's check rows (`GET /models/{id}/checks`): governing check, clause, demand and capacity where the result names them, utilisation, verdict, combination. `failing_only`, `family` (`steel`, `concrete`, `foundation`, `base_plate`, `wall`, `slab`, `joint`, `deflection`), `member_ids`, `min_utilisation`, `detail` and `cursor`. `detail: "all"` gives every check row: each EN 1993 check of a steel member (§6.2.5 bending with M_Ed and M_Rd, shear, buckling, ...) under its governing combination, and each pad or plate sub-check; a row with no capacity or no ratio says why in `note`. It is on by default with `member_ids` or family `foundation` / `base_plate`; `detail: "governing"` keeps one row per member.

Every analysis reply stays under 40 000 characters and carries a `resource_link` to `roiko://models/{id}/results` for the full result. Plan limits (402), a plan without analysis (403), rate limits (429), a model with no result yet and cancelled runs each come back as one plain sentence.

## Export and catalogue tools

- `roiko_export` (a write tool: it spends the report and export allowances; the key needs the `run` scope) — `format` `report` returns the calculation report as markdown, inline up to 40 000 characters; a longer report is cut with `truncated: true` and a `resource_link` to `roiko://models/{id}/report`, which holds it whole (the last report is kept 10 minutes, so reading it spends nothing more). `dxf`, `ifc`, `sheet-pdf` (needs `sheets`) and `mto` always come back as a download link with its expiry (about 15 minutes), never as file bytes. `mto` also returns the take-off totals (steel by profile, concrete by grade, rebar, panels) unless `mto_summary_too` is false. Until download links are switched on at the server, a file export says so in one plain sentence; `mto` still returns its totals.
- `roiko_search_catalogue` — sections (searched by the API with `query` and `family`, optionally limited to a `project_id`), steel, concrete and rebar grades, base-plate parts, grating types, slab and wall thicknesses, and jurisdictions (filtered here). Paged with `cursor`, 25 rows by default, cached 10 minutes; `response_format: "detailed"` adds the section properties.

## Prompts

`design_review` (summary, then failing checks, then deflections), `explain_governing_check` (one member's check, clause, demand and capacity) and `size_a_beam` (the lightest section in the family under a target utilisation, at most three tries).

## Read-only mode

`ROIKO_MCP_READ_ONLY=true` (also `1` or `yes`) hides the five write tools (`roiko_create_project`, `roiko_create_model_from_text`, `roiko_edit_model`, `roiko_run_analysis`, `roiko_export`) from the tool list, and they refuse if a client calls them anyway. `roiko_whoami` reports `read_only: true`. Use it, or a key with only the `read` scope, for autonomous agents that must not change models; a key without `write` is refused by the API with a readable message in either mode.

## Changes

**0.2.0** (not published yet)
- `roiko_edit_model` gains bulk operations: `add_members_table`, `add_foundations_table`, `copy_transform` (move, mirror, rotate, polar array; loads, releases and supports carried when named), `update_members`, `update_surfaces`, `add_loads`, and loads by selector inside `upsert_load_case`. Slabs, walls and gratings by id: `add_surface`, `update_surface`, `remove_surface`.
- A refused structure names the element (kind, index, id), the field and the reason.
- A run refused for memory says the estimate and what is free (`insufficient_memory`).
- `roiko_create_model_from_text` refuses an ask of more than about 200 elements before anything is made or charged, and points to the bulk operations (`too_large_for_text`).
- Concrete sections also take millimetres (`b_mm`, `h_mm`, `grade`); thickness and mesh size above sensible bounds are refused as millimetres typed as metres.
- `remove_member` says how many loads still name the removed member.
- A save no longer sends the 3D viewer's profile outline back to the API; on very large models (about 16,000 steel members) that made the next edit fail as `extensions_too_large`.
