Skip to content

fix: send pairing secret in JSON body because pyRevit Routes hides headers - #72

Open
DavidPinto123 wants to merge 1 commit into
mcp-servers-for-revit:masterfrom
DavidPinto123:fix/pairing-token-in-body
Open

DavidPinto123 wants to merge 1 commit into
mcp-servers-for-revit:masterfrom
DavidPinto123:fix/pairing-token-in-body

Conversation

@DavidPinto123

Copy link
Copy Markdown

Problem

With pyRevit 7.0 (Revit 2026.5), every bridge route returns 401 "Bridge is disconnected or pairing is invalid." even right after MCP > Bridge > Connect. pyRevit's server.py::_prepare_request builds base.Request without ever calling add_header, so request.headers is always {} inside a route handler and the Authorization: Bearer header sent by main.py never reaches validate_request.

Fix

  • revit_mcp/pairing.py: new AUTH_FIELD = "revit_mcp_auth" and authorization_body(data). validate_request(headers, body_token=None) checks the Authorization header first when one is visible (Origin still rejected), and otherwise the body token. Comparison is still constant time.
  • revit_mcp/security.py: authorize_request pops the token from request.data (it parses a JSON string body if needed) before the callbackUrl check, the route logic and the Revit review prompt, so the secret is never shown in the review dialog or passed to route code.
  • main.py: revit_get, revit_post and revit_image send json=authorization_body(...), GET included. The secret never goes in the URL.
  • Integration conftest.py uses the same body mechanism.
  • SECURITY.md, README.md and LLM.txt describe the new transport. With pyRevit 7.0 the bridge cannot see Origin, so browser protection relies on the secret plus the CORS preflight a cross-origin application/json body needs, which pyRevit does not grant.

The optional SSE/streamable-HTTP transports (PairingMiddleware) are unchanged and still use the header.

Testing

  • uv run --frozen --extra test python -m pytest tests/unit -q: 110 passed. New tests cover the body token, header precedence, stripping the secret before review, and the client body.
  • scripts/export_mcp_manifest.py --check: OK.
  • Against a live Revit 2026.5 + pyRevit 7.0 (IronPython 3.4):
    • revit_get('/status/') → 200 healthy
    • /model_info/ → 200
    • no token → 401, wrong token → 401

🤖 Generated with Claude Code

…aders

pyRevit 7.0 never copies HTTP headers into the route Request object, so
request.headers is always empty and every bridge route returned 401 even
for a paired client.

The client now sends the secret in the `revit_mcp_auth` field of a JSON
body (GET included). authorize_request pops it from request.data before
the callbackUrl check, the route logic and the Revit review prompt. An
Authorization header still wins when a pyRevit version exposes headers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
karlipegomes added a commit to buzfam/mcp-server-for-revit-python that referenced this pull request Oct 21, 2026
…aders

pyRevit Routes 6.x/7.0 never copies HTTP headers into request.headers
(pyRevit #3765), so every bridge route answered 401 even after pairing.
Ported from upstream PR mcp-servers-for-revit#72, keeping the popped token on the request so
routes that authorize twice (bulk_set_parameters) still pass.
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