-
Notifications
You must be signed in to change notification settings - Fork 133
feat(elicitation): add user consent through elicitation MCP-185 #551
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7f3ed9c
feat(elicitation): add user consent configuration through elicitation…
gagik faa2824
chore: remove redundant test
gagik 7cf9386
chore: add elicitation to helpers
gagik 80258d4
chore(tests): use actual integration structure
gagik 6c3e17a
chore: fix MongoDB tests
gagik 3425bb6
chore: fixup
gagik 896150c
chore: remove voids
gagik a19e2f0
chore: reformat
gagik f883282
chore: check for default message, use MCP schema type, tweak formatti…
gagik 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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type { ElicitRequest } from "@modelcontextprotocol/sdk/types.js"; | ||
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; | ||
|
||
export class Elicitation { | ||
private readonly server: McpServer["server"]; | ||
constructor({ server }: { server: McpServer["server"] }) { | ||
this.server = server; | ||
} | ||
|
||
/** | ||
* Checks if the client supports elicitation capabilities. | ||
* @returns True if the client supports elicitation, false otherwise. | ||
*/ | ||
public supportsElicitation(): boolean { | ||
const clientCapabilities = this.server.getClientCapabilities(); | ||
return clientCapabilities?.elicitation !== undefined; | ||
nirinchev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* Requests a boolean confirmation from the user. | ||
* @param message - The message to display to the user. | ||
* @returns True if the user confirms the action or the client does not support elicitation, false otherwise. | ||
*/ | ||
public async requestConfirmation(message: string): Promise<boolean> { | ||
if (!this.supportsElicitation()) { | ||
return true; | ||
} | ||
|
||
const result = await this.server.elicitInput({ | ||
message, | ||
requestedSchema: Elicitation.CONFIRMATION_SCHEMA, | ||
}); | ||
return result.action === "accept" && result.content?.confirmation === "Yes"; | ||
} | ||
|
||
/** | ||
* The schema for the confirmation question. | ||
* TODO: In the future would be good to use Zod 4's toJSONSchema() to generate the schema. | ||
*/ | ||
public static CONFIRMATION_SCHEMA: ElicitRequest["params"]["requestedSchema"] = { | ||
type: "object", | ||
properties: { | ||
confirmation: { | ||
type: "string", | ||
title: "Would you like to confirm?", | ||
description: "Would you like to confirm?", | ||
enum: ["Yes", "No"], | ||
enumNames: ["Yes, I confirm", "No, I do not confirm"], | ||
}, | ||
}, | ||
required: ["confirmation"], | ||
}; | ||
} |
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.
If one wants to be paranoid... there's might be a chance some client will claim it supports
elicitation
while not supporting it. Then this would likely make this tool a confusing no-op.That said this would be client's fault and one could unblock themselves by setting confirmation required tools to nothing.