Skip to content

Unpaired requests return a misleading 408 (uncaught IOError in IronPython) instead of 401 #70

Open

Description

@ovrvzz

What happens

After updating to 14208da (PR #68, local pairing), every revit_mcp route returns HTTP 408 instantly if no pairing secret exists yet. The 401 "Bridge is disconnected or pairing is invalid." is never returned. A 408 looks like a Revit/ExternalEvent timeout, so users chase the wrong problem (closing dialogs, pressing Esc, restarting Revit).

Steps to reproduce

  1. Revit 2026.4 + pyRevit 6.5.5 (IronPython 2.7.12), Routes server enabled.
  2. Install or update the extension, but don't click MCP > Bridge > Connect yet (so %LOCALAPPDATA%\RevitMCPPython\pairing.dpapi doesn't exist).
  3. curl -i http://127.0.0.1:48884/revit_mcp/status/

Expected: 401 with "Bridge is disconnected or pairing is invalid."
Actual: 408 in ~10 ms, with this body (shortened):

IOError: [Errno 2] Could not find a part of the path '...\RevitMCPPython\pairing.dpapi'
  File "revit_mcp\status.py", line 24, in revit_status
  File "revit_mcp\security.py", line 15, in authorize_request
  File "revit_mcp\pairing.py", line 111, in validate_request
  File "revit_mcp\pairing.py", line 91, in get_token

Cause

In Python 2 / IronPython, IOError is not a subclass of OSError; both inherit from EnvironmentError. So in revit_mcp/pairing.py:96

except (OSError, ValueError, PairingError):

doesn't catch the IOError raised by open() on line 91. The exception escapes validate_request (which catches only PairingError, line 112) and the route handler, and pyRevit reports it as a 408.

The same pattern appears in MCP.tab/Bridge.panel/Connect.pushbutton/script.py:28 and Disconnect.pushbutton/script.py:14: except (PairingError, OSError) misses an IOError from open()/os.remove() under IronPython, so a failed write shows a raw pyRevit error instead of the friendly alert. The CPython side (where IOError is OSError) isn't affected, which is probably why the unit tests pass.

Suggested fix

Catch EnvironmentError (the parent of both on Python 2; an alias of OSError on Python 3), e.g.:

except (EnvironmentError, ValueError, PairingError):

Apply it in pairing.get_token and in the Connect and Disconnect button scripts. Optionally, also make validate_request treat any exception from get_token() as "not paired", so the route can never leak a traceback instead of returning 401.

Environment

  • Extension commit 14208da
  • pyRevit 6.5.5.26237, IronPython 2.7.12 (engine 2712)
  • Revit 2026.4 (26.4.0.32), Windows 11

Activity

  1. ovrvzz commented on Oct 14, 2026

    @ovrvzz
    Author

    Follow-up: pairing can't succeed under pyRevit at all

    After pairing successfully (MCP > Bridge > Connect → "Paired.", pairing.dpapi created), every request still gets 401 "Bridge is disconnected or pairing is invalid.", even though main.py sends the correct Authorization: Bearer ... header.

    Cause: pyRevit's routes server never passes HTTP headers to route handlers. request.headers is always {} (pyRevit 6.5.5, and also on develop/7.0.0). validate_request(request.headers) therefore never sees the Authorization header, so the check always fails.

    The unit tests pass because they hand validate_request a headers dict directly. That path never happens inside Revit.

    Reported upstream: pyrevitlabs/pyRevit#3765, with a ~3-line fix in routes/server/server.py::_prepare_request. With that patch applied locally, the headers arrive.

    Suggestions for this repo until pyRevit ships a fix:

    • Note the minimum pyRevit version (or this limitation) in the README.
    • Or have get_revit_status / the 401 response say that the bearer header wasn't received at all (empty headers), as opposed to a wrong token, so users don't keep re-pairing.
  2. jinye005 commented on Oct 14, 2026

    @jinye005

    Reproduced on pyRevit 7.0.0.26278 (IronPython 2.7.12) / Revit 2026.4 before pairing: missing pairing.dpapi → uncaught IOError → 408 with traceback. Catching EnvironmentError (or (IOError, OSError)) in get_token() would fix it.

    Separately, after pairing, all requests still returned 401 because pyRevit 7.0's Routes server does not forward HTTP headers — filed as #71.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions