forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMCPIntroView.swift
More file actions
184 lines (166 loc) · 6.3 KB
/
MCPIntroView.swift
File metadata and controls
184 lines (166 loc) · 6.3 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import Client
import Foundation
import Logger
import SharedUIComponents
import SwiftUI
struct MCPIntroView: View {
var exampleConfig: String {
"""
{
"servers": {
"my-mcp-server": {
"type": "stdio",
"command": "my-command",
"args": [],
"env": {
"TOKEN": "my_token"
}
}
}
}
"""
}
@State private var isExpanded = true
@Binding private var isMCPFFEnabled: Bool
public init(isExpanded: Bool = true, isMCPFFEnabled: Binding<Bool>) {
self.isExpanded = isExpanded
self._isMCPFFEnabled = isMCPFFEnabled
}
var body: some View {
VStack(alignment: .leading, spacing: 8) {
if !isMCPFFEnabled {
GroupBox {
HStack(alignment: .top, spacing: 8) {
Image(systemName: "info.circle.fill")
.font(.body)
.foregroundColor(.gray)
Text(
"MCP servers are disabled by your organization’s policy. To enable them, please contact your administrator. [Get More Info about Copilot policies](https://docs.github.com/en/copilot/how-tos/administer-copilot/manage-for-organization/manage-policies)"
)
}
}
.groupBoxStyle(
CardGroupBoxStyle(
backgroundColor: Color(nsColor: .textBackgroundColor)
)
)
}
GroupBox(
label: Text("Model Context Protocol (MCP) Configuration")
.fontWeight(.bold)
) {
Text(
"MCP is an open standard that connects AI models to external tools. In Xcode, it enhances GitHub Copilot's agent mode by connecting to any MCP server and integrating its tools into your workflow. [Learn More](https://modelcontextprotocol.io/introduction)"
)
}.groupBoxStyle(CardGroupBoxStyle())
if isMCPFFEnabled {
DisclosureGroup(isExpanded: $isExpanded) {
exampleConfigView()
} label: {
sectionHeader()
}
.padding(.horizontal, 0)
.padding(.vertical, 10)
HStack(spacing: 8) {
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(.borderedProminent)
.help("Configure your MCP server")
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")
}
}
}
}
@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(4)
.overlay(
RoundedRectangle(cornerRadius: 4)
.inset(by: 0.5)
.stroke(Color("GroupBoxStrokeColor"), lineWidth: 1)
)
}
@ViewBuilder
private func sectionHeader() -> some View {
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)
}
private func openConfigFile() {
let url = URL(fileURLWithPath: mcpConfigFilePath)
NSWorkspace.shared.open(url)
}
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)
}
}
#Preview {
MCPIntroView(isExpanded: true, isMCPFFEnabled: .constant(true))
.frame(width: 800)
}
#Preview {
MCPIntroView(isExpanded: true, isMCPFFEnabled: .constant(false))
.frame(width: 800)
}