-
Notifications
You must be signed in to change notification settings - Fork 184
Fix kotlin-mcp-server sample #459
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
Conversation
There was a problem hiding this 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 fixes the kotlin-mcp-server sample by adding awaitCancellation() to prevent the SSE connection from closing immediately in the plain configuration server. It also adds comprehensive test coverage for both server configuration types.
Key changes:
- Added
awaitCancellation()in the SSE endpoint handler for plain configuration to keep the connection alive - Refactored tests to support both Ktor plugin and plain configuration server types through a parameterized approach
- Changed function signature to return
EmbeddedServer<*, *>for consistency between both server implementations
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| samples/kotlin-mcp-server/src/main/kotlin/io/modelcontextprotocol/sample/server/server.kt | Added awaitCancellation() to fix SSE connection closing prematurely and changed return type to EmbeddedServer<*, *> |
| samples/kotlin-mcp-server/src/test/kotlin/McpServerType.kt | New enum to define server configuration types with their respective SSE endpoints and factory methods |
| samples/kotlin-mcp-server/src/test/kotlin/TestEnvironment.kt | Refactored from singleton object to parameterized class to support testing multiple server configurations |
| samples/kotlin-mcp-server/src/test/kotlin/SseServerIntegrationTest.kt | Refactored tests into abstract base class with concrete implementations for each server type |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| this.port = port | ||
| } | ||
| } | ||
| val transport = httpClient.mcpSseTransport("http://127.0.0.1:$port/${config.sseEndpoint}") |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The URL construction "http://127.0.0.1:$port/${config.sseEndpoint}" creates incorrect URLs:
- When
sseEndpoint = "/sse", it produces"http://127.0.0.1:$port//sse"(double slash) - When
sseEndpoint = "", it produces"http://127.0.0.1:$port/"(trailing slash)
The sseEndpoint in McpServerType should not include the leading slash. Change it to:
PLAIN_CONFIGURATION(
sseEndpoint = "sse",
...
)Then this URL construction will work correctly for both cases.
| serverFactory = { port -> runSseMcpServerUsingKtorPlugin(port, wait = false) } | ||
| ), | ||
| PLAIN_CONFIGURATION( | ||
| sseEndpoint = "/sse", |
Copilot
AI
Dec 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sseEndpoint should be "sse" instead of "/sse" to avoid creating a double-slash URL (//sse) when concatenated in TestEnvironment.kt line 40. The leading slash is already provided in the URL construction.
| sseEndpoint = "/sse", | |
| sseEndpoint = "sse", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sense, but can be addressed separately
kpavlov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
0ed9ccc to
5263bc3
Compare
Added
awaitCancellationinrunSseMcpServerWithPlainConfiguration()How Has This Been Tested?
Added test for plain configuration server
Checked with inspector
Breaking Changes
None
Types of changes
Checklist