Skip to content

Route.mcp() needed to register routes correctly with Ktor #237

@ukarlsson

Description

@ukarlsson

Describe the bug
There is no Route.mcp() method, and this causes issues since Routing.mcp() seems to register the route on the top-level instead of the route where I need it. It seems like the example in the README.md is broken since that registers on the top-level instead of the route.

I had to add this locally to make it work

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

  sse { mcpSseEndpoint("", transports, block) }

  post { mcpPostEndpoint(transports) }
}

Now with this I can actually use it as intended

      route("/mcp") {
        authenticate("mcp-bearer") { mcp { mcpServer } }
      }

But with the Routing.mcp() it did not get registered in the right location. I also had to copy over util methods below to make it work since these we internal

suspend fun ServerSSESession.mcpSseEndpoint
internal fun ServerSSESession.mcpSseTransport
suspend fun RoutingContext.mcpPostEndpoint(transports: ConcurrentMap<String, SseServerTransport>)

Many thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions