-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathCopilotMCPToolManager.swift
More file actions
39 lines (32 loc) · 1.44 KB
/
CopilotMCPToolManager.swift
File metadata and controls
39 lines (32 loc) · 1.44 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
import Foundation
public extension Notification.Name {
static let gitHubCopilotMCPToolsDidChange = Notification
.Name("com.github.CopilotForXcode.CopilotMCPToolsDidChange")
}
public class CopilotMCPToolManager {
private static var availableMCPServerTools: [MCPServerToolsCollection] = []
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 clearMCPTools() {
availableMCPServerTools = []
DispatchQueue.main.async {
NotificationCenter.default.post(name: .gitHubCopilotMCPToolsDidChange, object: nil)
}
}
}