forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMCPManualInstallView.swift
More file actions
160 lines (147 loc) · 5.65 KB
/
MCPManualInstallView.swift
File metadata and controls
160 lines (147 loc) · 5.65 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import AppKit
import Logger
import SharedUIComponents
import SwiftUI
struct MCPManualInstallView: View {
@State private var isExpanded: Bool = false
var body: some View {
VStack(spacing: 0) {
DisclosureSettingsRow(
isExpanded: $isExpanded,
accessibilityLabel: { $0 ? "Collapse manual install section" : "Expand manual install section" },
title: { Text("Manual Install").font(.headline) },
subtitle: { Text("Add MCP Servers to power AI with tools for files, databases, and external APIs.") },
actions: {
HStack(spacing: 8) {
Button {
openMCPRunTimeLogFolder()
} label: {
HStack(spacing: 0) {
Image(systemName: "folder")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 12, height: 12, alignment: .center)
.padding(4)
Text("Open MCP Log Folder")
}
.conditionalFontWeight(.semibold)
}
.buttonStyle(.bordered)
.help("Open MCP Runtime Log Folder")
Button {
openConfigFile()
} label: {
HStack(spacing: 0) {
Image(systemName: "square.and.pencil")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 12, height: 12, alignment: .center)
.padding(4)
Text("Edit Config")
}
.conditionalFontWeight(.semibold)
}
.buttonStyle(.bordered)
.help("Configure your MCP server")
}
.padding(.vertical, 12)
}
)
if isExpanded {
VStack(alignment: .leading, spacing: 8) {
HStack(spacing: 8) {
Text("Example Configuration").foregroundColor(.primary.opacity(0.85))
CopyButton(
copy: {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(exampleConfig, forType: .string)
},
foregroundColor: .primary.opacity(0.85),
fontWeight: .semibold
)
.frame(width: 10, height: 10)
}
.padding(.leading, 4)
exampleConfigView()
}
.padding(.top, 8)
.padding([.leading, .trailing, .bottom], 20)
.background(QuaternarySystemFillColor.opacity(0.75))
.transition(.opacity.combined(with: .scale(scale: 1, anchor: .top)))
}
}
.cornerRadius(12)
.clipShape(RoundedRectangle(cornerRadius: 12))
.overlay(
RoundedRectangle(cornerRadius: 12)
.inset(by: 0.5)
.stroke(SecondarySystemFillColor, lineWidth: 1)
.animation(.easeInOut(duration: 0.3), value: isExpanded)
)
.animation(.easeInOut(duration: 0.3), value: isExpanded)
}
var exampleConfig: String {
"""
{
"servers": {
"my-mcp-server": {
"type": "stdio",
"command": "my-command",
"args": [],
"env": {
"TOKEN": "my_token"
}
}
}
}
"""
}
@ViewBuilder
private func exampleConfigView() -> some View {
Text(exampleConfig)
.font(.system(.body, design: .monospaced))
.padding(.horizontal, 16)
.padding(.top, 8)
.padding(.bottom, 6)
.frame(maxWidth: .infinity, alignment: .leading)
.background(
Color(nsColor: .textBackgroundColor).opacity(0.5)
)
.textSelection(.enabled)
.cornerRadius(6)
.overlay(
RoundedRectangle(cornerRadius: 6)
.inset(by: 0.5)
.stroke(Color("GroupBoxStrokeColor"), lineWidth: 1)
)
}
private func openMCPRunTimeLogFolder() {
let url = URL(
fileURLWithPath: FileLoggingLocation.mcpRuntimeLogsPath.description,
isDirectory: true
)
// Create directory if it doesn't exist
if !FileManager.default.fileExists(atPath: url.path) {
do {
try FileManager.default.createDirectory(
atPath: url.path,
withIntermediateDirectories: true,
attributes: nil
)
} catch {
Logger.client.error("Failed to create MCP runtime log folder: \(error)")
return
}
}
NSWorkspace.shared.open(url)
}
private func openConfigFile() {
let url = URL(fileURLWithPath: mcpConfigFilePath)
NSWorkspace.shared.open(url)
}
}
#Preview {
MCPManualInstallView()
.padding()
.frame(width: 900)
}