Skip to content

Conversation

IainHull
Copy link

This should also fix Issues #236 and #237

Changes the Ktor API from

fun Routing.mcp(block: ServerSSESession.() -> Server)

to

fun Route.mcp(block: suspend ServerSSESession.() -> Server)

Motivation and Context

This fixes

  • mcp inside a route is bound to the path specified in the route not the root path.
  • ability to publish multiple mcp servers
  • can create the server asynchronously
  • together this enables developers to created multi tenanted mcp servers

This enables code the following style of code

routing {
    route("mcp/{application}") {
        mcp {
            val authHeader = call.request.header("Authorization") ?: throw IllegalArgumentException("Authorization header required")
            val application = call.parameters["application"] ?: throw IllegalArgumentException("Application required")
            return@mcpFixed mcpServerManager.getOrCreateServer(authHeader, application)
        }
    }
}

How Has This Been Tested?

Tested this with npx @modelcontextprotocol/inspector and Flowise

Breaking Changes

This maintains source compatibility, but not binary compatibility.

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

Address

@IainHull
Copy link
Author

Sorry for the churn, there were two pieces missing from my initial commit.

@kpavlov would you be able to trigger another build?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants