Repository navigation
fix: make Revit pairing work on .NET 8+ (Revit 2025+) - #91
Open
protocolx30 wants to merge 1 commit into
Open
protocolx30 wants to merge 1 commit into
protocolx30 wants to merge 1 commit into
Conversation
On Revit 2025+ (IronPython on .NET 8/10), System.Security.Cryptography. ProtectedData is not available, so MCP > Bridge > Connect raised an uncaught import error and no pairing secret was ever written. - Fall back to the existing crypt32 ctypes DPAPI path when ProtectedData cannot be loaded; it produces the same CurrentUser blob the CPython MCP server already reads. - Catch unexpected errors in get_token/validate_request so they deny the request instead of escaping into pyRevit's route thread, and record the traceback (never the token) in pairing_error.log. Tested on Revit 2027.3 with pyRevit 6.5: Connect pairs, and get_revit_status / list_levels succeed. Note pyRevit 6.5 itself also needs request headers passed through to route handlers for the bearer check to succeed; that is a separate pyRevit-side issue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
Correction to the "pyRevit 6.5 issues" section of the description: both are already reported and fixed upstream in pyRevit.
So on pyRevit 7.x neither problem needs a local workaround. A note in the README recommending pyRevit 7.0.1 or later, or 7.1.0 for both fixes, might save other users the same debugging. This PR is still needed on pyRevit 7: |
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.
Summary
On Revit 2025+ (IronPython running on .NET 8 or later — Revit 2027.3 reports .NET 10), MCP > Bridge > Connect never pairs.
revit_mcp/pairing.pyimportsSystem.Security.Cryptography.ProtectedData, which is not part of the .NET 8+ runtime and is not shipped by Revit 2027 or pyRevit. The import raises an uncaught exception, pyRevit shows its error window, and nopairing.dpapifile is written — so every MCP request is denied.Changes (
revit_mcp/pairing.pyonly)ProtectedDatacannot be loaded under IronPython, fall through to the existingcrypt32ctypes path. It uses the sameCurrentUserscope with no entropy, so it produces the same blob the CPython MCP server already reads.get_token()andvalidate_request()now catch unexpected exceptions, deny the request, and append the traceback (never the token) to%LOCALAPPDATA%\RevitMCPPython\pairing_error.log. An exception escaping a pyRevit route can take Revit down (see below), so failing closed is safer than raising.Testing
get_revit_statusandlist_levelsreturn model data through the MCP server (stdio).authorization_headers()→validate_request()accepts the valid token, rejects a wrong token, and rejects requests carrying anOriginheader.Reviewer notes: pyRevit 6.5 issues outside this repo
While testing I hit two problems in pyRevit's own Routes server (
pyrevitlib/pyrevit/routes/server/server.py). They are not fixed by this PR, but they block the bridge on stock pyRevit 6.5:_prepare_request()buildsbase.Request(...)without callingadd_header, sorequest.headersis always{}andauthorize_request()always returns 401. Working around it locally meant copyingself.headersonto the request.sys.stderr(for examplelog_messageor an unhandled thread exception). pyRevit then creates its output window on a non-STA thread and .NET terminates Revit (InvalidOperationException: The calling thread must be STA). Working around it locally meant routinglog_message/handle_errorto a file.It may be worth documenting a minimum pyRevit version, or a known-issues note, until these are fixed upstream in pyRevit.
🤖 Generated with Claude Code