Skip to content

Commit 0ef91d2

Browse files
authored
Merge pull request modelcontextprotocol#754 from cmgriffing/cmgriffing/fix-cli-truncated-output
Make cli output awaitable to prevent truncating the result
2 parents 5ca3aab + d3fcedc commit 0ef91d2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

cli/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
} from "./client/index.js";
2020
import { handleError } from "./error-handler.js";
2121
import { createTransport, TransportOptions } from "./transport.js";
22+
import { awaitableLog } from "./utils/awaitable-log.js";
2223

2324
// JSON value type for CLI arguments
2425
type JsonValue =
@@ -167,7 +168,7 @@ async function callMethod(args: Args): Promise<void> {
167168
);
168169
}
169170

170-
console.log(JSON.stringify(result, null, 2));
171+
await awaitableLog(JSON.stringify(result, null, 2));
171172
} finally {
172173
try {
173174
await disconnect(transport);

cli/src/utils/awaitable-log.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function awaitableLog(logValue: string): Promise<void> {
2+
return new Promise<void>((resolve) => {
3+
process.stdout.write(logValue, () => {
4+
resolve();
5+
});
6+
});
7+
}

0 commit comments

Comments
 (0)