Repository navigation
fix(server): raise HTTP request body limit #871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zereight
merged 3 commits into
zereight:main
from
bufferoverflow:feature/configurable-mcp-request-limit
Oct 19, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { test } from "node:test"; | ||
| import { CreateDraftNoteSchema, CreateMergeRequestNoteSchema } from "../schemas.js"; | ||
|
|
||
| const GITLAB_NOTE_CHARACTER_LIMIT = 1_000_000; | ||
|
|
||
| test("merge request note input schemas accept GitLab's note character limit", () => { | ||
| const body = "a".repeat(GITLAB_NOTE_CHARACTER_LIMIT); | ||
|
|
||
| const note = CreateMergeRequestNoteSchema.parse({ | ||
| project_id: "group/project", | ||
| merge_request_iid: 1, | ||
| body, | ||
| }); | ||
| const draft = CreateDraftNoteSchema.parse({ | ||
| project_id: "group/project", | ||
| merge_request_iid: 1, | ||
| body, | ||
| }); | ||
|
|
||
| assert.equal(note.body.length, GITLAB_NOTE_CHARACTER_LIMIT); | ||
| assert.equal(draft.body.length, GITLAB_NOTE_CHARACTER_LIMIT); | ||
| }); |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { afterEach, describe, test } from "node:test"; | ||
| import { | ||
| cleanupServers, | ||
| findAvailablePort, | ||
| launchServer, | ||
| ServerInstance, | ||
| TransportMode, | ||
| } from "./utils/server-launcher.js"; | ||
|
|
||
| const HOST = process.env.HOST || "127.0.0.1"; | ||
| const GITLAB_NOTE_CHARACTER_LIMIT = 1_000_000; | ||
| const TWENTY_KIB = 20 * 1024; | ||
|
|
||
| const servers: ServerInstance[] = []; | ||
|
|
||
| function noteRequest(bodyLength: number): string { | ||
| return JSON.stringify({ | ||
| jsonrpc: "2.0", | ||
| id: 1, | ||
| method: "tools/call", | ||
| params: { | ||
| name: "create_merge_request_note", | ||
| arguments: { | ||
| project_id: "group/project", | ||
| merge_request_iid: 1, | ||
| body: "a".repeat(bodyLength), | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| function noteRequestWithEncodedLength(encodedLength: number): string { | ||
| const emptyRequest = noteRequest(0); | ||
| const fixedLength = Buffer.byteLength(emptyRequest); | ||
|
|
||
| assert.ok(encodedLength >= fixedLength); | ||
| const request = noteRequest(encodedLength - fixedLength); | ||
| assert.equal(Buffer.byteLength(request), encodedLength); | ||
| return request; | ||
| } | ||
|
|
||
| async function startServer(basePort: number, env: Record<string, string> = {}): Promise<string> { | ||
| const port = await findAvailablePort(basePort); | ||
| const server = await launchServer({ | ||
| mode: TransportMode.STREAMABLE_HTTP, | ||
| port, | ||
| env: { | ||
| GITLAB_API_URL: "https://gitlab.example.com/api/v4", | ||
| REMOTE_AUTHORIZATION: "true", | ||
| ...env, | ||
| }, | ||
| }); | ||
| servers.push(server); | ||
| return `http://${HOST}:${port}/mcp`; | ||
| } | ||
|
|
||
| async function postNoteRequest(mcpUrl: string, body: string): Promise<Response> { | ||
| return fetch(mcpUrl, { | ||
| method: "POST", | ||
| headers: { | ||
| Accept: "application/json, text/event-stream", | ||
| "Content-Type": "application/json", | ||
| }, | ||
| body, | ||
| }); | ||
| } | ||
|
|
||
| afterEach(() => { | ||
| cleanupServers(servers); | ||
| servers.length = 0; | ||
| }); | ||
|
|
||
| describe("Streamable HTTP request body limit", () => { | ||
| test("parses a note at GitLab's character limit by default", async () => { | ||
| const mcpUrl = await startServer(4590); | ||
| const response = await postNoteRequest(mcpUrl, noteRequest(GITLAB_NOTE_CHARACTER_LIMIT)); | ||
|
|
||
| assert.equal(response.status, 401); | ||
| }); | ||
|
|
||
| test("honors a configured request body limit", async () => { | ||
| const mcpUrl = await startServer(4600, { GITLAB_MCP_REQUEST_BODY_LIMIT: "20kb" }); | ||
|
|
||
| const accepted = await postNoteRequest(mcpUrl, noteRequestWithEncodedLength(TWENTY_KIB)); | ||
| assert.equal(accepted.status, 401); | ||
|
|
||
| const rejected = await postNoteRequest(mcpUrl, noteRequestWithEncodedLength(TWENTY_KIB + 1)); | ||
| assert.equal(rejected.status, 413); | ||
|
|
||
| const unrelatedRoute = await postNoteRequest( | ||
| mcpUrl.replace(/\/mcp$/, "/health"), | ||
| noteRequestWithEncodedLength(TWENTY_KIB + 1) | ||
| ); | ||
| assert.equal(unrelatedRoute.status, 404); | ||
| }); | ||
|
|
||
| test("rate-limits an oversized request before parsing it", async () => { | ||
| const mcpUrl = await startServer(4610, { | ||
| GITLAB_MCP_REQUEST_BODY_LIMIT: "20kb", | ||
| MAX_REQUESTS_PER_MINUTE: "1", | ||
| }); | ||
|
|
||
| const first = await postNoteRequest(mcpUrl, noteRequest(1)); | ||
| assert.equal(first.status, 401); | ||
|
|
||
| const rateLimited = await postNoteRequest(mcpUrl, noteRequestWithEncodedLength(TWENTY_KIB + 1)); | ||
| assert.equal(rateLimited.status, 429); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.