Skip to content

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
DrunkOnJava merged 6 commits into
mainfrom
fix/1883-mcp-bounds
Nov 13, 2026

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

rvt-rs-mcp bounds 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_rooms is paged and a limit outside 1 to 1000 is an error.

Motivation

Batch 5's audit of rvt-mcp found 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 in notes (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 (RevitFile holds the file; the comment in gate.rs says why the place is not held across the two).
  • list_rooms takes limit and offset and answers total, 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_elements keeps 100. The tool description says that a returned below total is a list that is not complete. A limit outside 1 to 1000 is a tool error and the schema states the range (item 8).
  • export_gltf writes the GLB from the buffer it builds with the new rvt::ifc::gltf::write_glb_to (same bytes as write_glb; a GLB over 4 GiB is an error, where its length wrapped) (item 5).
  • The progress queue holds 16 events and drops what a slow client has not read (item 7); a phase name over 256 characters is refused and the phase errors the store keeps are bounded (item 6); a file with no readable modification time is refused (item 9).
  • The tool descriptions say that names, values and messages in an answer are text from the file (item 10).
  • tools/re/mcp_client.py (Measure's MCP scorer) pages list_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.rs drives the built server over stdio:

  • tools/check-local.sh: CI's full run passed at b0ca6303 (no local builds here; rustfmt was run locally).
  • End to end on the synthetic fixture with small limits (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 covering list_rooms on every file drive runs (the fixture; Einhoven where CI has it), the 1000 default, a limit of 0, 1001 and 100,000 refused on both list tools, a 300-character phase refused, and four concurrent opens under --max-open-models 1 that all finish with one model kept (concurrent_opens_of_different_files_all_finish).
  • The exports stay byte for byte rvt-ifc's and rvt-gltf's, which the existing test compares (the glb now through write_glb_to; three pure tests in src/ifc/gltf.rs pin it to write_glb at every remainder of both lengths mod 4, the format's lengths and padding, and a writer's error).
  • Measure 43398565674, unfiltered (samples, nordic, r2025, racadv, holdout, bimcollab, families), b0ca6303 against b979b791, with this branch's scorers (the client that pages list_rooms): 146 of 146 export hashes and 121 of 121 diagnostics.json equal, no scorer output moves (mcp_answers_vs_ifc included), the same-project gates check 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 reflect this PR (docs/mcp.md, the tool contract).
  • Changelog fragment changelog.d/security/1883-mcp-bounds.md.
  • New limitations are in the fragment and the docs: list_rooms needs a second call past 1000 spaces; an answer over 4 MiB is refused.

Breaking changes

list_rooms returns at most 1000 spaces by default (it returned every space); total says how many there are. A limit of 0 or over 1000 is an error where it was changed quietly. Measure's scorer is updated for both, and it pages list_rooms.

…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.
@DrunkOnJava
DrunkOnJava marked this pull request as ready for review November 13, 2026 08:49
rvt-rs-review[bot]
rvt-rs-review Bot previously approved these changes Nov 13, 2026
…ormat's lengths and padding at every remainder, and a writer's error fails the write (#1883)
@DrunkOnJava
DrunkOnJava merged commit cdd5f5d into main Nov 13, 2026
82 checks passed
@DrunkOnJava
DrunkOnJava deleted the fix/1883-mcp-bounds branch November 13, 2026 09:41
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).
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