Repository navigation
Return compact JSON from MCP tool and resource responses - #257
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
yummybomb
force-pushed
the
hypeship/compact-json-responses
branch
from
October 17, 2026 09:26
55720d4 to
c8d3a4c
Compare
yummybomb
marked this pull request as ready for review
October 17, 2026 09:28
rgarcia
approved these changes
Oct 18, 2026
rgarcia
left a comment
Contributor
There was a problem hiding this comment.
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 eitherJSON.parses the text or compares againstJSON.stringify(...), so reintroducingnull, 2injsonResponsewould 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 indurable-contracts.test.tsare 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)returnsundefined). 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 inbrowsers.tsis gone, nothing records compact JSON as the response convention. optional line in AGENTS.md would replace it.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
webmcplistresponses, 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
jsonResponse(used by most tools),safeJsonResponseinauth-connections, thebrowser_replsummary,exec_command, and JSON resources. The data itself is unchanged.package.jsonandtsconfig.jsonfiles stay pretty-printed.Testing
bun test,tsc --noEmit, andprettier --checkpass.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.stringifyindentation) so responses stay smaller under agent harness truncation limits; payload shapes are unchanged.jsonResponseis the standard path (also adopted byexec_commandinshell.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.