Skip to content

Fix MCP request body limit falling back to 256 KiB - #25

Merged
ruibaby merged 1 commit into
mainfrom
fix/mcp-request-body-limit
Nov 24, 2026
Merged

ruibaby merged 1 commit into
mainfrom
fix/mcp-request-body-limit

Conversation

@ruibaby

@ruibaby ruibaby commented Nov 24, 2026

Copy link
Copy Markdown
Member

Summary

  • Serve the /mcp endpoint with HandlerStrategies that buffer up to 10 MiB instead of Spring's default 256 KiB.
  • Add a regression test that passes a 300 KiB request body through the authentication filter.

Root cause

McpKeyAuthenticationFilter wrapped the MCP router with RouterFunctions.toWebHandler(router). That overload builds HandlerStrategies.withDefaults(), which creates a separate codec configuration whose buffering limit is Spring's 256 KiB default. Halo's spring.http.codecs.max-in-memory-size: 10MB configures the application's own ServerCodecConfigurer, so it never reached the plugin's handler.

As a result, tools/call requests above 256 KiB failed while reading the body, before halo_upload_attachment could apply its own 7 MiB limit (about 9.3 MiB once Base64-encoded).

Reproduction

  1. Send a tools/call request whose body exceeds 256 KiB to /mcp, for example an attachment upload with enough Base64 content.
  2. Before this change the request fails while buffering the body, so the tool never runs.
  3. After this change the same request reaches the tool; halo_upload_attachment then enforces its 7 MiB decoded limit.

Verification

  • ./gradlew test spotlessCheck passes.
  • The new regression test reads a 300 KiB body; it fails when the codec limit is set back to 256 KiB and passes with the 10 MiB limit.

Fixes #24

@ruibaby
ruibaby merged commit fb08424 into main Nov 24, 2026
1 check passed
@ruibaby
ruibaby deleted the fix/mcp-request-body-limit branch November 24, 2026 09:39
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.

通过 MCP 上传附件似乎被限制了 256KB,这个可以调整吗?

1 participant