Skip to content

fix: accept pairing token via query param for pyRevit 7 routes - #89

Open
tinyspacesshop-hash wants to merge 1 commit into
mcp-servers-for-revit:masterfrom
tinyspacesshop-hash:fix/pyrevit7-pairing-headers
Open

tinyspacesshop-hash wants to merge 1 commit into
mcp-servers-for-revit:masterfrom
tinyspacesshop-hash:fix/pyrevit7-pairing-headers

Conversation

@tinyspacesshop-hash

Copy link
Copy Markdown

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 Request without HTTP headers. In pyrevitlib/pyrevit/routes/server/server.py, _prepare_request passes path, method, data, params and query_params to base.Request, but never copies self.headers in, so request.headers is always {}. That means the Authorization: Bearer … header sent by main.py never reaches authorize_request. The existing unit tests passed because they build requests with SimpleNamespace(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: adds PAIRING_QUERY_PARAM = "revit_mcp_pairing", bridge_query_params() (client side) and bridge_request_headers(headers, query_params). The latter uses a real Authorization header when one arrives, and otherwise builds it from the query parameter.
  • revit_mcp/security.py: authorize_request validates the merged headers.
  • main.py and tests/integration/conftest.py: bridge clients send params=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 Origin header 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.py docstring to say so.

Testing

  • New unit test test_route_accepts_pairing_query_param_when_pyrevit_drops_headers reproduces pyRevit's empty headers.
  • uv run --frozen --extra test python -m pytest tests/unit -q: 107 passed.
  • Live on Revit 2026.4 / pyRevit 7.0.0 after a pyRevit reload: GET /revit_mcp/status/ returns 401 without the token and 200 with it ("health": "healthy").

🤖 Generated with Claude Code

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