-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathGitHubCopilotRequest+MCP.swift
More file actions
172 lines (143 loc) · 4.92 KB
/
GitHubCopilotRequest+MCP.swift
File metadata and controls
172 lines (143 loc) · 4.92 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
import Foundation
import JSONRPC
import LanguageServerProtocol
public enum MCPServerStatus: String, Codable, Equatable, Hashable {
case running = "running"
case stopped = "stopped"
case error = "error"
}
public enum MCPToolStatus: String, Codable, Equatable, Hashable {
case enabled = "enabled"
case disabled = "disabled"
}
public struct InputSchema: Codable, Equatable, Hashable {
public var type: String = "object"
public var properties: [String: JSONValue]?
public init(properties: [String: JSONValue]? = nil) {
self.properties = properties
}
// Custom coding for handling `properties` as Any
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
type = try container.decode(String.self, forKey: .type)
if let propertiesData = try? container.decode(Data.self, forKey: .properties),
let props = try? JSONSerialization.jsonObject(with: propertiesData) as? [String: JSONValue] {
properties = props
}
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(type, forKey: .type)
if let props = properties,
let propertiesData = try? JSONSerialization.data(withJSONObject: props) {
try container.encode(propertiesData, forKey: .properties)
}
}
enum CodingKeys: String, CodingKey {
case type
case properties
}
}
public struct ToolAnnotations: Codable, Equatable, Hashable {
public var title: String?
public var readOnlyHint: Bool?
public var destructiveHint: Bool?
public var idempotentHint: Bool?
public var openWorldHint: Bool?
public init(
title: String? = nil,
readOnlyHint: Bool? = nil,
destructiveHint: Bool? = nil,
idempotentHint: Bool? = nil,
openWorldHint: Bool? = nil
) {
self.title = title
self.readOnlyHint = readOnlyHint
self.destructiveHint = destructiveHint
self.idempotentHint = idempotentHint
self.openWorldHint = openWorldHint
}
enum CodingKeys: String, CodingKey {
case title
case readOnlyHint
case destructiveHint
case idempotentHint
case openWorldHint
}
}
public struct MCPTool: Codable, Equatable, Hashable {
public let name: String
public let description: String?
public let _status: MCPToolStatus
public let inputSchema: InputSchema
public var annotations: ToolAnnotations?
public init(
name: String,
description: String? = nil,
_status: MCPToolStatus,
inputSchema: InputSchema,
annotations: ToolAnnotations? = nil
) {
self.name = name
self.description = description
self._status = _status
self.inputSchema = inputSchema
self.annotations = annotations
}
enum CodingKeys: String, CodingKey {
case name
case description
case _status
case inputSchema
case annotations
}
}
public struct MCPServerToolsCollection: Codable, Equatable, Hashable {
public let name: String
public let status: MCPServerStatus
public let tools: [MCPTool]
public let error: String?
public init(name: String, status: MCPServerStatus, tools: [MCPTool], error: String? = nil) {
self.name = name
self.status = status
self.tools = tools
self.error = error
}
}
public struct GetAllToolsParams: Codable, Hashable {
public var servers: [MCPServerToolsCollection]
public static func decode(fromParams params: JSONValue?) -> GetAllToolsParams? {
try? JSONDecoder().decode(Self.self, from: (try? JSONEncoder().encode(params)) ?? Data())
}
}
public struct UpdatedMCPToolsStatus: Codable, Hashable {
public var name: String
public var status: MCPToolStatus
public init(name: String, status: MCPToolStatus) {
self.name = name
self.status = status
}
}
public struct UpdateMCPToolsStatusServerCollection: Codable, Hashable {
public var name: String
public var tools: [UpdatedMCPToolsStatus]
public init(name: String, tools: [UpdatedMCPToolsStatus]) {
self.name = name
self.tools = tools
}
}
public struct UpdateMCPToolsStatusParams: Codable, Hashable {
public var servers: [UpdateMCPToolsStatusServerCollection]
public init(servers: [UpdateMCPToolsStatusServerCollection]) {
self.servers = servers
}
}
public typealias CopilotMCPToolsRequest = JSONRPCRequest<GetAllToolsParams>
public struct MCPOAuthRequestParams: Codable, Hashable {
public var mcpServer: String
public var authLabel: String
}
public struct MCPOAuthResponse: Codable, Hashable {
public var confirm: Bool
}
public typealias MCPOAuthRequest = JSONRPCRequest<MCPOAuthRequestParams>