Skip to content

Return compact JSON from MCP tool and resource responses - #257

Merged
yummybomb merged 2 commits into
mainfrom
hypeship/compact-json-responses
Oct 19, 2026
Merged

yummybomb merged 2 commits into
mainfrom
hypeship/compact-json-responses

Conversation

@yummybomb

@yummybomb yummybomb commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

MCP tool and resource responses were pretty-printed with JSON.stringify(value, null, 2). The indentation adds nothing for models, and agent harnesses truncate MCP results at fixed limits (pi: 20 KB, Claude Code: 25k tokens, Codex: 10k tokens).

On live webmcp list responses, indentation was 20–37% of the tokens. A 9-tool list drops from 24.0 KB to 17.3 KB, which now fits under pi's limit.

Changes

  • All model-facing JSON is now compact: jsonResponse (used by most tools), safeJsonResponse in auth-connections, the browser_repl summary, exec_command, and JSON resources. The data itself is unchanged.
  • Two tests that assert exact response text now expect compact JSON.
  • Generated package.json and tsconfig.json files stay pretty-printed.

Testing

bun test, tsc --noEmit, and prettier --check pass.


Note

Low Risk
Serialization-only change with no API or schema changes; risk is limited to clients that depended on pretty-printed whitespace.

Overview
MCP tool results and JSON resources now serialize with compact JSON (no JSON.stringify indentation) so responses stay smaller under agent harness truncation limits; payload shapes are unchanged.

jsonResponse is the standard path (also adopted by exec_command in shell.ts); safeJsonResponse, browser REPL summaries, and resource templates follow the same rule. AGENTS.md documents the convention, and tests assert compact output where response text is pinned.

Reviewed by Cursor Bugbot for commit 48b3327. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
mcp Ready Ready Preview Oct 19, 2026 2:05pm UTC

@yummybomb
yummybomb force-pushed the hypeship/compact-json-responses branch from 55720d4 to c8d3a4c Compare October 17, 2026 09:26
@yummybomb
yummybomb marked this pull request as ready for review October 17, 2026 09:28

@rgarcia rgarcia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed — mechanical and correct. local run of bun test src/lib/mcp is 941 pass / 0 fail, and grepping null, 2 across src/, fixtures/, docs/ leaves only src/lib/resolvers/typescript.ts:138-139, which pretty-prints generated package.json/tsconfig.json file contents and is correctly untouched.

nice cleanup on shell.ts — it was the last tool hand-rolling the content: [{type:"text"}] envelope, and the output is byte-identical apart from indentation.

Questions

  • src/lib/mcp/responses.test.ts — nothing asserts the compact format. every existing test either JSON.parses the text or compares against JSON.stringify(...), so reintroducing null, 2 in jsonResponse would still pass the suite. one assertion would pin the intent, e.g. expect(jsonResponse({ a: 1 }).content[0].text).toBe('{"a":1}'). the two updated expectations in durable-contracts.test.ts are the same shape, so they don't guard formatting either.

Nits

  • src/lib/mcp/responses.ts:34 — ?? String(value) is unreachable for everything that matters (JSON.stringify(undefined) returns undefined). predates this PR, could drop while you're here.
  • AGENTS.md:82 — now that the "single-line JSON rather than the pretty-printed house helpers" comment in browsers.ts is gone, nothing records compact JSON as the response convention. optional line in AGENTS.md would replace it.

@yummybomb
yummybomb merged commit a80d12f into main Oct 19, 2026
10 checks passed
@yummybomb
yummybomb deleted the hypeship/compact-json-responses branch October 19, 2026 14:06

This branch was successfully deployed

1 active deployment
Preview — 48b3327b Deployed Oct 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants