|
| 1 | +<script lang="ts"> |
| 2 | + import { KeyRound } from '@lucide/svelte'; |
| 3 | + import * as AlertDialog from '$lib/components/ui/alert-dialog'; |
| 4 | + import type { MCPServerSettingsEntry } from '$lib/types'; |
| 5 | + import { mcpStore } from '$lib/stores/mcp.svelte'; |
| 6 | + import { BrowserMcpOAuthProvider } from '$lib/services/mcp-oauth.service'; |
| 7 | + import { McpServerIdentity } from '$lib/components/app/mcp'; |
| 8 | +
|
| 9 | + interface Props { |
| 10 | + open: boolean; |
| 11 | + server?: MCPServerSettingsEntry | null; |
| 12 | + onOpenChange?: (open: boolean) => void; |
| 13 | + } |
| 14 | +
|
| 15 | + let { open = $bindable(), server = null, onOpenChange }: Props = $props(); |
| 16 | +
|
| 17 | + let displayName = $derived(server ? mcpStore.getServerLabel(server) : 'this server'); |
| 18 | + let faviconUrl = $derived(server ? mcpStore.getServerFavicon(server.id) : null); |
| 19 | +
|
| 20 | + function handleOpenChange(newOpen: boolean) { |
| 21 | + open = newOpen; |
| 22 | + onOpenChange?.(newOpen); |
| 23 | + } |
| 24 | +
|
| 25 | + function handleAuthorize() { |
| 26 | + if (!server) return; |
| 27 | +
|
| 28 | + // Start the OAuth flow by opening a window and beginning authorization |
| 29 | + const authorizationWindow = window.open('about:blank', '_blank'); |
| 30 | + BrowserMcpOAuthProvider.beginInteractiveAuthorization(authorizationWindow); |
| 31 | +
|
| 32 | + // Trigger health check to complete the connection after OAuth |
| 33 | + mcpStore.runHealthCheck(server); |
| 34 | +
|
| 35 | + handleOpenChange(false); |
| 36 | + } |
| 37 | +</script> |
| 38 | + |
| 39 | +<AlertDialog.Root {open} onOpenChange={handleOpenChange}> |
| 40 | + <AlertDialog.Content> |
| 41 | + <AlertDialog.Header> |
| 42 | + <AlertDialog.Title class="flex items-center gap-2"> |
| 43 | + <KeyRound class="h-5 w-5 text-primary" /> |
| 44 | + |
| 45 | + Authorize MCP Server |
| 46 | + </AlertDialog.Title> |
| 47 | + |
| 48 | + <AlertDialog.Description> |
| 49 | + Would you like to authorize |
| 50 | + <span class="font-medium"> |
| 51 | + {displayName} |
| 52 | + </span> |
| 53 | + to connect using OAuth? |
| 54 | + </AlertDialog.Description> |
| 55 | + </AlertDialog.Header> |
| 56 | + |
| 57 | + {#if server} |
| 58 | + <div class="rounded-lg border bg-muted/30 p-3"> |
| 59 | + <McpServerIdentity |
| 60 | + {displayName} |
| 61 | + {faviconUrl} |
| 62 | + iconClass="h-6 w-6" |
| 63 | + iconRounded="rounded" |
| 64 | + nameClass="leading-5 text-sm font-medium" |
| 65 | + /> |
| 66 | + </div> |
| 67 | + {/if} |
| 68 | + |
| 69 | + <AlertDialog.Footer> |
| 70 | + <AlertDialog.Cancel onclick={() => handleOpenChange(false)}>Cancel</AlertDialog.Cancel> |
| 71 | + <AlertDialog.Action onclick={handleAuthorize}>Authorize</AlertDialog.Action> |
| 72 | + </AlertDialog.Footer> |
| 73 | + </AlertDialog.Content> |
| 74 | +</AlertDialog.Root> |
0 commit comments