Skip to content

fix(mcp): the server reads models from, and writes exports to, one folder its setup picks, and refuses a path that leaves it (#1883) - #1900

Merged
DrunkOnJava merged 13 commits into
mainfrom
feat/1883-mcp-root
Nov 13, 2026
Merged

DrunkOnJava merged 13 commits into
mainfrom
feat/1883-mcp-root

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

rvt-rs-mcp reads models from, and writes exports to, one folder that its setup picks; a path that leaves the folder is refused. This is the maintainer's decision on item 11 of #1883 (comment) with its refinement (the setup picks the folder; a working directory that is too broad is not a folder). Follows #1897 (the bounds, merged as cdd5f5d6): main is merged into this branch, and the diff of the branch against main equals the diff of its one commit, c7afa486, byte for byte (1,410 lines; the merge took this side on the hunks the squash overlaps, and no other commit of main since the fork touches rvt-mcp).

Why: the names, values and messages in a Revit file reach the client's model unmarked (#1883 item 10), so a crafted file could steer it into asking the server to open a file outside the project, or to overwrite one. Until now the server read any file the account could read and wrote anywhere but inside --output-dir.

The folder, in order: --root <folder>; the environment variable RVT_MCP_ROOT (for a client that passes only an environment); the folder the server was started in, unless that is the top of a file system (/, C:\), the home folder or a folder that holds it, since some MCP clients start their servers from /. With none, the server starts and every tool that touches a file refuses with a message that names --root. --root / and --unconfined lift the limit; --output-dir still sends exports to a folder of their own.

A relative path is taken from the folder. A path is compared with the folder once .. and links are resolved, and a path whose text alone puts it outside is refused before any file is looked at, so the refusal does not say whether the file exists. Not defended: another process that rewrites the links inside the folder while a call runs.

Upgrade: a setup that opens files outside the folder its client starts the server in now passes --root (or sets RVT_MCP_ROOT), or --unconfined for the old reach (fragment; docs/mcp.md, "The root folder").

Motivation

#1883 item 11 (the server's default reach), decided by the maintainer on 2026-11-13: confine reads and writes to one folder by default, compared after canonicalising so .. and symlinks cannot leave it, with a flag that widens it, stated in docs/mcp.md and the tool descriptions, and an upgrade note.

Changes

  • rvt-mcp/src/root.rs (new): Root (the canonical folder; locate, holds, refusal), Reach (Folder, Unset or Anywhere; choose, limit), too_broad, home_folders, and lexical, the text-only resolution of . and ... Pure helpers with failure-first tests (a .. that climbs out, a name that only starts like the root's, /.., a refusal that does not name the root, a working directory that is /, the home folder or above it).
  • store.rs (Identity::of takes the reach), output.rs (plan confines an export to --output-dir, else the root), config.rs, main.rs (--root, --unconfined, the environment variable, the start-up log), args.rs and server.rs (the tool descriptions and the server instructions say where the folder is).
  • tools/re/mcp_client.py, tools/re/mcp_answers_vs_ifc.py: Measure's scripted client starts the server with --root set to the model's folder when the server has the flag (it reads --help), since Measure runs the same scorer against the server of both sides.
  • docs/mcp.md, the READMEs, docs/maintaining.md, docs/mcp-tools.*, changelog.d/changed/1883-mcp-root.md.

Testing

Unit tests are banned in this repository apart from pure helpers; the check is the built server driven over stdio (rvt-mcp/tests/mcp_stdio.rs, real files, RVT_MCP_ANSWERS_DIR schema check), with the existing tests started --unconfined since their fixtures are outside the crate's folder:

  • the default root: a relative and an absolute path inside are opened and exported to; another folder, a .. that leaves, a file that is not there, a link to a file outside and a link to a folder outside are refused with the same words (a file there and a file not there read alike), and no export is written outside; Passed in CI on 5f0a62e (the_server_acts_inside_the_folder_it_is_started_in, a_path_outside_output_dir_is_refused).
  • --root beats RVT_MCP_ROOT; a relative path and an export go to the root, not the start folder; --root / and --unconfined reach outside; --output-dir outside the root takes the exports and reading stays inside; Passed in CI (root_names_another_folder_and_relative_paths_are_taken_from_it, unconfined_reads_and_writes_outside_the_start_folder, an_output_dir_outside_the_root_takes_the_exports, the_setup_picks_the_root_by_flag_or_environment_whatever_the_working_directory, a_root_and_an_output_dir_reached_through_a_link_take_paths_spelled_either_way).
  • a working directory that is /, the home folder or a folder above it gives no root: the tools refuse, naming --root; Passed in CI (a_working_directory_that_is_too_broad_gives_no_root).
  • a root that is missing or a file, and --root with --unconfined, fail to start; Passed in CI (a_root_that_is_not_a_folder_or_both_flags_fail_to_start).
  • this PR's CI. I cannot build locally (rule of this repository), so CI is the first compile of this change; the tool contract (docs/mcp-tools.json) is regenerated from it. On 5f0a62e the fast jobs pass: build and real files (stable and MSRV), clippy, doc, fmt, PII guard, corpus health, and MCP server on Einhoven; full CI runs once the PR is ready.
  • Measure (the scripted client opens each model with --root): mcp_answers_vs_ifc is unchanged on every model that has it. Run 43410662379 (scorers from this branch, head 5f0a62e): exports 146 of 146 identical, diagnostics 121 of 121 identical, scorer differences none beyond what only the head side writes.

Audit-honesty checklist

  • README / docs reflect the current state after this PR
  • A user-visible change has its entry as a fragment under changelog.d/
  • If a limitation was resolved, the docs are updated (docs/mcp.md no longer says reading is not confined)
  • Commit messages describe WHAT changed and WHY
  • No emojis in code, docs, or commit messages
  • No private paths, personal email addresses, or internal jargon in committed files
  • Reverse-engineering finding: not one (no format finding)

Legal and contribution hygiene

  • I agree this work is licensable under Apache-2.0
  • This PR contains no Autodesk proprietary source, decompiled internals, or NDA'd SDK content
  • No new test fixtures

Breaking changes

The default reach of rvt-rs-mcp narrows (see Upgrade above). No export or answer changes.

Related issues

Refs #1883 (item 11).

…s take a place at a gate, the glb streams, the progress queue is capped and list_rooms is paged (#1883)

Text from the file in an answer is cut at --max-field-chars (512), the
diagnostics document keeps at most 5,000 entries a list, and an answer over
--max-answer-bytes (4 MiB) is refused. list_rooms takes limit and offset as
list_elements does, a limit outside 1 to 1000 is an error and the schema says
so, reading a file and decoding take a place at a gate as wide as
--max-open-models, export_gltf writes the GLB with the new
rvt::ifc::gltf::write_glb_to, the progress queue holds 16 events, a phase name
over 256 characters is refused and a file with no readable modification time
is refused. The Measure scorer's MCP client pages list_rooms.
…e cut at the message limit, the gate and the answer limit say what they bound (#1883)

The longest of 1,094 measured diagnostics documents has a 1,129-character warning that rvt-rs writes itself, so a field limit of 512 would have cut honest output; names and values are cut at 1,000 characters and messages and the diagnostics' strings at eight times that. list_rooms keeps today's answer for any model up to 1000 spaces.
…ormat's lengths and padding at every remainder, and a writer's error fails the write (#1883)
…lder its setup picks, and refuses a path that leaves it (#1883)

The setup picks the folder: --root, the environment variable RVT_MCP_ROOT, or
the folder the server was started in unless that is the top of a file system,
the home folder or a folder above it, in which case every tool that touches a
file refuses and names --root. A path is compared once .. and links are
resolved; one whose text alone is outside is refused before any file is looked
at. --root / and --unconfined lift the limit. Upgrade: a setup that opens files
outside its start folder now passes --root.
Base automatically changed from fix/1883-mcp-bounds to main November 13, 2026 09:41
… the PII guard does not take for a person's path (#1883)
…hs spelled either way, and the resolved path stays the gate (#1883)

A folder behind a link has two names (/tmp/work and /private/tmp/work on macOS,
a symlinked /home on Linux), and a client sends the one it knows. The text
check before any file is looked at compared a path with the resolved name only,
so the ordinary spelling of a path inside the folder was refused, and an
--output-dir named through a link refused its own exports. The folder keeps
the spelling it was given (and the shell's PWD where that names it) beside the
resolved path; a path outside by every name is still refused before any file is
looked at.
@DrunkOnJava
DrunkOnJava marked this pull request as ready for review November 13, 2026 10:59
…s the tests that use it are (#1883)

Windows compiles the stdio tests with warnings as errors, and the helper was
unused there: the full CI of #1900 failed on it.
@DrunkOnJava

Copy link
Copy Markdown
Owner Author

Approved at b73808e by the review bot as a self-approval, under Griffin's answer of 2026-11-12 ("You are allowed to self-approve"): rvtDevelop's session has not read the head sent to it at about 11:40 UTC. I re-read the whole diff (root.rs and its path logic, Identity::of and output::plan, the argument and environment precedence, the tool descriptions and the regenerated contract, the end-to-end tests for the default root, --root, --unconfined, --output-dir, a broad working directory, the environment variable and a root reached through a link) as if another session had written it.

@DrunkOnJava
DrunkOnJava merged commit 6fdb904 into main Nov 13, 2026
36 checks passed
@DrunkOnJava
DrunkOnJava deleted the feat/1883-mcp-root branch November 13, 2026 13:07
DrunkOnJava added a commit that referenced this pull request Nov 13, 2026
…reads are not confined to a folder, which #1900 changed
DrunkOnJava added a commit that referenced this pull request Nov 13, 2026
## Summary

Release metadata for v0.22.0 (RELEASE.md, steps 4 to 7), cut from `main`
at `2b815423`:
- every version file moves to 0.22.0 (`tools/release/bump_version.py`),
and `CITATION.cff` is dated 2026-11-13;
- the 22 fragments under `changelog.d/` are assembled into a `[0.22.0]`
section, with its introduction, what is not measured, the comparison
with 0.21.0 and "Upgrading from 0.21";
- the README's release lines name v0.22.0;
- Core Interior's two witness observations and verdicts, and the two
synthetic IFC fixtures, are taken from the CI artifacts of run
[43491437324](https://github.com/DrunkOnJava/rvt-rs/actions/runs/43491437324)
(this PR's head at `80115b0a`): only `witness_version`, the verdict
hashes and the version strings of the IFC header and `IFCAPPLICATION`
differ, which the diff shows.

**Why now.** The security work of 0.22.0 (the MCP server's folder and
bounds, `rvt-doc --redact`, `rvt-info -f csv`, `rvt-dump`, the wall cut
chain, the Python bindings and the viewer) and the element fixes of its
backlog are on `main`, and 0.21.0 was cut the same day without them.
GlobalId work (#878, #1929) is not in it: it moves GlobalIds and ships
on its own.

Measured and rehearsed:
- the comparison with 0.21.0 is in the section, from Measure run
[43491038743](https://github.com/DrunkOnJava/rvt-rs/actions/runs/43491038743)
(unfiltered, `main` at `2b815423` against `v0.21.0`'s `b979b791`);
- `publish.yml` rehearsal on this branch, as RELEASE.md step 7 says: run
[43491446679](https://github.com/DrunkOnJava/rvt-rs/actions/runs/43491446679)
on `80115b0a` passed (it publishes nothing); the later commits change
the witness files, the fixtures and the notes only.
- Two statements of the entries were contradicted by that Measure and
are corrected in the notes: the 21 doors of each office that stay out of
their curtain wall (RE-453 takes them: 268 of 268 are aggregated) and
the curtain door 216844 left out on 2026 and 2027 (RE-452 takes it). The
second read (rvtDevelop's) found a third: the Security entry of the MCP
server still said its reads are not confined to a folder, which #1900
changed; it is corrected at `9c4403fa`.

## Testing

- `python3 tools/release/changelog.py check` passes: no fragment is
left.
- `bump_version.py` checks the version files with the preflight's own
`check_versions`.
- The PII guard runs `release_preflight.py` on this PR.

## Related issues

Release 0.22.0. Milestone `0.22.0`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant