Compare commits

...

2 Commits

Author SHA1 Message Date
Peter Steinberger
9e7db5ddb3 test(cli): ensure raw output not truncated 2025-12-06 01:30:30 +01:00
Kenn Costales
97aa9aea18 fix(cli): prevent string truncation in raw output
Node's util.inspect() has a default maxStringLength of 10000 characters,
causing large MCP responses to be truncated with '... N more characters'.

See: https://nodejs.org/api/util.html#utilinspectobject-options

This affects --output raw and the default output format when it falls
back to printRaw().

Fix: set maxStringLength: null to disable string truncation while
preserving depth: 2 for readable nested object summaries.

Verify (before fix shows 10000, after fix shows 15000):
  node -e "console.log('x count:', (require('util').inspect({t:'x'.repeat(15000)}, {depth:2}).match(/x/g)||[]).length)"
  node -e "console.log('x count:', (require('util').inspect({t:'x'.repeat(15000)}, {depth:2, maxStringLength:null}).match(/x/g)||[]).length)"
2025-12-06 01:30:30 +01:00
2 changed files with 26 additions and 1 deletions

View File

@ -156,5 +156,5 @@ function printRaw(raw: unknown): void {
console.log(raw.toString());
return;
}
console.log(inspect(raw, { depth: 2, breakLength: 80 }));
console.log(inspect(raw, { depth: 2, maxStringLength: null, breakLength: 80 }));
}

View File

@ -0,0 +1,25 @@
import { describe, expect, it, vi } from 'vitest';
import { printCallOutput } from '../src/cli/output-utils.js';
describe('printCallOutput raw output', () => {
it('does not truncate long strings when printing raw output', () => {
const longText = 'x'.repeat(15000);
const log = vi.spyOn(console, 'log').mockImplementation(() => {});
const wrapped = {
json: () => null,
markdown: () => null,
text: () => null,
};
try {
printCallOutput(wrapped as any, { t: longText }, 'raw');
expect(log).toHaveBeenCalledTimes(1);
const logged = log.mock.calls[0][0] as string;
expect(logged).not.toContain('... 5000 more characters');
expect(logged).toContain(longText.slice(-50));
} finally {
log.mockRestore();
}
});
});