Repository navigation
fix: accept pairing token via query param for pyRevit 7 routes - #89
Open
tinyspacesshop-hash wants to merge 1 commit into
Open
tinyspacesshop-hash wants to merge 1 commit into
tinyspacesshop-hash wants to merge 1 commit into
Conversation
pyRevit 7's routes server builds each Request with empty headers, so the Authorization bearer token never reached authorize_request and every bridge call returned 401 "Bridge is disconnected or pairing is invalid", even right after MCP > Bridge > Connect. Bridge clients now also send the token as the revit_mcp_pairing query parameter, which pyRevit passes through. The Revit side uses a real Authorization header when one arrives, and otherwise falls back to that parameter. Wrong, rotated and repeated tokens are still rejected, and an Origin header still blocks the request. Verified against Revit 2026.4 with pyRevit 7.0.0: /status/ returns 401 without the token and 200 with it. 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
With pyRevit 7 (tested on 7.0.0.26278+2233 with Revit 2026.4), every bridge call returns
401 {"error": "Bridge is disconnected or pairing is invalid."}, even right after MCP > Bridge > Connect and a pyRevit reload.The cause: pyRevit's routes server builds each
Requestwithout HTTP headers. Inpyrevitlib/pyrevit/routes/server/server.py,_prepare_requestpassespath,method,data,paramsandquery_paramstobase.Request, but never copiesself.headersin, sorequest.headersis always{}. That means theAuthorization: Bearer …header sent bymain.pynever reachesauthorize_request. The existing unit tests passed because they build requests withSimpleNamespace(headers=…), which pyRevit itself never does.Fix
pyRevit does pass the query string through, so the token now also travels there:
revit_mcp/pairing.py: addsPAIRING_QUERY_PARAM = "revit_mcp_pairing",bridge_query_params()(client side) andbridge_request_headers(headers, query_params). The latter uses a realAuthorizationheader when one arrives, and otherwise builds it from the query parameter.revit_mcp/security.py:authorize_requestvalidates the merged headers.main.pyandtests/integration/conftest.py: bridge clients sendparams=bridge_query_params()alongside the existing header.README.md: documents the query parameter.Unchanged: a wrong, rotated or repeated (list-valued) token is still rejected, an
Originheader still blocks the request, and the MCP HTTP transports (tools/http_security.py) still require the real header.Trade-off: the token now appears in the bridge request URL. These requests stay on loopback, but the URL can show up in pyRevit's debug-level request log. I updated the
pairing.pydocstring to say so.Testing
test_route_accepts_pairing_query_param_when_pyrevit_drops_headersreproduces pyRevit's empty headers.uv run --frozen --extra test python -m pytest tests/unit -q: 107 passed.GET /revit_mcp/status/returns 401 without the token and 200 with it ("health": "healthy").🤖 Generated with Claude Code