Skip to content

fix: forward HTTP headers to pyRevit route requests - #74

Open
robotroth-debug wants to merge 1 commit into
mcp-servers-for-revit:masterfrom
robotroth-debug:fix/forward-route-request-headers
Open

robotroth-debug wants to merge 1 commit into
mcp-servers-for-revit:masterfrom
robotroth-debug:fix/forward-route-request-headers

Conversation

@robotroth-debug

Copy link
Copy Markdown

Problem

After pairing with MCP > Bridge > Connect, every bridge request still fails with:

401 - {"error": "Bridge is disconnected or pairing is invalid."}

pyRevit's Routes server builds the Request passed to route handlers without copying the incoming HTTP headers. HttpRequestHandler._prepare_request only fills in path, method, body, route params and query params; nothing calls Request.add_header. So request.headers is always {}, validate_request() never sees the Authorization header, and pairing auth can't succeed. The same code is on pyRevit's current develop branch.

Fix

At extension startup, startup.py wraps HttpRequestHandler._prepare_request to copy self.headers onto 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:

  • Before: /status/ returns 401 even with a valid pairing file that Revit can decrypt. A temporary diagnostic confirmed request.headers was empty.
  • After a pyRevit reload: /status/ returns 200 / healthy, and list_levels returns 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

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>
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