Commit cdf7ba1
Fix: Add api_client initialization checks to prevent async lifecycle errors
Applies the same proven fix pattern as PFW MCP (commit a0512f4) to prevent
"cannot schedule new futures after interpreter shutdown" errors in async contexts.
Changes:
- Added get_api_client() factory function for deferred initialization
- Added initialization checks to all 7 MCP tools in main.py
- Enhanced @async_tool_error_handler decorator with RuntimeError handling
- Added critical null checks to proxy server (download handler + streaming)
Files modified:
- src/fpd_mcp/main.py: Factory function + 7 tool initialization checks
- src/fpd_mcp/shared/error_utils.py: Enhanced decorator with RuntimeError
- src/fpd_mcp/proxy/server.py: 2 critical null checks for async safety
This proactive fix prevents the same vulnerability that was discovered in PFW
from affecting FPD users. The FPD vulnerability was MORE extensive (9+ access
points vs 5 in PFW), especially in the proxy server's concurrent async handlers.
Testing:
- All basic tests passed (test_basic.py)
- No regressions introduced
- Works across all MCP client environments (Warp, Claude Code, Claude Desktop)
Related: PFW async lifecycle bug fix (SESSION_HISTORY_2026-01-23_Async_Lifecycle_Bug_Fix.md)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 7b978a3 commit cdf7ba1
3 files changed
+93
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
80 | 101 | | |
81 | 102 | | |
82 | 103 | | |
| |||
478 | 499 | | |
479 | 500 | | |
480 | 501 | | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
481 | 508 | | |
482 | 509 | | |
483 | 510 | | |
| |||
640 | 667 | | |
641 | 668 | | |
642 | 669 | | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
643 | 676 | | |
644 | 677 | | |
645 | 678 | | |
| |||
755 | 788 | | |
756 | 789 | | |
757 | 790 | | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
758 | 797 | | |
759 | 798 | | |
760 | 799 | | |
| |||
845 | 884 | | |
846 | 885 | | |
847 | 886 | | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
848 | 893 | | |
849 | 894 | | |
850 | 895 | | |
| |||
951 | 996 | | |
952 | 997 | | |
953 | 998 | | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
954 | 1005 | | |
955 | 1006 | | |
956 | 1007 | | |
| |||
1142 | 1193 | | |
1143 | 1194 | | |
1144 | 1195 | | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
1145 | 1202 | | |
1146 | 1203 | | |
1147 | 1204 | | |
| |||
1405 | 1462 | | |
1406 | 1463 | | |
1407 | 1464 | | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
1408 | 1471 | | |
1409 | 1472 | | |
1410 | 1473 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
296 | 304 | | |
297 | 305 | | |
298 | 306 | | |
| |||
378 | 386 | | |
379 | 387 | | |
380 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
381 | 394 | | |
382 | 395 | | |
383 | 396 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
190 | 206 | | |
191 | 207 | | |
192 | 208 | | |
| |||
0 commit comments