Skip to content

perf(plugin-mcp): minify JSON in MCP tool responses#15598

Merged
paulpopus merged 10 commits intopayloadcms:mainfrom
jhb-dev:feat/plugin-mcp/minify-json-responses
Apr 11, 2026
Merged

perf(plugin-mcp): minify JSON in MCP tool responses#15598
paulpopus merged 10 commits intopayloadcms:mainfrom
jhb-dev:feat/plugin-mcp/minify-json-responses

Conversation

@jhb-dev
Copy link
Copy Markdown
Contributor

@jhb-dev jhb-dev commented Feb 11, 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

@jhb-dev
Copy link
Copy Markdown
Contributor Author

jhb-dev commented Apr 7, 2026

Hi @kendelljoseph, could you please review this PR? I would appreciate it!

@paulpopus paulpopus merged commit 976369d into payloadcms:main Apr 11, 2026
162 checks passed
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>
@github-actions
Copy link
Copy Markdown
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants