Skip to content

refactor: refactor Streamable HTTP ktor extensions (#562) - #568

Merged
kpavlov merged 4 commits into
mainfrom
kpavlov/562-refactor-ktor-extensions
Mar 3, 2026
Merged

refactor: refactor Streamable HTTP ktor extensions (#562)#568
kpavlov merged 4 commits into
mainfrom
kpavlov/562-refactor-ktor-extensions

Conversation

@kpavlov

@kpavlov kpavlov commented Mar 1, 2026

Copy link
Copy Markdown
Contributor
  • Extract TransportManager into its own file and introduce generics for improved type safety. Remove unused method TransportManager.hasTransport
  • Streamline MCP protocol configuration with StreamableHttpServerTransport.Configuration: refactored mcpStatelessStreamableHttp to use StreamableHttpServerTransport.Configuration; Introduced additional overloads of MCP routing functions.
  • Added missing KDoc comments.

Motivation and Context

Address the issue when StreamableHttpServerTransport.Configuration is created on every post invocation

How Has This Been Tested?

Regression tests. No public api changes

Breaking Changes

None

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactoring
  • 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

#521

@@ -1,3 +1,5 @@
@file:Suppress("TooManyFunctions")

@kpavlov kpavlov Mar 1, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Splitting the file is beyond the scope of this PR.

route(path) {
post {
mcpStatelessStreamableHttpEndpoint(
enableDnsRebindingProtection = enableDnsRebindingProtection,

@kpavlov kpavlov Mar 1, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This code caused a configuration object to be created on every call.

@kpavlov
kpavlov marked this pull request as ready for review March 1, 2026 21:09
@kpavlov
kpavlov requested a review from e5l March 1, 2026 21:09
@kpavlov kpavlov changed the title refactor: refactor Streamable HTTP ktor extensions (#562) fix: refactor Streamable HTTP ktor extensions (#562) Mar 1, 2026
@kpavlov kpavlov changed the title fix: refactor Streamable HTTP ktor extensions (#562) refactor: refactor Streamable HTTP ktor extensions (#562) Mar 1, 2026
@kpavlov
kpavlov requested a review from devcrocod March 1, 2026 21:11
@kpavlov kpavlov added the bugfix label Mar 1, 2026
@kpavlov
kpavlov force-pushed the kpavlov/562-refactor-ktor-extensions branch from d436796 to 927cdbc Compare March 2, 2026 09:43
@kpavlov
kpavlov requested a review from e5l March 2, 2026 10:43
@kpavlov
kpavlov force-pushed the kpavlov/562-refactor-ktor-extensions branch from a872e0a to f5845fa Compare March 2, 2026 15:31
kpavlov added 3 commits March 2, 2026 19:45
…erverTransport.Configuration`

- Refactored `mcpStatelessStreamableHttp` to utilize `StreamableHttpServerTransport.Configuration` for enhanced flexibility and maintainability.
- Introduced additional overloads of MCP routing functions to improve usability and extensibility.
- Added missing KDoc comments.
@kpavlov
kpavlov force-pushed the kpavlov/562-refactor-ktor-extensions branch from f5845fa to 4d6681b Compare March 2, 2026 17:45
@codecov-commenter

codecov-commenter commented Mar 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 53.65854% with 19 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...delcontextprotocol/kotlin/sdk/server/KtorServer.kt 47.22% 18 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

…ents

- Deleted the unused `hasTransport` method from `TransportManager`.
- Removed redundant KDoc comments for private methods in `KtorServer`.

@e5l e5l 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.

lgtm

@kpavlov
kpavlov merged commit 9eabb54 into main Mar 3, 2026
13 checks passed
@kpavlov
kpavlov deleted the kpavlov/562-refactor-ktor-extensions branch March 3, 2026 06:51
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