MCP · Tools

MCP0004Return compact JSON from MCP tools

Report MCP tools that return indented JSON as their text: `JSON.stringify(value, replacer, indent)` with an indent, or, with nitro-mcp-toolkit or @nuxtjs/mcp-toolkit, a plain object or array, or 0.x `jsonResult(data)`, which the toolkit indents.

Why it happens

The model reads a tool's text result as tokens in its context window. Indentation adds a newline and spaces before every key and item, which carries no data: in the Quiver Portal MCP it was about a third of each answer's characters. Claude Code replaces a result over 50,000 characters with the path of a file that holds it, so padding pushes a large answer past that limit sooner.

Fix

Remove only the third argument of JSON.stringify(value, replacer, indent); keep the replacer. With nitro-mcp-toolkit or @nuxtjs/mcp-toolkit, serialize only plain data with `JSON.`stringify(data), or pass false to 0.x jsonResult(), leaving strings and MCP result envelopes unchanged.

Example

Return compact JSON

Before

export default defineMcpTool({
  handler: async () => ({
    content: [{ type: 'text', text: JSON.stringify(await listDrops(), ['id'], 2) }],
  }),
})

After

export default defineMcpTool({
  handler: async () => ({
    content: [{ type: 'text', text: JSON.stringify(await listDrops(), ['id']) }],
  }),
})

Return compact JSON from @nuxtjs/mcp-toolkit

Before

export default defineMcpTool({
  handler: async () => ({ drops: await listDrops() }),
})

After

export default defineMcpTool({
  handler: async () => JSON.stringify({ drops: await listDrops() }),
})

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm vite-doctor . --rules mcp/tools/no-indented-json-output
Copyright © 2026