Commit 6ce9ff8
authored
feat(server): support configurable max request payload size (#646)
## Summary
Add `maxRequestBodySize` parameter to
`StreamableHttpServerTransport.Configuration`, allowing consumers to set
a custom request body size limit lower than the default 4 MB.
- Add `maxRequestBodySize: Long` property to `Configuration` with a
default of 4 MB (`4,194,304` bytes)
- Replace hardcoded `MAXIMUM_MESSAGE_SIZE` constant with the
configurable value in `parseBody()`
- Use `Long` for content-length comparison to avoid `Int` overflow on
large values
## Motivation and Context
Closes #521
The `StreamableHttpServerTransport` has a hardcoded 4 MB request body
limit. Consumers who need a lower limit currently have to manually count
the request payload size before passing it to the SDK. This change makes
the limit configurable via `Configuration`.
## How Has This Been Tested?
- Existing unit tests continue to pass (default 4 MB behavior unchanged)
- Added `POST with custom max request body size rejects oversized
payload` — verifies `PayloadTooLarge` is returned for payloads exceeding
the custom limit
- Added `POST at exactly custom max request body size is not rejected as
payload too large` — verifies payloads at exactly the limit are not
rejected by the size check
```bash
./gradlew :kotlin-sdk-server:jvmTest --tests "*.StreamableHttpServerTransportTest"
```
## Breaking Changes
None. The new parameter has a default value matching the previous
hardcoded limit.
## Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
## Checklist
- [x] I have read the [MCP
Documentation](https://modelcontextprotocol.io)
- [x] My code follows the repository's style guidelines
- [x] New and existing tests pass locally
- [x] I have added appropriate error handling
- [x] I have added or updated documentation as needed1 parent fdecf6b commit 6ce9ff8
4 files changed
Lines changed: 73 additions & 10 deletions
File tree
- kotlin-sdk-server
- api
- src
- commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server
- jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
230 | | - | |
231 | | - | |
| 230 | + | |
| 231 | + | |
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
| 237 | + | |
237 | 238 | | |
238 | 239 | | |
239 | 240 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
Lines changed: 19 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
144 | 147 | | |
145 | 148 | | |
146 | 149 | | |
| |||
149 | 152 | | |
150 | 153 | | |
151 | 154 | | |
152 | | - | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
153 | 163 | | |
154 | 164 | | |
155 | 165 | | |
| |||
661 | 671 | | |
662 | 672 | | |
663 | 673 | | |
664 | | - | |
| 674 | + | |
665 | 675 | | |
666 | | - | |
667 | | - | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
668 | 679 | | |
669 | 680 | | |
670 | 681 | | |
671 | | - | |
| 682 | + | |
672 | 683 | | |
673 | 684 | | |
674 | 685 | | |
675 | 686 | | |
676 | 687 | | |
677 | | - | |
| 688 | + | |
678 | 689 | | |
679 | 690 | | |
680 | 691 | | |
681 | | - | |
| 692 | + | |
682 | 693 | | |
683 | 694 | | |
684 | 695 | | |
| |||
Lines changed: 50 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| |||
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
66 | 77 | | |
67 | 78 | | |
68 | 79 | | |
| |||
383 | 394 | | |
384 | 395 | | |
385 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
386 | 436 | | |
387 | 437 | | |
388 | 438 | | |
| |||
0 commit comments