Skip to content

Add ServerSSESession as a receiver for mcp {} dsl #190

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions kotlin-sdk-server/api/kotlin-sdk-server.api
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ public final class io/modelcontextprotocol/kotlin/sdk/LibVersionKt {
}

public final class io/modelcontextprotocol/kotlin/sdk/server/KtorServerKt {
public static final fun MCP (Lio/ktor/server/application/Application;Lkotlin/jvm/functions/Function0;)V
public static final fun mcp (Lio/ktor/server/application/Application;Lkotlin/jvm/functions/Function0;)V
public static final fun mcp (Lio/ktor/server/routing/Routing;Ljava/lang/String;Lkotlin/jvm/functions/Function0;)V
public static final fun mcp (Lio/ktor/server/routing/Routing;Lkotlin/jvm/functions/Function0;)V
public static final fun MCP (Lio/ktor/server/application/Application;Lkotlin/jvm/functions/Function1;)V
public static final fun mcp (Lio/ktor/server/application/Application;Lkotlin/jvm/functions/Function1;)V
public static final fun mcp (Lio/ktor/server/routing/Routing;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public static final fun mcp (Lio/ktor/server/routing/Routing;Lkotlin/jvm/functions/Function1;)V
}

public final class io/modelcontextprotocol/kotlin/sdk/server/RegisteredPrompt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import io.ktor.utils.io.KtorDsl
private val logger = KotlinLogging.logger {}

@KtorDsl
public fun Routing.mcp(path: String, block: () -> Server) {
public fun Routing.mcp(path: String, block: ServerSSESession.() -> Server) {
route(path) {
mcp(block)
}
Expand All @@ -29,7 +29,7 @@ public fun Routing.mcp(path: String, block: () -> Server) {
* Configures the Ktor Application to handle Model Context Protocol (MCP) over Server-Sent Events (SSE).
*/
@KtorDsl
public fun Routing.mcp(block: () -> Server) {
public fun Routing.mcp(block: ServerSSESession.() -> Server) {
val transports = ConcurrentMap<String, SseServerTransport>()

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

@Suppress("FunctionName")
@Deprecated("Use mcp() instead", ReplaceWith("mcp(block)"), DeprecationLevel.WARNING)
public fun Application.MCP(block: () -> Server) {
public fun Application.MCP(block: ServerSSESession.() -> Server) {
mcp(block)
}

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

install(SSE)
Expand All @@ -67,7 +67,7 @@ public fun Application.mcp(block: () -> Server) {
private suspend fun ServerSSESession.mcpSseEndpoint(
postEndpoint: String,
transports: ConcurrentMap<String, SseServerTransport>,
block: () -> Server,
block: ServerSSESession.() -> Server,
) {
val transport = mcpSseTransport(postEndpoint, transports)

Expand Down
Loading