feat: sep-1036 add URL Mode Elicitation (#843)

closes #410 

## How Has This Been Tested?
integration and unit tests 

## Breaking Changes
none

## Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update

## Checklist
- [x] I have read the [MCP
Documentation](https://modelcontextprotocol.io)
- [x] My code follows the repository's style guidelines
- [x] New and existing tests pass locally
- [x] I have added appropriate error handling
- [x] I have added or updated documentation as needed
This commit is contained in:
Pavel Gorgulov 2026-06-23 22:14:59 +02:00 • committed by GitHub
commit c8a1103b16
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 494 additions and 6 deletions

View file

@ -25,6 +25,7 @@ import io.modelcontextprotocol.kotlin.sdk.types.ResourceListChangedNotification
import io.modelcontextprotocol.kotlin.sdk.types.ResourceUpdatedNotification
import io.modelcontextprotocol.kotlin.sdk.types.ServerNotification
import io.modelcontextprotocol.kotlin.sdk.types.ToolListChangedNotification
import io.modelcontextprotocol.kotlin.sdk.types.supportsUrl
private val logger = KotlinLogging.logger {}
@ -238,6 +239,11 @@ internal class ClientConnectionImpl(private val session: ServerSession) : Client
override suspend fun createElicitation(request: ElicitRequest, options: RequestOptions?): ElicitResult {
val params = request.params
if (params is ElicitRequestURLParams) {
require(session.clientCapabilities?.elicitation.supportsUrl) {
"Client did not advertise elicitation.url capability; cannot send a URL-mode elicitation."
}
}
logger.debug {
when (params) {
is ElicitRequestFormParams ->
@ -299,6 +305,9 @@ internal class ClientConnectionImpl(private val session: ServerSession) : Client
}
override suspend fun sendElicitationComplete(notification: ElicitationCompleteNotification) {
require(session.clientCapabilities?.elicitation.supportsUrl) {
"Client did not advertise elicitation.url capability; cannot send an elicitation completion notification."
}
logger.debug { "Sending elicitation complete notification for: ${notification.params.elicitationId}" }
notification(notification)
}

View file

@ -46,6 +46,7 @@ import io.modelcontextprotocol.kotlin.sdk.types.ToolAnnotations
import io.modelcontextprotocol.kotlin.sdk.types.ToolExecution
import io.modelcontextprotocol.kotlin.sdk.types.ToolSchema
import io.modelcontextprotocol.kotlin.sdk.types.UnsubscribeRequest
import io.modelcontextprotocol.kotlin.sdk.types.UrlElicitationRequiredException
import io.modelcontextprotocol.kotlin.sdk.utils.MatchResult
import io.modelcontextprotocol.kotlin.sdk.utils.PathSegmentTemplateMatcher
import io.modelcontextprotocol.kotlin.sdk.utils.ResourceTemplateMatcher
@ -651,6 +652,9 @@ public open class Server(
}
} catch (e: CancellationException) {
throw e
} catch (e: UrlElicitationRequiredException) {
// Surface a required URL-mode elicitation as a JSON-RPC error (-32042)
throw e
} catch (e: Exception) {
logger.error(e) { "Error executing tool ${requestParams.name}" }
CallToolResult(