perf(plugin-mcp): minify JSON in MCP tool responses#15598
Merged
paulpopus merged 10 commits intopayloadcms:mainfrom Apr 11, 2026
Merged
perf(plugin-mcp): minify JSON in MCP tool responses#15598paulpopus merged 10 commits intopayloadcms:mainfrom
paulpopus merged 10 commits intopayloadcms:mainfrom
Conversation
…ify-json-responses
…ify-json-responses
Contributor
Author
|
Hi @kendelljoseph, could you please review this PR? I would appreciate it! |
paulpopus
approved these changes
Apr 11, 2026
Raghvendra2420
pushed a commit
to Raghvendra2420/payload
that referenced
this pull request
Apr 13, 2026
### What? Replaces `JSON.stringify(result, null, 2)` with `JSON.stringify(result)` in all MCP tool response handlers — resource CRUD, global find/update, auth tools, and job run. ### Why? MCP tool responses are consumed by AI agents, not humans. Pretty-printed JSON with 2-space indentation adds significant whitespace overhead that inflates response size without benefit. For rich-text-heavy documents, this reduces MCP response payload size by ~50%. ### How? - Changed all `JSON.stringify(x, null, 2)` calls to `JSON.stringify(x)` in MCP tool response code (12 source files) - Code-generation files (`config.ts`, `job/create.ts`) are intentionally unchanged — they produce human-readable source files - Updated existing test assertions to match minified format (`"key":"value"` instead of `"key": "value"`) - Added dedicated `Minified JSON responses` test suite verifying JSON blocks contain no indentation and are valid JSON --------- Co-authored-by: Paul Popus <paul@payloadcms.com>
Contributor
|
🚀 This is included in version v3.83.0 |
milamer
pushed a commit
to milamer/payload
that referenced
this pull request
Apr 20, 2026
### What? Replaces `JSON.stringify(result, null, 2)` with `JSON.stringify(result)` in all MCP tool response handlers — resource CRUD, global find/update, auth tools, and job run. ### Why? MCP tool responses are consumed by AI agents, not humans. Pretty-printed JSON with 2-space indentation adds significant whitespace overhead that inflates response size without benefit. For rich-text-heavy documents, this reduces MCP response payload size by ~50%. ### How? - Changed all `JSON.stringify(x, null, 2)` calls to `JSON.stringify(x)` in MCP tool response code (12 source files) - Code-generation files (`config.ts`, `job/create.ts`) are intentionally unchanged — they produce human-readable source files - Updated existing test assertions to match minified format (`"key":"value"` instead of `"key": "value"`) - Added dedicated `Minified JSON responses` test suite verifying JSON blocks contain no indentation and are valid JSON --------- Co-authored-by: Paul Popus <paul@payloadcms.com>
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.
What?
Replaces
JSON.stringify(result, null, 2)withJSON.stringify(result)in all MCP tool response handlers — resource CRUD, global find/update, auth tools, and job run.Why?
MCP tool responses are consumed by AI agents, not humans. Pretty-printed JSON with 2-space indentation adds significant whitespace overhead that inflates response size without benefit. For rich-text-heavy documents, this reduces MCP response payload size by ~50%.
How?
JSON.stringify(x, null, 2)calls toJSON.stringify(x)in MCP tool response code (12 source files)config.ts,job/create.ts) are intentionally unchanged — they produce human-readable source files"key":"value"instead of"key": "value")Minified JSON responsestest suite verifying JSON blocks contain no indentation and are valid JSON