Skip to content

fix: pass request headers to routes on pyRevit 7 - #87

Open
rgZenith wants to merge 1 commit into
mcp-servers-for-revit:masterfrom
rgZenith:fix/pyrevit7-header-passthrough
Open

rgZenith wants to merge 1 commit into
mcp-servers-for-revit:masterfrom
rgZenith:fix/pyrevit7-header-passthrough

Conversation

@rgZenith

Copy link
Copy Markdown

Problem

On pyRevit 7.0.0 every bridge request is rejected with 401 Bridge is disconnected or pairing is invalid., even right after a successful MCP > Bridge > Connect.

pyRevit 7.0.0's HttpRequestHandler._prepare_request (pyrevit/routes/server/server.py) builds base.Request without copying the incoming HTTP headers, so request.headers is always {}. revit_mcp.pairing.validate_request never sees the Authorization header, so pairing can never succeed.

Fix

  • New revit_mcp/header_passthrough.py wraps the routes handler's _prepare_request and copies the HTTP headers onto the request only when pyRevit left them empty, so pyRevit builds that already pass headers are unaffected.
  • pyRevit stops the routes server at session start, runs extension startup scripts, and only then starts a new server, possibly in another script engine. So the handler class is patched when the extension loads, and again through the live server object (get_active_server().server.RequestHandlerClass) on Revit's first Idling event.
  • startup.py installs it after route registration; any failure is logged and never blocks route registration.
  • Token validation is unchanged. A side effect: Origin headers now actually reach the existing browser-request rejection in validate_request.

Testing

  • New tests/unit/test_header_passthrough.py (6 tests): headers copied when dropped, left alone when provided, idempotent patching, valid / browser-Origin / missing-token requests through validate_request, and patching the live server with or without one running. Full unit suite: 112 passed.
  • Manually on Revit 2025.4 + pyRevit 7.0.0 (IronPython 2.7.12): before, /status/ returned 401; after, it returns status: active, health: healthy.

Note for reviewers

After a pyRevit Reload, pyRevit 7 can leave the previous routes server listening on the same port (allow_reuse_address), and Windows may keep routing connections to that old, unpatched server. A full Revit restart clears it. This is a pyRevit issue, outside this extension, but it can look like this fix didn't work.

🤖 Generated with Claude Code

pyRevit 7.0.0 builds each routes Request without copying the incoming
HTTP headers, so request.headers is always empty. The pairing check
never sees the Authorization header and every bridge request is
rejected with 401, even after a successful Connect.

Wrap the routes handler's _prepare_request to copy the HTTP headers
onto the request when pyRevit left them empty. pyRevit stops its server
at session start and starts a new one only after extension startup
scripts run, possibly in another script engine, so the handler class is
patched at load and again through the live server on Revit's first
Idling event. Token validation is unchanged; Origin headers now reach
the existing browser check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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