feat: client-side application of elicitation schema defaults (SEP-1034) (#976)

Adds an opt-in McpClient builder option `applyElicitationDefaults(boolean)`
that, when enabled, fills missing keys of an accepted ElicitResult.content
with `default` values declared in the requestedSchema before returning the
result to the server. Mirrors the TypeScript SDK's applyElicitationDefaults
behavior, but exposed as a local client config rather than a wire capability.

Co-authored-by: Sainath Reddy Bobbala <bsnr@amazon.com>
Signed-off-by: Dariusz Jędrzejczyk <2554306+chemicL@users.noreply.github.com>
This commit is contained in:
Dariusz Jędrzejczyk 2026-05-22 19:51:54 +02:00 • committed by GitHub
commit accba74c8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,5 +1,5 @@
/*
* Copyright 2025 - 2025 the original author or authors.
* Copyright 2025 - 2026 the original author or authors.
*/
package io.modelcontextprotocol.spec;
@ -1886,6 +1886,29 @@ public class McpSchemaTests {
assertThat(json).doesNotContain("\"url\"");
}
@Test
void testElicitRequestWithDefaultValues() throws Exception {
// Test that schemas with default values serialize correctly in an ElicitRequest
McpSchema.ElicitRequest request = McpSchema.ElicitRequest.builder()
.message("Please provide your info")
.requestedSchema(Map.of("type", "object", "properties",
Map.of("name", Map.of("type", "string", "default", "John Doe"), "age",
Map.of("type", "integer", "default", 30), "score",
Map.of("type", "number", "default", 95.5), "status",
Map.of("type", "string", "enum", List.of("active", "inactive"), "default", "active"),
"verified", Map.of("type", "boolean", "default", true)),
"required", List.of("name")))
.build();
String value = JSON_MAPPER.writeValueAsString(request);
assertThatJson(value).node("requestedSchema.properties.name.default").isEqualTo("John Doe");
assertThatJson(value).node("requestedSchema.properties.age.default").isEqualTo(30);
assertThatJson(value).node("requestedSchema.properties.score.default").isEqualTo(95.5);
assertThatJson(value).node("requestedSchema.properties.status.default").isEqualTo("active");
assertThatJson(value).node("requestedSchema.properties.verified.default").isEqualTo(true);
}
// Progress Notification Tests
@Test