Skip to content

fix: bound inline SSE event size in Streamable HTTP client#841

Merged
devcrocod merged 1 commit into
mainfrom
fix/inline-sse-size-limit
Jun 18, 2026
Merged

fix: bound inline SSE event size in Streamable HTTP client#841
devcrocod merged 1 commit into
mainfrom
fix/inline-sse-size-limit

Conversation

@devcrocod

@devcrocod devcrocod commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Bound the size of a single inline SSE event parsed from a POST response in StreamableHttpClientTransport, so a non-conforming or unbounded server response cannot grow the client's buffer without limit.

How Has This Been Tested?

New unit tests

Breaking Changes

none

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Copilot AI review requested due to automatic review settings June 17, 2026 23:32
@devcrocod devcrocod requested a review from e5l June 17, 2026 23:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a defensive size bound to inline SSE parsing for Streamable HTTP POST responses so that a non-terminating or oversized SSE event cannot grow the client buffer without limit.

Changes:

  • Introduces maxInlineSseEventSize (default 16 MiB) and enforces it while parsing inline SSE (data: accumulation + per-line bounds).
  • Adds unit tests covering oversized inline SSE events, exact-bound acceptance, and invalid configuration.
  • Updates the public API dump to reflect the new constructor signature.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTransport.kt Adds max-size configuration and enforces bounds while parsing inline SSE from POST responses.
kotlin-sdk-client/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/client/streamable/http/StreamableHttpClientTransportTest.kt Adds unit tests for oversized/exact-size inline SSE events and invalid max size.
kotlin-sdk-client/api/kotlin-sdk-client.api Updates API dump for the changed StreamableHttpClientTransport constructor signature.
Comments suppressed due to low confidence (1)

kotlin-sdk-client/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/client/StreamableHttpClientTransport.kt:111

  • The deprecated constructor's ReplaceWith suggestion is now invalid because the primary constructor gained a maxInlineSseEventSize: Int parameter. As written, the replacement call passes requestBuilder positionally as the 4th argument, which will now be treated as maxInlineSseEventSize and fail to compile. Use a named argument for requestBuilder (and/or supply maxInlineSseEventSize).
        replaceWith = ReplaceWith(
            "StreamableHttpClientTransport(client, url, " +
                "ReconnectionOptions(initialReconnectionDelay = reconnectionTime ?: 1.seconds), requestBuilder)",
            "kotlin.time.Duration.Companion.seconds",
            "io.modelcontextprotocol.kotlin.sdk.client.ReconnectionOptions",

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +486 to +490
val line = try {
channel.readUTF8Line(maxInlineSseEventSize)
} catch (_: TooLongLineException) {
throw TooLongFrameException(maxInlineSseEventSize.toLong() + 1, maxInlineSseEventSize)
}
Comment on lines +88 to 92
* @param maxInlineSseEventSize maximum size, in characters, of a single inline SSE event parsed from a
* POST response; a server that exceeds it (including by never terminating an event) fails the send
* with [io.modelcontextprotocol.kotlin.sdk.shared.TooLongFrameException]. Defaults to 16 MiB.
* @param requestBuilder builder applied to every outgoing HTTP request, e.g. for adding auth headers
*/
Comment on lines +104 to +105
public fun <init> (Lio/ktor/client/HttpClient;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/client/ReconnectionOptions;ILkotlin/jvm/functions/Function1;)V
public synthetic fun <init> (Lio/ktor/client/HttpClient;Ljava/lang/String;Lio/modelcontextprotocol/kotlin/sdk/client/ReconnectionOptions;ILkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
@devcrocod devcrocod merged commit d21728e into main Jun 18, 2026
21 checks passed
@devcrocod devcrocod deleted the fix/inline-sse-size-limit branch June 18, 2026 06:54
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.

3 participants