-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathCopilotMCPToolManager.swift
More file actions
51 lines (42 loc) · 2.02 KB
/
CopilotMCPToolManager.swift
File metadata and controls
51 lines (42 loc) · 2.02 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
import Foundation
import Logger
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 {
Logger.client.info("Notify about MCP tools change: \(getToolsSummary())")
DistributedNotificationCenter.default().post(name: .gitHubCopilotMCPToolsDidChange, object: nil)
}
}
private static func getToolsSummary() -> String {
var summary = ""
guard let tools = availableMCPServerTools else { return summary }
for server in tools {
summary += "Server: \(server.name) with \(server.tools.count) tools (\(server.tools.filter { $0._status == .enabled }.count) enabled, \(server.tools.filter { $0._status == .disabled }.count) disabled). "
}
return summary
}
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 != nil && !availableMCPServerTools!.isEmpty
}
public static func clearMCPTools() {
availableMCPServerTools = []
DispatchQueue.main.async {
DistributedNotificationCenter.default().post(name: .gitHubCopilotMCPToolsDidChange, object: nil)
}
}
}