-
Notifications
You must be signed in to change notification settings - Fork 1.4k
SEP-1034: Default values for Elicitation Schemas #1096
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
felixweinberger
merged 10 commits into
modelcontextprotocol:main
from
KKonstantinov:feature/sep-1034-default-values-elicitation-schemas
Nov 11, 2025
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
80dd446
save commit
KKonstantinov 159eef6
clean up
KKonstantinov 7e7fb9a
move defaulting to client side
KKonstantinov cee9d13
prettier fix
KKonstantinov c68bc97
spec types - temporary fix for elicitation: object type
KKonstantinov e614046
prettier fix
KKonstantinov 7d28962
clean up
KKonstantinov 37b9cf0
clean up
KKonstantinov 724c73b
prettier fix
KKonstantinov c90f256
clean up
KKonstantinov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,10 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo | |
| } | ||
| ); | ||
|
|
||
| const client = new Client({ name: 'test-client', version: '1.0.0' }, { capabilities: { elicitation: {} } }); | ||
| const client = new Client( | ||
| { name: 'test-client', version: '1.0.0' }, | ||
| { capabilities: { elicitation: {} }, jsonSchemaValidator: validatorProvider } | ||
| ); | ||
|
|
||
| client.setRequestHandler(ElicitRequestSchema, _request => ({ | ||
| action: 'accept', | ||
|
|
@@ -73,7 +76,10 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo | |
| } | ||
| ); | ||
|
|
||
| const client = new Client({ name: 'test-client', version: '1.0.0' }, { capabilities: { elicitation: {} } }); | ||
| const client = new Client( | ||
| { name: 'test-client', version: '1.0.0' }, | ||
| { capabilities: { elicitation: {} }, jsonSchemaValidator: validatorProvider } | ||
| ); | ||
|
|
||
| client.setRequestHandler(ElicitRequestSchema, _request => ({ | ||
| action: 'accept', | ||
|
|
@@ -109,7 +115,10 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo | |
| } | ||
| ); | ||
|
|
||
| const client = new Client({ name: 'test-client', version: '1.0.0' }, { capabilities: { elicitation: {} } }); | ||
| const client = new Client( | ||
| { name: 'test-client', version: '1.0.0' }, | ||
| { capabilities: { elicitation: {} }, jsonSchemaValidator: validatorProvider } | ||
| ); | ||
|
|
||
| client.setRequestHandler(ElicitRequestSchema, _request => ({ | ||
| action: 'accept', | ||
|
|
@@ -145,7 +154,10 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo | |
| } | ||
| ); | ||
|
|
||
| const client = new Client({ name: 'test-client', version: '1.0.0' }, { capabilities: { elicitation: {} } }); | ||
| const client = new Client( | ||
| { name: 'test-client', version: '1.0.0' }, | ||
| { capabilities: { elicitation: {} }, jsonSchemaValidator: validatorProvider } | ||
| ); | ||
|
|
||
| const userData = { | ||
| name: 'Jane Smith', | ||
|
|
@@ -200,7 +212,10 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo | |
| } | ||
| ); | ||
|
|
||
| const client = new Client({ name: 'test-client', version: '1.0.0' }, { capabilities: { elicitation: {} } }); | ||
| const client = new Client( | ||
| { name: 'test-client', version: '1.0.0' }, | ||
| { capabilities: { elicitation: {} }, jsonSchemaValidator: validatorProvider } | ||
| ); | ||
|
|
||
| client.setRequestHandler(ElicitRequestSchema, _request => ({ | ||
| action: 'accept', | ||
|
|
@@ -237,7 +252,10 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo | |
| } | ||
| ); | ||
|
|
||
| const client = new Client({ name: 'test-client', version: '1.0.0' }, { capabilities: { elicitation: {} } }); | ||
| const client = new Client( | ||
| { name: 'test-client', version: '1.0.0' }, | ||
| { capabilities: { elicitation: {} }, jsonSchemaValidator: validatorProvider } | ||
| ); | ||
|
|
||
| client.setRequestHandler(ElicitRequestSchema, _request => ({ | ||
| action: 'accept', | ||
|
|
@@ -274,7 +292,10 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo | |
| } | ||
| ); | ||
|
|
||
| const client = new Client({ name: 'test-client', version: '1.0.0' }, { capabilities: { elicitation: {} } }); | ||
| const client = new Client( | ||
| { name: 'test-client', version: '1.0.0' }, | ||
| { capabilities: { elicitation: {} }, jsonSchemaValidator: validatorProvider } | ||
| ); | ||
|
|
||
| client.setRequestHandler(ElicitRequestSchema, _request => ({ | ||
| action: 'accept', | ||
|
|
@@ -307,7 +328,10 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo | |
| } | ||
| ); | ||
|
|
||
| const client = new Client({ name: 'test-client', version: '1.0.0' }, { capabilities: { elicitation: {} } }); | ||
| const client = new Client( | ||
| { name: 'test-client', version: '1.0.0' }, | ||
| { capabilities: { elicitation: {} }, jsonSchemaValidator: validatorProvider } | ||
| ); | ||
|
|
||
| client.setRequestHandler(ElicitRequestSchema, _request => ({ | ||
| action: 'accept', | ||
|
|
@@ -340,7 +364,10 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo | |
| } | ||
| ); | ||
|
|
||
| const client = new Client({ name: 'test-client', version: '1.0.0' }, { capabilities: { elicitation: {} } }); | ||
| const client = new Client( | ||
| { name: 'test-client', version: '1.0.0' }, | ||
| { capabilities: { elicitation: {} }, jsonSchemaValidator: validatorProvider } | ||
| ); | ||
|
|
||
| client.setRequestHandler(ElicitRequestSchema, _request => ({ | ||
| action: 'accept', | ||
|
|
@@ -374,7 +401,10 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo | |
| } | ||
| ); | ||
|
|
||
| const client = new Client({ name: 'test-client', version: '1.0.0' }, { capabilities: { elicitation: {} } }); | ||
| const client = new Client( | ||
| { name: 'test-client', version: '1.0.0' }, | ||
| { capabilities: { elicitation: {} }, jsonSchemaValidator: validatorProvider } | ||
| ); | ||
|
|
||
| client.setRequestHandler(ElicitRequestSchema, _request => ({ | ||
| action: 'decline' | ||
|
|
@@ -408,7 +438,10 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo | |
| } | ||
| ); | ||
|
|
||
| const client = new Client({ name: 'test-client', version: '1.0.0' }, { capabilities: { elicitation: {} } }); | ||
| const client = new Client( | ||
| { name: 'test-client', version: '1.0.0' }, | ||
| { capabilities: { elicitation: {} }, jsonSchemaValidator: validatorProvider } | ||
|
||
| ); | ||
|
|
||
| client.setRequestHandler(ElicitRequestSchema, _request => ({ | ||
| action: 'cancel' | ||
|
|
@@ -609,6 +642,72 @@ function testElicitationFlow(validatorProvider: typeof ajvProvider | typeof cfWo | |
| }); | ||
| }); | ||
|
|
||
| test(`${validatorName}: should default missing fields from schema defaults`, async () => { | ||
| const server = new Server( | ||
| { name: 'test-server', version: '1.0.0' }, | ||
| { | ||
| capabilities: {}, | ||
| jsonSchemaValidator: validatorProvider | ||
| } | ||
| ); | ||
|
|
||
| const client = new Client( | ||
| { name: 'test-client', version: '1.0.0' }, | ||
| { | ||
| capabilities: { | ||
| elicitation: { | ||
| applyDefaults: true | ||
| } | ||
| } | ||
| } | ||
| ); | ||
|
|
||
| // Client returns no values; SDK should apply defaults automatically (and validate) | ||
| client.setRequestHandler(ElicitRequestSchema, request => { | ||
| expect(request.params.requestedSchema).toEqual({ | ||
| type: 'object', | ||
| properties: { | ||
| subscribe: { type: 'boolean', default: true }, | ||
| nickname: { type: 'string', default: 'Guest' }, | ||
| age: { type: 'integer', minimum: 0, maximum: 150, default: 18 }, | ||
| color: { type: 'string', enum: ['red', 'green'], default: 'green' } | ||
| }, | ||
| required: ['subscribe', 'nickname', 'age', 'color'] | ||
| }); | ||
| return { | ||
| action: 'accept', | ||
| content: {} | ||
| }; | ||
| }); | ||
|
|
||
| const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); | ||
| await Promise.all([client.connect(clientTransport), server.connect(serverTransport)]); | ||
|
|
||
| const result = await server.elicitInput({ | ||
| message: 'Provide your preferences', | ||
| requestedSchema: { | ||
| type: 'object', | ||
| properties: { | ||
| subscribe: { type: 'boolean', default: true }, | ||
| nickname: { type: 'string', default: 'Guest' }, | ||
| age: { type: 'integer', minimum: 0, maximum: 150, default: 18 }, | ||
| color: { type: 'string', enum: ['red', 'green'], default: 'green' } | ||
| }, | ||
| required: ['subscribe', 'nickname', 'age', 'color'] | ||
| } | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| action: 'accept', | ||
| content: { | ||
| subscribe: true, | ||
| nickname: 'Guest', | ||
| age: 18, | ||
| color: 'green' | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| test(`${validatorName}: should reject invalid email format`, async () => { | ||
| const server = new Server( | ||
| { name: 'test-server', version: '1.0.0' }, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove