Skip to content

feat(server): allow decorating Ktor transports - #953

Open
ECD5A wants to merge 1 commit into
modelcontextprotocol:mainfrom
ECD5A:feat/921-ktor-transport-decorator
Open

feat(server): allow decorating Ktor transports#953
ECD5A wants to merge 1 commit into
modelcontextprotocol:mainfrom
ECD5A:feat/921-ktor-transport-decorator

Conversation

@ECD5A

@ECD5A ECD5A commented Aug 11, 2026

Copy link
Copy Markdown

Motivation and Context

Closes #921.

The Ktor SSE and Streamable HTTP extensions create their transports internally, so applications cannot add transport-level logging, metrics, back-pressure, or framing without reimplementing the SDK's private route and session wiring.

This adds opt-in transportDecorator overloads for the SSE mcp extensions and mcpStreamableHttp. Each decorator receives the concrete SDK transport and returns the Transport passed to Server.createSession. Existing overloads delegate through an identity decorator, preserving current source and binary APIs.

How Has This Been Tested?

  • Added Ktor integration tests for Application.mcp, Route.mcp(path), and Application.mcpStreamableHttp.
  • The tests wrap each concrete transport, verify the wrapper is started, and exercise the normal SSE ping or Streamable HTTP initialize flow.
  • Ran the complete kotlin-sdk-server JVM test suite.
  • Ran ktlintCheck, detekt, and apiCheck for the repository.

Breaking Changes

None. Existing overloads and their generated JVM signatures remain unchanged; the new overloads are additive.

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

The concrete transport remains responsible for Ktor request handling and session bookkeeping. A decorator must delegate lifecycle methods and callback registration to that supplied transport; this requirement is documented on each new overload.

@ECD5A
ECD5A marked this pull request as ready for review August 11, 2026 06:40
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.

Ktor SSE / StreamableHttp extensions build their transports internally, with no hook to wrap them

1 participant