Skip to content

Add Streamable Http Transport #87

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

SeanChinJunKai
Copy link
Contributor

@SeanChinJunKai SeanChinJunKai commented Apr 27, 2025

Closes #79

Pending:

  • Client Implementation of StreamableHttp
  • Unit Tests
  • Integration Tests

Motivation and Context

How Has This Been Tested?

Breaking Changes

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

Additional context

@e5l e5l requested review from Copilot and e5l April 29, 2025 12:10
Copilot

This comment was marked as outdated.

Copy link
Contributor

@e5l e5l left a comment

Choose a reason for hiding this comment

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

Hey @SeanChinJunKai, thanks for the PR. Please check the comments.

It also would be great to have some tests

try {
val acceptHeader = call.request.headers["Accept"]?.split(",") ?: listOf()

if (!acceptHeader.contains("text/event-stream") || !acceptHeader.contains("application/json")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

please use match instead of contains

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@e5l do you mean regex match with call.request.headers["Accept"]? Why do you prefer match over contains?

}

if (sessionId != null) {
call.response.header("Mcp-Session-Id", sessionId!!)
Copy link
Contributor

Choose a reason for hiding this comment

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

Constants should be extracted to the top-level scope with a proper visibility

Copy link
Contributor Author

@SeanChinJunKai SeanChinJunKai May 3, 2025

Choose a reason for hiding this comment

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

@e5l I have extracted it into a Constants file in shared module since we might need it in client module

@SeanChinJunKai
Copy link
Contributor Author

Hi @e5l, thanks for the comments. Ill take a look. I have some questions regarding client transport implementation. In particular, when client makes post request to server server can open a sse session but how does client connect to this sse session?

@SeanChinJunKai
Copy link
Contributor Author

Hi @e5l, could i get some help on the above?

@e5l
Copy link
Contributor

e5l commented May 7, 2025

Sure, let me check

@e5l e5l self-assigned this May 7, 2025
michaellatman added a commit to michaellatman/kotlin-sdk that referenced this pull request Jun 2, 2025
- Clear callMapping in close() method to prevent memory leaks
- Add comprehensive KDoc comments for all public APIs
- Fix Accept header validation to use proper matching instead of contains
- Fix ContentType header key to use HttpHeaders.ContentType
- Fix parseBody error message for invalid JSON format
- Add unit tests for StreamableHttpServerTransport
michaellatman added a commit to michaellatman/kotlin-sdk that referenced this pull request Jun 2, 2025
- Clear callMapping in close() method to prevent memory leaks
- Add comprehensive KDoc comments for all public APIs
- Fix Accept header validation to use proper matching instead of contains
- Fix ContentType header key to use HttpHeaders.ContentType
- Fix parseBody error message for invalid JSON format
- Add unit tests for StreamableHttpServerTransport
michaellatman added a commit to michaellatman/kotlin-sdk that referenced this pull request Jun 2, 2025
- Clear callMapping in close() method to prevent memory leaks
- Add comprehensive KDoc comments for all public APIs
- Fix Accept header validation to use proper matching instead of contains
- Fix ContentType header key to use HttpHeaders.ContentType
- Fix parseBody error message for invalid JSON format
- Add unit tests for StreamableHttpServerTransport
michaellatman added a commit to michaellatman/kotlin-sdk that referenced this pull request Jun 2, 2025
- Clear callMapping in close() method to prevent memory leaks
- Add comprehensive KDoc comments for all public APIs
- Fix Accept header validation to use proper matching instead of contains
- Fix ContentType header key to use HttpHeaders.ContentType
- Fix parseBody error message for invalid JSON format
- Add unit tests for StreamableHttpServerTransport
@devcrocod devcrocod force-pushed the sean/streamable-http branch from 802d323 to 257929a Compare July 9, 2025 10:47
@e5l e5l requested a review from devcrocod July 10, 2025 06:49
@devcrocod devcrocod force-pushed the sean/streamable-http branch from d0e2593 to 9613cd3 Compare July 11, 2025 14:17
@devcrocod devcrocod requested review from Copilot and e5l July 11, 2025 14:18
devcrocod
devcrocod previously approved these changes Jul 11, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

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 introduces a new streamable HTTP transport for JSON-RPC over Server-Sent Events (SSE) and updates protocol message types.

  • Bump protocol version and make JSONRPC IDs optional in response/error types
  • Add StreamableHttpServerTransport and EventStore interface for SSE-based streaming
  • Update API metadata to expose new transport and error constructors

Reviewed Changes

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

File Description
src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/types.kt Updated LATEST_PROTOCOL_VERSION, SUPPORTED_PROTOCOL_VERSIONS, and changed JSONRPCResponse/JSONRPCError signatures to accept nullable IDs
src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/shared/Protocol.kt Adjusted named parameter for JSONRPCError instantiation in fallback error response
src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServerTransport.kt Newly added HTTP transport implementation with SSE, session management, and optional resumability
api/kotlin-sdk.api Reflected changes to JSONRPCError, added EventStore interface, and StreamableHttpServerTransport to public API
Comments suppressed due to low confidence (3)

src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/types.kt:280

  • Changing JSONRPCError from a data class to a regular class and adding an optional id parameter is a breaking API change (removes copy, destructuring, and equals/hashCode). Document this in the changelog and provide migration guidance.
public class JSONRPCError(

src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServerTransport.kt:92

  • This new transport contains complex SSE and HTTP-session logic but no accompanying tests. Add unit and integration tests covering initialization, streaming, error handling, and session resumption.
public class StreamableHttpServerTransport(

src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServerTransport.kt:206

  • [nitpick] Consider adding KDoc to handleRequest (and other public methods) explaining the expected HTTP headers and lifecycle to improve readability and maintainability.
    public suspend fun handleRequest(call: ApplicationCall, session: ServerSSESession) {

@@ -248,7 +248,7 @@ public abstract class Protocol(
JSONRPCResponse(
id = request.id,
error = JSONRPCError(
Copy link
Preview

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

JSONRPCError is instantiated without passing the original request.id, so clients cannot correlate the method-not-found error with the request. Include id = request.id when constructing JSONRPCError.

Suggested change
error = JSONRPCError(
error = JSONRPCError(
id = request.id,

Copilot uses AI. Check for mistakes.

…r/StreamableHttpServerTransport.kt

Co-authored-by: Copilot <[email protected]>
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.

Adding Streaming HTTP Transport
3 participants