Commit 6c5a467
committed
Fix MCP stdio protocol violation during startup
The MCP protocol requires the client to send the first message. Writing
to stdout before the client's initialization request breaks the protocol
handshake, causing 'BrokenResourceError' in clients like langchain-mcp-adapters.
Root cause: Transport was created AFTER config/feature flags initialization,
so logger.* calls during startup wrote directly to stdout (bypassing buffering)
or called sendLog() which also wrote to stdout without checking isInitialized.
Additional issue: Async feature flag fetch operations would log messages
AFTER the client had already started closing, causing timing conflicts.
Fixes:
1. Move FilteredStdioServerTransport creation before config loading
2. Buffer sendLog() messages when isInitialized is false
3. Guard sendProgress/sendCustomNotification when not initialized
4. Add .unref() to feature flag refresh interval for clean process exit
5. Remove async logging from feature flag fetch/save operations
Tested with langchain-mcp-adapters - now passes where it previously failed.
Fixes #issue-reported-by-ever10221 parent d3f5824 commit 6c5a467
3 files changed
+37
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
| 280 | + | |
280 | 281 | | |
281 | 282 | | |
282 | 283 | | |
283 | 284 | | |
284 | 285 | | |
285 | 286 | | |
286 | 287 | | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
287 | 299 | | |
288 | 300 | | |
289 | 301 | | |
| |||
315 | 327 | | |
316 | 328 | | |
317 | 329 | | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
318 | 335 | | |
319 | 336 | | |
320 | 337 | | |
| |||
346 | 363 | | |
347 | 364 | | |
348 | 365 | | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
349 | 371 | | |
350 | 372 | | |
351 | 373 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
42 | 49 | | |
43 | 50 | | |
44 | 51 | | |
| |||
56 | 63 | | |
57 | 64 | | |
58 | 65 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
49 | 53 | | |
50 | 54 | | |
51 | 55 | | |
| |||
107 | 111 | | |
108 | 112 | | |
109 | 113 | | |
110 | | - | |
| 114 | + | |
111 | 115 | | |
112 | 116 | | |
113 | 117 | | |
| |||
132 | 136 | | |
133 | 137 | | |
134 | 138 | | |
135 | | - | |
| 139 | + | |
| 140 | + | |
136 | 141 | | |
137 | | - | |
138 | | - | |
139 | 142 | | |
140 | 143 | | |
141 | 144 | | |
| |||
154 | 157 | | |
155 | 158 | | |
156 | 159 | | |
157 | | - | |
| 160 | + | |
158 | 161 | | |
159 | 162 | | |
160 | 163 | | |
| |||
0 commit comments