-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathCopilotMCPToolManager.swift
More file actions
55 lines (46 loc) · 2.06 KB
/
CopilotMCPToolManager.swift
File metadata and controls
55 lines (46 loc) · 2.06 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
import Foundation
public extension Notification.Name {
static let gitHubCopilotMCPToolsDidChange = Notification
.Name("com.github.CopilotForXcode.CopilotMCPToolsDidChange")
}
public class CopilotMCPToolManager {
private static var availableMCPServerTools: [MCPServerToolsCollection] = []
private static var updatedMCPToolsStatusParams: UpdateMCPToolsStatusParams = .init(servers: [])
public static func updateMCPTools(_ serverToolsCollections: [MCPServerToolsCollection]) {
let sortedMCPServerTools = serverToolsCollections.sorted(by: { $0.name.lowercased() < $1.name.lowercased() })
guard sortedMCPServerTools != availableMCPServerTools else { return }
availableMCPServerTools = sortedMCPServerTools
DispatchQueue.main.async {
NotificationCenter.default.post(name: .gitHubCopilotMCPToolsDidChange, object: nil)
}
}
public static func getAvailableMCPTools() -> [MCPTool] {
// Flatten all tools from all servers into a single array
return availableMCPServerTools.flatMap { $0.tools }
}
public static func getAvailableMCPServerToolsCollections() -> [MCPServerToolsCollection] {
return availableMCPServerTools
}
public static func hasMCPTools() -> Bool {
return !availableMCPServerTools.isEmpty
}
public static func updateMCPToolsStatus(_ servers: [UpdateMCPToolsStatusServerCollection]) {
updatedMCPToolsStatusParams = .init(servers: servers)
DispatchQueue.main.async {
NotificationCenter.default
.post(
name: .gitHubCopilotShouldUpdateMCPToolsStatus,
object: nil
)
}
}
public static func getUpdatedMCPToolsStatusParams() -> UpdateMCPToolsStatusParams {
return updatedMCPToolsStatusParams
}
public static func clearMCPTools() {
availableMCPServerTools = []
DispatchQueue.main.async {
NotificationCenter.default.post(name: .gitHubCopilotMCPToolsDidChange, object: nil)
}
}
}