Skip to content

fix: pass HTTP headers to routes on pyRevit 7 - #80

Open
aldo0308 wants to merge 1 commit into
mcp-servers-for-revit:masterfrom
aldo0308:fix/pyrevit7-request-headers
Open

aldo0308 wants to merge 1 commit into
mcp-servers-for-revit:masterfrom
aldo0308:fix/pyrevit7-request-headers

Conversation

@aldo0308

Copy link
Copy Markdown

Problem

On pyRevit 7.0 every bridge call returns 401 - Bridge is disconnected or pairing is invalid., even with a valid pairing.

pyRevit 7's HttpRequestHandler._prepare_request (pyrevitlib/pyrevit/routes/server/server.py) builds the Request without copying the incoming HTTP headers, so request.headers is always {}. pairing.validate_request therefore never sees the Authorization bearer token, and the Origin check never sees browser requests either.

Fix

  • revit_mcp/routes_compat.py: wraps the handler's _prepare_request to copy the HTTP headers onto the Request when pyRevit hasn't (a no-op on versions that already pass them; installs once).
  • pyRevit starts the Routes server only after extension startup scripts run, so startup.py subscribes to UIApplication.Idling and patches the live server's RequestHandlerClass (looked up via the ROUTES_SERVER env var) on the first idle after it exists, then unsubscribes. It gives up after 500 idles if no server starts (e.g. Routes disabled).

Testing

  • tests/unit/test_routes_compat.py: header copying, preserving headers pyRevit already set, idempotency, deferred install/unsubscribe, give-up path. Full unit suite: 111 passed.
  • Manually verified on Revit 2024.3 + pyRevit 7.0.0.26278: get_revit_model_info went from 401 to success after reload.

🤖 Generated with Claude Code

pyRevit 7.0 builds the route Request without copying the incoming HTTP
headers, so pairing authentication always failed with 401 and the Origin
check never saw browser requests. Patch the live Routes server's handler
class on Revit's first idle after load (the server starts after extension
startup scripts) so requests carry their headers.

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