Commit 7093e56
Limucc's v2.2.4 test on Windows 11 / Python 3.14 confirmed that the
WindowsSelectorEventLoopPolicy fix from v2.2.4 was *necessary but
not sufficient* — read-only tools work, but long-running tools still
hang indefinitely over stdio MCP:
build_or_update_graph_tool(full_rebuild=True) → hangs
embed_graph_tool (sentence-transformers) → hangs
Root cause: FastMCP 2.x dispatches sync handlers inline on the only
event-loop thread. When a handler runs for more than a few seconds —
especially one that spawns child processes (full_build uses
ProcessPoolExecutor) or does CPU-bound inference (sentence-transformers)
— the loop stops pumping stdin/stdout, Claude Code's request never
gets a response, and the MCP client shows "Synthesizing…" forever.
Fix: make the five heavy tool handlers ``async def`` and offload the
blocking work with ``asyncio.to_thread``. The event loop stays
responsive and the stdio transport keeps pumping. This is a no-op
for short tools, zero-config, and works on every platform.
Tools converted to async + asyncio.to_thread:
- build_or_update_graph_tool (full_build / incremental_update)
- run_postprocess_tool (community detection can be slow)
- embed_graph_tool (sentence-transformers inference)
- detect_changes_tool (git diff + BFS traversal)
- generate_wiki_tool (many SQLite reads + file writes)
The other 19 tools are fast SQLite-read paths and stay sync.
Tests: tests/test_main.py::TestLongRunningToolsAreAsync
- Asserts all 5 tools are registered as coroutines via FastMCP's
get_tools() introspection
- Defense-in-depth: asserts each tool's source literally contains
"asyncio.to_thread" so we don't accidentally make a tool async
without offloading the blocking work
Verified locally on Python 3.11 / macOS:
- ruff clean, mypy clean, bandit clean
- 737 tests pass (+2 new async lock-in tests), coverage 74.63%
- mcp.get_tools() returns 24 tools with the 5 above as coroutines
Windows verification requested from @dev-limucc on #136 once v2.3.1
ships.
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e366db8 commit 7093e56
2 files changed
Lines changed: 121 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
80 | | - | |
| 81 | + | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| |||
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
93 | 101 | | |
94 | 102 | | |
95 | 103 | | |
| |||
99 | 107 | | |
100 | 108 | | |
101 | 109 | | |
102 | | - | |
103 | | - | |
104 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
105 | 117 | | |
106 | 118 | | |
107 | 119 | | |
108 | 120 | | |
109 | | - | |
| 121 | + | |
110 | 122 | | |
111 | 123 | | |
112 | 124 | | |
| |||
117 | 129 | | |
118 | 130 | | |
119 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
120 | 136 | | |
121 | 137 | | |
122 | 138 | | |
123 | 139 | | |
124 | 140 | | |
125 | 141 | | |
126 | | - | |
127 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
128 | 146 | | |
129 | 147 | | |
130 | 148 | | |
| |||
273 | 291 | | |
274 | 292 | | |
275 | 293 | | |
276 | | - | |
| 294 | + | |
277 | 295 | | |
278 | 296 | | |
279 | 297 | | |
| |||
287 | 305 | | |
288 | 306 | | |
289 | 307 | | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
290 | 313 | | |
291 | 314 | | |
292 | 315 | | |
293 | 316 | | |
294 | 317 | | |
295 | | - | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
296 | 323 | | |
297 | 324 | | |
298 | 325 | | |
| |||
501 | 528 | | |
502 | 529 | | |
503 | 530 | | |
504 | | - | |
| 531 | + | |
505 | 532 | | |
506 | 533 | | |
507 | 534 | | |
| |||
515 | 542 | | |
516 | 543 | | |
517 | 544 | | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
518 | 549 | | |
519 | 550 | | |
520 | 551 | | |
| |||
524 | 555 | | |
525 | 556 | | |
526 | 557 | | |
527 | | - | |
| 558 | + | |
| 559 | + | |
528 | 560 | | |
529 | 561 | | |
530 | 562 | | |
| |||
598 | 630 | | |
599 | 631 | | |
600 | 632 | | |
601 | | - | |
| 633 | + | |
602 | 634 | | |
603 | 635 | | |
604 | 636 | | |
| |||
608 | 640 | | |
609 | 641 | | |
610 | 642 | | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
611 | 647 | | |
612 | 648 | | |
613 | 649 | | |
614 | 650 | | |
615 | | - | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
616 | 656 | | |
617 | 657 | | |
618 | 658 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
| |||
43 | 46 | | |
44 | 47 | | |
45 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
0 commit comments