Repository navigation
fix: send pairing secret in JSON body because pyRevit Routes hides headers - #72
Open
DavidPinto123 wants to merge 1 commit into
Open
DavidPinto123 wants to merge 1 commit into
DavidPinto123 wants to merge 1 commit into
Conversation
…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.
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.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_requestbuildsbase.Requestwithout ever callingadd_header, sorequest.headersis always{}inside a route handler and theAuthorization: Bearerheader sent bymain.pynever reachesvalidate_request.Fix
revit_mcp/pairing.py: newAUTH_FIELD = "revit_mcp_auth"andauthorization_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_requestpops the token fromrequest.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_postandrevit_imagesendjson=authorization_body(...), GET included. The secret never goes in the URL.conftest.pyuses the same body mechanism.SECURITY.md,README.mdandLLM.txtdescribe the new transport. With pyRevit 7.0 the bridge cannot seeOrigin, so browser protection relies on the secret plus the CORS preflight a cross-originapplication/jsonbody 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.revit_get('/status/')→ 200healthy/model_info/→ 200🤖 Generated with Claude Code