-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(elicitation): Add URL elicitation support. SEP-1036 #994
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
Open
pbezglasny
wants to merge
5
commits into
modelcontextprotocol:main
Choose a base branch
from
pbezglasny:url-elicitation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+968
−23
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8c135fb
feat(elicitation): Add URL elicitation support. SEP-1036
pbezglasny 108631c
Update client/src/components/ElicitationUrlRequest.tsx
pbezglasny 1cfd1eb
Update client/src/components/ElicitationUrlRequest.tsx
pbezglasny f88e21a
Update client/src/components/ElicitationUrlRequest.tsx
pbezglasny 766a4f9
Update client/src/components/ElicitationUrlRequest.tsx
pbezglasny 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
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,165 @@ | ||
| import { | ||
| ElicitationResponse, | ||
| PendingElicitationRequest, | ||
| UrlElicitationRequestData, | ||
| } from "@/components/ElicitationTab.tsx"; | ||
| import JsonView from "@/components/JsonView.tsx"; | ||
| import { Button } from "@/components/ui/button.tsx"; | ||
| import { CheckCheck, Copy } from "lucide-react"; | ||
| import useCopy from "@/lib/hooks/useCopy.ts"; | ||
| import { toast } from "@/lib/hooks/useToast.ts"; | ||
|
|
||
| export type ElicitationUrlRequestProps = { | ||
| request: PendingElicitationRequest & { | ||
| request: UrlElicitationRequestData; | ||
| }; | ||
| onResolve: (id: number, response: ElicitationResponse) => void; | ||
| }; | ||
|
|
||
| const ElicitationUrlRequest = ({ | ||
| request, | ||
| onResolve, | ||
| }: ElicitationUrlRequestProps) => { | ||
| const { copied, setCopied } = useCopy(); | ||
|
|
||
| const parsedUrl = (() => { | ||
| try { | ||
| return new URL(request.request.url); | ||
| } catch { | ||
| return null; | ||
| } | ||
| })(); | ||
|
|
||
| const handleAcceptAndOpen = () => { | ||
| if (!parsedUrl) { | ||
| return; | ||
| } | ||
|
|
||
pbezglasny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| window.open(parsedUrl.href, "_blank", "noopener,noreferrer"); | ||
|
|
||
| onResolve(request.id, { | ||
| action: "accept", | ||
| }); | ||
| }; | ||
|
|
||
| const handleAccept = () => { | ||
| onResolve(request.id, { | ||
| action: "accept", | ||
| }); | ||
| }; | ||
|
|
||
| const handleDecline = () => { | ||
| onResolve(request.id, { action: "decline" }); | ||
| }; | ||
|
|
||
| const handleCancel = () => { | ||
| onResolve(request.id, { action: "cancel" }); | ||
| }; | ||
|
|
||
| const warnings = (() => { | ||
| if (!parsedUrl) { | ||
| return []; | ||
| } | ||
|
|
||
| const warnings: string[] = []; | ||
|
|
||
| if (parsedUrl.protocol !== "https:") { | ||
| warnings.push("Not HTTPS protocol"); | ||
| } | ||
|
|
||
| if (parsedUrl.hostname.includes("xn--")) { | ||
| warnings.push("This URL contains internationalized (non-ASCII) characters"); | ||
| } | ||
| return warnings; | ||
| })(); | ||
|
|
||
| const domain = (() => { | ||
| if (parsedUrl) { | ||
| return parsedUrl.hostname; | ||
| } | ||
| console.error("Invalid URL in elicitation request."); | ||
| return "Invalid URL"; | ||
| })(); | ||
|
|
||
| return ( | ||
| <div | ||
| data-testid="elicitation-request" | ||
| className="flex gap-4 p-4 border rounded-lg space-y-4" | ||
pbezglasny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| > | ||
| <div className="flex-1 bg-gray-50 dark:bg-gray-800 dark:text-gray-100 p-2 rounded"> | ||
| <div className="space-y-2"> | ||
| <div className="mt-2"> | ||
| <h5 className="text-xs font-medium mb-1">Request Schema:</h5> | ||
| <JsonView | ||
| data={JSON.stringify( | ||
| request.request, | ||
| ["message", "url", "elicitationId"], | ||
| 2, | ||
| )} | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="flex-1 space-y-6"> | ||
| <div className="space-y-3"> | ||
| {warnings.length > 0 && | ||
| warnings.map((msg, index) => ( | ||
| <div | ||
| key={index} | ||
| className="bg-yellow-100 border-l-4 border-yellow-500 p-2 text-xs text-yellow-700 dark:bg-yellow-900 dark:text-yellow-200" | ||
| > | ||
| {msg} | ||
| </div> | ||
| ))} | ||
| <p className="text-sm">{request.request.message}</p> | ||
| <p className="text-sm font-semibold">Domain: {domain}</p> | ||
| <p className="text-xs text-gray-600"> | ||
pbezglasny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Full URL: {request.request.url} | ||
| </p> | ||
| </div> | ||
| <div className="flex space-x-2"> | ||
pbezglasny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <Button | ||
| type="button" | ||
| onClick={handleAcceptAndOpen} | ||
| disabled={!parsedUrl} | ||
| > | ||
| Accept and open | ||
| </Button> | ||
| <Button type="button" onClick={handleAccept}> | ||
| Accept | ||
| </Button> | ||
| <Button type="button" variant="outline" onClick={handleDecline}> | ||
| Decline | ||
| </Button> | ||
| <Button type="button" variant="outline" onClick={handleCancel}> | ||
| Cancel | ||
| </Button> | ||
| <Button | ||
pbezglasny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| type="button" | ||
| onClick={async () => { | ||
| try { | ||
| await navigator.clipboard.writeText(request.request.url); | ||
| setCopied(true); | ||
| } catch (error) { | ||
| toast({ | ||
| title: "Error", | ||
| description: `There was an error copying url to the clipboard: ${error instanceof Error ? error.message : String(error)}`, | ||
| }); | ||
| } | ||
| }} | ||
| > | ||
| {copied ? ( | ||
| <CheckCheck className="h-4 w-4 mr-2 dark:text-green-700 text-green-600" /> | ||
| ) : ( | ||
| <Copy className="h-4 w-4 mr-2" /> | ||
| )} | ||
| Copy URL | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default ElicitationUrlRequest; | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.