Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mcp-doctor-race.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'incur': patch
---

Fixed an intermittent `mcp doctor` failure where the tools/list response could be missed under load.
1 change: 1 addition & 0 deletions src/Cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function mockMcpServeResponses(responses: unknown[]) {
options!.output?.write(
`${typeof response === 'string' ? response : JSON.stringify(response)}\n`,
)
options!.output?.end()
})
}

Expand Down
15 changes: 13 additions & 2 deletions src/Cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2740,7 +2740,6 @@ async function runMcpDoctor(
const input = new PassThrough()
const output = new PassThrough()
const chunks: string[] = []
output.on('data', (chunk) => chunks.push(chunk.toString()))

let serveError: unknown
const done = Mcp.serve(name, options.version ?? '0.0.0', commands, {
Expand Down Expand Up @@ -2768,7 +2767,19 @@ async function runMcpDoctor(
})}\n`,
)
input.write(`${Json.stringify({ jsonrpc: '2.0', id: 2, method: 'tools/list', params: {} })}\n`)
await new Promise((resolve) => setTimeout(resolve, 20))
await new Promise<void>((resolve) => {
let lines = 0
output.on('data', (chunk) => {
const text = chunk.toString()
chunks.push(text)
lines += text.split('\n').length - 1
if (lines >= 2) resolve()
})
output.once('end', resolve)
done.then(() => {
if (serveError !== undefined) resolve()
})
})
input.end()
await done

Expand Down
Loading