-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathMCPRegistryURLSheet.swift
More file actions
68 lines (60 loc) · 2.19 KB
/
MCPRegistryURLSheet.swift
File metadata and controls
68 lines (60 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import GitHubCopilotService
import SwiftUI
struct MCPRegistryURLSheet: View {
@AppStorage(\.mcpRegistryURL) private var mcpRegistryURL
@AppStorage(\.mcpRegistryURLHistory) private var mcpRegistryURLHistory
@Environment(\.dismiss) private var dismiss
@State private var originalMcpRegistryURL: String = ""
@State private var isFormValid: Bool = true
let onURLUpdated: (() -> Void)?
init(onURLUpdated: (() -> Void)? = nil) {
self.onURLUpdated = onURLUpdated
}
var body: some View {
Form {
VStack(alignment: .center, spacing: 20) {
HStack(alignment: .center) {
Spacer()
Text("MCP Registry URL").font(.headline)
Spacer()
AdaptiveHelpLink(action: openHelpLink)
}
VStack(alignment: .leading, spacing: 4) {
MCPRegistryURLInputField(
urlText: $originalMcpRegistryURL,
isSheet: true,
onValidationChange: { isValid in
isFormValid = isValid
}
)
}
HStack(spacing: 8) {
Spacer()
Button("Cancel", role: .cancel) { dismiss() }
Button("Update") {
// Check if URL changed before updating
if originalMcpRegistryURL != mcpRegistryURL {
mcpRegistryURL = originalMcpRegistryURL
onURLUpdated?()
}
dismiss()
}
.buttonStyle(.borderedProminent)
.disabled(!isFormValid)
}
}
.textFieldStyle(.plain)
.multilineTextAlignment(.trailing)
.padding(20)
}
.onAppear {
loadExistingURL()
}
}
private func loadExistingURL() {
originalMcpRegistryURL = mcpRegistryURL
}
private func openHelpLink() {
NSWorkspace.shared.open(URL(string: "https://registry.mcpservers.org")!)
}
}