Repository navigation
fix(mcp): answers and text from the file are bounded, concurrent opens take a place at a gate, the glb streams, the progress queue is capped and list_rooms is paged (#1883) - #1897
Merged
Conversation
…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.
…r limit, and the test takes unwrap_or (#1883)
…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.
DrunkOnJava
marked this pull request as ready for review
November 13, 2026 08:49
…ormat's lengths and padding at every remainder, and a writer's error fails the write (#1883)
16 tasks done
DrunkOnJava
added a commit
that referenced
this pull request
Nov 13, 2026
…lder its setup picks, and refuses a path that leaves it (#1883) (#1900) ## 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](#1883 (comment))) with its [refinement](#1883 (comment)) (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: - [x] 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`). - [x] `--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`). - [x] 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`). - [x] 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`). - [x] 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. - [x] 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 - [x] README / docs reflect the current state after this PR - [x] A user-visible change has its entry as a fragment under `changelog.d/` - [x] If a limitation was resolved, the docs are updated (`docs/mcp.md` no longer says reading is not confined) - [x] Commit messages describe WHAT changed and WHY - [x] No emojis in code, docs, or commit messages - [x] No private paths, personal email addresses, or internal jargon in committed files - [x] Reverse-engineering finding: not one (no format finding) ## Legal and contribution hygiene - [x] I agree this work is licensable under Apache-2.0 - [x] This PR contains no Autodesk proprietary source, decompiled internals, or NDA'd SDK content - [x] 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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rvt-rs-mcpbounds what an answer carries and what the server holds (#1883): text from the file, the diagnostics document, the answer's size, concurrent opens, the GLB export's memory, the progress queue, phase names and the file's modification time.list_roomsis paged and alimitoutside 1 to 1000 is an error.Motivation
Batch 5's audit of
rvt-mcpfound answers and server memory sized by the file and the client with no byte cap, and file text reaching the client's model with nothing marking it as file content. Ten of the issue's eleven items are done here; item 11 (confining reads to the folder the server started in) is a product call recorded on the issue, not changed.Changes
rvt-mcp/src/bounds.rs(new):--max-field-chars(1,000) cuts a name or value from the file and writes how much it cut; a message and each string of the diagnostics are cut at eight times that (of 1,094 diagnostics documents from five Measure runs the longest string is 1,129 characters, the longest list 1,070 and the largest object 1,019, so none is changed);--max-answer-bytes(4 MiB, counted once; the wire message carries the answer twice) refuses a longer answer; the diagnostics document keeps at most 5,000 entries of a list or object and says which it held innotes(items 2, 3, 10).rvt-mcp/src/gate.rs(new): reading a file and decoding take a place at a gate as wide as--max-open-models, so no more than that many models decode at once, and a cancelled call leaves the queue (item 4). A call that has read its file and waits to decode keeps the file's bytes meanwhile: the gate does not bound those (RevitFileholds the file; the comment ingate.rssays why the place is not held across the two).list_roomstakeslimitandoffsetand answerstotal,offset,limit,returned(item 1). Its default is 1000, its most, so a model with up to 1000 spaces answers as before (the largest measured has 308) and the cap is what bounds the answer;list_elementskeeps 100. The tool description says that areturnedbelowtotalis a list that is not complete. Alimitoutside 1 to 1000 is a tool error and the schema states the range (item 8).export_gltfwrites the GLB from the buffer it builds with the newrvt::ifc::gltf::write_glb_to(same bytes aswrite_glb; a GLB over 4 GiB is an error, where its length wrapped) (item 5).tools/re/mcp_client.py(Measure's MCP scorer) pageslist_rooms; it takes the old server's unpaged answer too, so the base side of a comparison still reads.docs/mcp.md,docs/mcp-tools.*(from CI's artifact),changelog.d/security/1883-mcp-bounds.md.Testing
Unit tests are banned in this repository: none added. The end-to-end test
rvt-mcp/tests/mcp_stdio.rsdrives the built server over stdio:tools/check-local.sh: CI's full run passed atb0ca6303(no local builds here; rustfmt was run locally).an_answer_is_bounded: text cut at 1 character and messages and diagnostics at 8, an answer limit of 900 bytes, the summary refused, the levels answer not, the export's diagnostics and a path message cut), pages of three coveringlist_roomson every filedriveruns (the fixture; Einhoven where CI has it), the 1000 default, alimitof 0, 1001 and 100,000 refused on both list tools, a 300-character phase refused, and four concurrent opens under--max-open-models 1that all finish with one model kept (concurrent_opens_of_different_files_all_finish).rvt-ifc's andrvt-gltf's, which the existing test compares (the glb now throughwrite_glb_to; three pure tests insrc/ifc/gltf.rspin it towrite_glbat every remainder of both lengths mod 4, the format's lengths and padding, and a writer's error).samples,nordic,r2025,racadv,holdout,bimcollab,families),b0ca6303againstb979b791, with this branch's scorers (the client that pageslist_rooms): 146 of 146 export hashes and 121 of 121diagnostics.jsonequal, no scorer output moves (mcp_answers_vs_ifcincluded), thesame-project gatescheck run passes.Not measured: the peak memory of concurrent opens (the gate bounds it by design), and a crafted file with a very long name (no corpus holds one; the small-limit test exercises the same cut).
Audit-honesty checklist
docs/mcp.md, the tool contract).changelog.d/security/1883-mcp-bounds.md.list_roomsneeds a second call past 1000 spaces; an answer over 4 MiB is refused.Breaking changes
list_roomsreturns at most 1000 spaces by default (it returned every space);totalsays how many there are. Alimitof 0 or over 1000 is an error where it was changed quietly. Measure's scorer is updated for both, and it pageslist_rooms.