Skip to content

Answer the save prompt in close_document instead of hanging - #67

Merged
jmcouffin merged 2 commits into
mcp-servers-for-revit:masterfrom
hjazazzi:fix/close-document-save-prompt
Oct 14, 2026
Merged

jmcouffin merged 2 commits into
mcp-servers-for-revit:masterfrom
hjazazzi:fix/close-document-save-prompt

Conversation

@hjazazzi

@hjazazzi hjazazzi commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Problem

close_document closes the active document by posting the Close command. If the document has unsaved changes, Revit then shows the "Save File" prompt (TaskDialog_Save_File). Nothing answers it from an API call, so it blocks Revit's UI thread. Every later MCP call that needs the API context times out until someone clicks the dialog by hand. This happens even with save=False, which is meant to discard changes.

Fix

  • When the document is modified, close_document attaches a one-shot DialogBoxShowing handler before posting Close. It answers only TaskDialog_Save_File, with No, and then detaches.
  • It gives up after 60 s without answering, so it never touches a save prompt from a close the user starts in the UI. If PostCommand fails, the handler is removed straight away.
  • The response says when changes were discarded (discarded_changes).
  • With save=True, a failed save now returns a 500 and leaves the document open. Before, it logged a warning and closed anyway, which discarded the work.

Workshared-close prompts (sync / relinquish) are deliberately not handled.

Testing

Revit 2027.3, Snowdon Towers HVAC sample:

Case Result
Modified doc, save=False Closes, no prompt left open, API stays responsive
Then a manual-style close of a modified doc Save prompt appears normally (handler had detached)
Unmodified doc Closes, no handler attached

🤖 Generated with Claude Code

close_document posts the Close command. On a modified document Revit
then shows TaskDialog_Save_File, which nothing answers from an API call:
it blocks the UI thread and every later MCP call times out.

When the document has unsaved changes, attach a one-shot DialogBoxShowing
handler that answers that prompt with No, then detaches. It only matches
TaskDialog_Save_File and gives up after 60 s, so prompts from closes the
user starts are left alone. The response now reports discarded changes.

With save=True, a failed save now returns an error and leaves the
document open, instead of closing and discarding the work.

Tested on Revit 2027 with a sample model: modified close, unmodified
close, and a later user-style close still shows the prompt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jmcouffin
jmcouffin merged commit e7d0737 into mcp-servers-for-revit:master Oct 14, 2026
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.

2 participants