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 needed
This commit is contained in:
parent
fdecf6bdf5
commit
6ce9ff81e7
1 changed files with 73 additions and 10 deletions
|
|
@ -227,13 +227,14 @@ public final class io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServe
|
|||
}
|
||||
|
||||
public final class io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServerTransport$Configuration {
|
||||
public synthetic fun <init> (ZZLjava/util/List;Ljava/util/List;Lio/modelcontextprotocol/kotlin/sdk/server/EventStore;Lkotlin/time/Duration;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public synthetic fun <init> (ZZLjava/util/List;Ljava/util/List;Lio/modelcontextprotocol/kotlin/sdk/server/EventStore;Lkotlin/time/Duration;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public synthetic fun <init> (ZZLjava/util/List;Ljava/util/List;Lio/modelcontextprotocol/kotlin/sdk/server/EventStore;Lkotlin/time/Duration;JILkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public synthetic fun <init> (ZZLjava/util/List;Ljava/util/List;Lio/modelcontextprotocol/kotlin/sdk/server/EventStore;Lkotlin/time/Duration;JLkotlin/jvm/internal/DefaultConstructorMarker;)V
|
||||
public final fun getAllowedHosts ()Ljava/util/List;
|
||||
public final fun getAllowedOrigins ()Ljava/util/List;
|
||||
public final fun getEnableDnsRebindingProtection ()Z
|
||||
public final fun getEnableJsonResponse ()Z
|
||||
public final fun getEventStore ()Lio/modelcontextprotocol/kotlin/sdk/server/EventStore;
|
||||
public final fun getMaxRequestBodySize ()J
|
||||
public final fun getRetryInterval-FghU774 ()Lkotlin/time/Duration;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue