Repository navigation
Conversation
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>
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.
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 theRequestwithout copying the incoming HTTP headers, sorequest.headersis always{}.pairing.validate_requesttherefore never sees theAuthorizationbearer token, and theOrigincheck never sees browser requests either.Fix
revit_mcp/routes_compat.py: wraps the handler's_prepare_requestto copy the HTTP headers onto theRequestwhen pyRevit hasn't (a no-op on versions that already pass them; installs once).startup.pysubscribes toUIApplication.Idlingand patches the live server'sRequestHandlerClass(looked up via theROUTES_SERVERenv 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.get_revit_model_infowent from 401 to success after reload.🤖 Generated with Claude Code