Skip to content

fix: pairing token in JSON body, and serialize concurrent Revit bridge calls - #90

Open
richard1seg1nz wants to merge 2 commits into
mcp-servers-for-revit:masterfrom
richard1seg1nz:fix/pairing-token-in-body
Open

richard1seg1nz wants to merge 2 commits into
mcp-servers-for-revit:masterfrom
richard1seg1nz:fix/pairing-token-in-body

Conversation

@richard1seg1nz

@richard1seg1nz richard1seg1nz commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

  • Pairing token in body (a025383): pyRevit Routes doesn't pass HTTP headers to route handlers, so the pairing secret now also goes in the JSON body. The Authorization header is still sent for pyRevit builds that do pass it on.
  • Serialize bridge calls (a0a4b13): pyRevit Routes sends every request through one shared ExternalEvent handler (REQUEST_HNDLR in pyrevit/routes/server/server.py). When two requests overlap, the second overwrites the first's handler, so both callers get the same response. For example, get_revit_status run in parallel with get_current_view_info returned the view info. main.py now holds one asyncio.Lock around each bridge call, including image export.

Testing

  • New test_concurrent_revit_calls_do_not_share_responses fakes the shared-handler behaviour. It fails without the fix and passes with it.
  • All 112 unit tests pass.
  • Checked against a live Revit model: the two calls run in parallel now each return the right result.

Known limitation

If a request times out on the client while Revit is still running it, the lock is released and the next request can still collide. Fixing that fully means changing pyRevit Routes.

🤖 Generated with Claude Code

BIM.SEG and others added 2 commits November 24, 2026 13:38
…ders

pyRevit Routes (6.x and 7.0) builds each route Request without copying the
HTTP headers, so the Authorization bearer never reached authorize_request and
every bridge call returned 401 after pairing.

- Client sends the token both as Authorization and in a revit_mcp_auth field
  of an application/json body (GET included). A header, when pyRevit exposes
  one, stays authoritative; otherwise the body field is checked in constant
  time. Routes pop the field before the payload is used or shown for review.
- Reference both System.Security and System.Security.Cryptography.ProtectedData
  so DPAPI loads on .NET Framework Revit (2024 and older).
- Catch EnvironmentError in get_token so IronPython's IOError on a missing
  pairing file yields 401 instead of an uncaught error reported as 408.

Verified live on Revit 2025.4 / pyRevit 7.0.1: header-only 401, body token
200, wrong or missing token 401, model_info 200.

Fixes mcp-servers-for-revit#71, mcp-servers-for-revit#84, mcp-servers-for-revit#85, mcp-servers-for-revit#78, mcp-servers-for-revit#75, mcp-servers-for-revit#88, mcp-servers-for-revit#70.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…onses

pyRevit Routes dispatches every request through one shared ExternalEvent
handler, so overlapping requests overwrite each other and both callers get
the same response (e.g. get_revit_status returning current view info).
Hold a single asyncio lock around each bridge call, including image export.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@richard1seg1nz richard1seg1nz changed the title Fix/pairing token in body fix: pairing token in JSON body, and serialize concurrent Revit bridge calls Nov 24, 2026
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