Skip to content

feat: Verify MCP endpoints with authentication for Streamable HTTP transport, test for SSE transport#535

Draft
kpavlov wants to merge 4 commits intomainfrom
kpavlov/auth-test
Draft

feat: Verify MCP endpoints with authentication for Streamable HTTP transport, test for SSE transport#535
kpavlov wants to merge 4 commits intomainfrom
kpavlov/auth-test

Conversation

@kpavlov
Copy link
Contributor

@kpavlov kpavlov commented Feb 18, 2026

Verify/fix MCP endpoint with Ktor authentication for SSE and Streamable-HTTP

  1. Add Ktor authentication integration tests for protecting MCP routes (SSE & Streamable HTTP)
  2. Add/refactor MCP route extensions
    • Add missing Route.mcpStreamableHttp extensions, similar to other transports
    • Move TransportManager to a separate file and generalize.
    • Refactored mcpStreamableHttp and mcpStatelessStreamableHttp extensions to use the config object instead of too many parameters. This change unblocks Support configuration of the max request payload size for Streamable HTTP impl #521
    • Added integration tests (KtorStreamableHttpExtensionsTest) to validate route registrations, subpath handling, and sibling route isolation.

Motivation and Context

To demonstrate and verify Ktor authentication in action, I provided an example. However, it revealed that StreamableHttp transport isn’t fully supported. Consequently, missing extensions were implemented and method signatures were refactored.

How Has This Been Tested?

Unit and integration tests

Breaking Changes

Only the new API was modified.

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

#521

@kpavlov kpavlov added the enhancement New feature or request label Feb 18, 2026
@kpavlov kpavlov changed the title refactor: feat!: Support authentiucation endpoints for Streamable HTTP transport Feb 18, 2026
@kpavlov kpavlov added breaking Breaking changes 👧🏠🔥 and removed breaking Breaking changes 👧🏠🔥 labels Feb 18, 2026
@kpavlov kpavlov changed the title feat!: Support authentiucation endpoints for Streamable HTTP transport feat: Support authentiucation endpoints for Streamable HTTP transport Feb 18, 2026
@kpavlov kpavlov changed the title feat: Support authentiucation endpoints for Streamable HTTP transport feat: Support authentication endpoints for Streamable HTTP transport Feb 18, 2026
@kpavlov kpavlov changed the title feat: Support authentication endpoints for Streamable HTTP transport feat: Support MCP endpoints with authentication for Streamable HTTP transport, test for SSE transport Feb 18, 2026
@kpavlov kpavlov added the tests label Feb 18, 2026
@kpavlov kpavlov force-pushed the kpavlov/auth-test branch 2 times, most recently from a714c63 to 7c93a68 Compare February 18, 2026 20:06
@kpavlov kpavlov added this to the 0.9 milestone Feb 18, 2026
@kpavlov kpavlov marked this pull request as ready for review February 18, 2026 20:51
- Introduced `SseAuthenticationTest`, demonstrating how to protect MCP endpoints with authentication.
- Move `TransportManager` to separate file and generalize.
- Refactored `mcpStreamableHttp` and `mcpStatelessStreamableHttp` to use config object.
- Added integration tests (`KtorStreamableHttpExtensionsTest`) to validate route registrations, subpath handling, and sibling route isolation.

fix: Correct Ktor external documentation link and update KDoc references

- Updated external documentation link from `ktor-client` to `ktor` in Dokka configuration.
- Replaced KDoc references to `io.ktor.server.auth.authenticate` with `Route.authenticate` for consistency.
- Removed `AbstractKtorExtensionsTest` and migrated its helpers to `TestHelpers.kt` for better reuse.
- Added new test cases for route and application-level MCP extensions, ensuring default and custom paths work as intended.
- Enabled parallel test execution via `junit-platform.properties`.
- Updated (reduced) detekt baselines to reflect changes in test structure and layout.
Comment on lines +119 to +120
config: McpStreamableHttpConfig.() -> Unit = {},
serverFactory: RoutingContext.() -> Server,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not the best API design
there are two lambda parameters in a row
and the second one has a default value while the third doesn't

Copy link
Contributor Author

@kpavlov kpavlov Feb 19, 2026

Choose a reason for hiding this comment

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

The exploded parameter list was not better either. Not scalable and requires hard changes to the api shape.
Let's keep it simpler then:

Suggested change
config: McpStreamableHttpConfig.() -> Unit = {},
serverFactory: RoutingContext.() -> Server,
config: McpStreamableHttpConfig,
serverFactory: RoutingContext.() -> Server,

@kpavlov kpavlov changed the title feat: Support MCP endpoints with authentication for Streamable HTTP transport, test for SSE transport feat: Verify MCP endpoints with authentication for Streamable HTTP transport, test for SSE transport Feb 21, 2026
@kpavlov kpavlov marked this pull request as draft February 23, 2026 14:25
Copy link
Collaborator

@aozherelyeva aozherelyeva left a comment

Choose a reason for hiding this comment

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

LGTM, didn't think of other checks for now. Thanks!

kpavlov added a commit that referenced this pull request Feb 26, 2026
## Introduce Configuration class for StreamableHttpServerTransport

Replace the six-parameter flat constructor of
`StreamableHttpServerTransport` with a typed `Configuration` class. This
improves API ergonomics, enables structural equality and copy(), and
provides a stable extension point for future options without further
breaking the constructor signature.

### Changes:

- Add `Configuration` as a public class nested directly on
`StreamableHttpServerTransport`, with `enableJsonResponse` as the first
parameter (most commonly set)
  - Change the primary constructor to accept `Configuration`.
- Rename `retryIntervalMillis: Long?` to `retryInterval: Duration?` in
Configuration, aligning with Kotlin's type-safe time API
  - Deprecate the old flat constructor with a compatibility bridge
  - Update KotlinTestBase integration test to use the new constructor
- Enable test
AbstractResourceIntegrationTest.testSubscribeAndUnsubscribe() since #249
is closed

## Motivation and Context

The current StreamableHttpServerTransport API cannot be easily extended:
adding more parameters would be a breaking change. But this is already
needed for #521.
This PR is a prerequisite for #535

## How Has This Been Tested?
Regression tests

## Breaking Changes
No. Current StreamableHttpServerTransport constructor was deprecated

## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [ ] 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
<!-- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [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
- [ ] I have added appropriate error handling
- [ ] I have added or updated documentation as needed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants