Skip to content

Commit 442c80d

Browse files
nerzhulartdevcrocod
authored andcommitted
Add ServerSSESession as a receiver for mcp {} dsl (modelcontextprotocol#190)
* Add ServerSSESession as a receiver for mcp {} dsl * update api --------- Co-authored-by: devcrocod <[email protected]>
1 parent e9dcd30 commit 442c80d

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

kotlin-sdk-server/api/kotlin-sdk-server.api

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ public final class io/modelcontextprotocol/kotlin/sdk/LibVersionKt {
33
}
44

55
public final class io/modelcontextprotocol/kotlin/sdk/server/KtorServerKt {
6-
public static final fun MCP (Lio/ktor/server/application/Application;Lkotlin/jvm/functions/Function0;)V
7-
public static final fun mcp (Lio/ktor/server/application/Application;Lkotlin/jvm/functions/Function0;)V
8-
public static final fun mcp (Lio/ktor/server/routing/Routing;Ljava/lang/String;Lkotlin/jvm/functions/Function0;)V
9-
public static final fun mcp (Lio/ktor/server/routing/Routing;Lkotlin/jvm/functions/Function0;)V
6+
public static final fun MCP (Lio/ktor/server/application/Application;Lkotlin/jvm/functions/Function1;)V
7+
public static final fun mcp (Lio/ktor/server/application/Application;Lkotlin/jvm/functions/Function1;)V
8+
public static final fun mcp (Lio/ktor/server/routing/Routing;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
9+
public static final fun mcp (Lio/ktor/server/routing/Routing;Lkotlin/jvm/functions/Function1;)V
1010
}
1111

1212
public final class io/modelcontextprotocol/kotlin/sdk/server/RegisteredPrompt {

kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/KtorServer.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import io.ktor.utils.io.KtorDsl
1919
private val logger = KotlinLogging.logger {}
2020

2121
@KtorDsl
22-
public fun Routing.mcp(path: String, block: () -> Server) {
22+
public fun Routing.mcp(path: String, block: ServerSSESession.() -> Server) {
2323
route(path) {
2424
mcp(block)
2525
}
@@ -29,7 +29,7 @@ public fun Routing.mcp(path: String, block: () -> Server) {
2929
* Configures the Ktor Application to handle Model Context Protocol (MCP) over Server-Sent Events (SSE).
3030
*/
3131
@KtorDsl
32-
public fun Routing.mcp(block: () -> Server) {
32+
public fun Routing.mcp(block: ServerSSESession.() -> Server) {
3333
val transports = ConcurrentMap<String, SseServerTransport>()
3434

3535
sse {
@@ -43,12 +43,12 @@ public fun Routing.mcp(block: () -> Server) {
4343

4444
@Suppress("FunctionName")
4545
@Deprecated("Use mcp() instead", ReplaceWith("mcp(block)"), DeprecationLevel.WARNING)
46-
public fun Application.MCP(block: () -> Server) {
46+
public fun Application.MCP(block: ServerSSESession.() -> Server) {
4747
mcp(block)
4848
}
4949

5050
@KtorDsl
51-
public fun Application.mcp(block: () -> Server) {
51+
public fun Application.mcp(block: ServerSSESession.() -> Server) {
5252
val transports = ConcurrentMap<String, SseServerTransport>()
5353

5454
install(SSE)
@@ -67,7 +67,7 @@ public fun Application.mcp(block: () -> Server) {
6767
private suspend fun ServerSSESession.mcpSseEndpoint(
6868
postEndpoint: String,
6969
transports: ConcurrentMap<String, SseServerTransport>,
70-
block: () -> Server,
70+
block: ServerSSESession.() -> Server,
7171
) {
7272
val transport = mcpSseTransport(postEndpoint, transports)
7373

0 commit comments

Comments
 (0)