Repository navigation
fix: forward HTTP headers to pyRevit route requests - #74
Open
robotroth-debug wants to merge 1 commit into
Open
robotroth-debug wants to merge 1 commit into
robotroth-debug wants to merge 1 commit into
Conversation
pyRevit's Routes server builds Request objects without copying the incoming HTTP headers, so request.headers is always empty and pairing authentication rejects every call with 401, even when paired. Wrap HttpRequestHandler._prepare_request at startup to copy the headers onto the request. The running Routes server survives pyRevit reloads with its original handler class, so patch that class too, re-wrapping pyRevit's original method so a reload installs the current wrapper. 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
After pairing with MCP > Bridge > Connect, every bridge request still fails with:
pyRevit's Routes server builds the
Requestpassed to route handlers without copying the incoming HTTP headers.HttpRequestHandler._prepare_requestonly fills in path, method, body, route params and query params; nothing callsRequest.add_header. Sorequest.headersis always{},validate_request()never sees theAuthorizationheader, and pairing auth can't succeed. The same code is on pyRevit's currentdevelopbranch.Fix
At extension startup,
startup.pywrapsHttpRequestHandler._prepare_requestto copyself.headersonto the returned request.pyRevit keeps the running Routes server alive across pyRevit > Reload, and that server still uses the handler class from the original module import. So the patch also targets the live server's
RequestHandlerClass. Each reload re-wraps pyRevit's original method, so the current wrapper always takes effect and wrappers don't stack.pyRevit itself isn't modified. This could later be fixed upstream in pyRevit, and the wrapper would then be redundant but harmless.
Testing
Revit 2025.5, pyRevit 7.0.0 (IronPython 2.7.12 on .NET 10), Windows 11:
/status/returns 401 even with a valid pairing file that Revit can decrypt. A temporary diagnostic confirmedrequest.headerswas empty./status/returns 200 /healthy, andlist_levelsreturns correct data through the stdio MCP server (uv run --frozen mcp run main.py).Separately, simultaneous MCP tool calls can come back with each other's results, because pyRevit's Routes server handles Revit-side requests through one shared handler object. That isn't addressed here.
🤖 Generated with Claude Code