Skip to content

Commit 7d5855e

Browse files
committed
Format and make Result properties public again
1 parent dc00a8c commit 7d5855e

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

Sources/MCP/Base/Lifecycle.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public enum Initialize: Method {
4242
}
4343

4444
public struct Result: Hashable, Codable, Sendable {
45-
let protocolVersion: String
46-
let capabilities: Server.Capabilities
47-
let serverInfo: Server.Info
48-
let instructions: String?
49-
var _meta: [String: Value]?
50-
var extraFields: [String: Value]?
45+
public let protocolVersion: String
46+
public let capabilities: Server.Capabilities
47+
public let serverInfo: Server.Info
48+
public let instructions: String?
49+
public var _meta: [String: Value]?
50+
public var extraFields: [String: Value]?
5151

5252
public init(
5353
protocolVersion: String,
@@ -78,7 +78,9 @@ public enum Initialize: Method {
7878

7979
var dynamicContainer = encoder.container(keyedBy: DynamicCodingKey.self)
8080
try encodeMeta(_meta, to: &dynamicContainer)
81-
try encodeExtraFields(extraFields, to: &dynamicContainer, excluding: Set(CodingKeys.allCases.map(\.rawValue)))
81+
try encodeExtraFields(
82+
extraFields, to: &dynamicContainer,
83+
excluding: Set(CodingKeys.allCases.map(\.rawValue)))
8284
}
8385

8486
public init(from decoder: Decoder) throws {
@@ -90,7 +92,8 @@ public enum Initialize: Method {
9092

9193
let dynamicContainer = try decoder.container(keyedBy: DynamicCodingKey.self)
9294
_meta = try decodeMeta(from: dynamicContainer)
93-
extraFields = try decodeExtraFields(from: dynamicContainer, excluding: Set(CodingKeys.allCases.map(\.rawValue)))
95+
extraFields = try decodeExtraFields(
96+
from: dynamicContainer, excluding: Set(CodingKeys.allCases.map(\.rawValue)))
9497
}
9598
}
9699
}

Sources/MCP/Base/Messages.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,12 @@ public struct Request<M: Method>: Hashable, Identifiable, Codable, Sendable {
123123
try container.encode(id, forKey: .id)
124124
try container.encode(method, forKey: .method)
125125
try container.encode(params, forKey: .params)
126-
126+
127127
// Encode _meta and extra fields, excluding JSON-RPC protocol fields
128128
var dynamicContainer = encoder.container(keyedBy: DynamicCodingKey.self)
129129
try encodeMeta(_meta, to: &dynamicContainer)
130-
try encodeExtraFields(extraFields, to: &dynamicContainer, excluding: Set(CodingKeys.allCases.map(\.rawValue)))
130+
try encodeExtraFields(
131+
extraFields, to: &dynamicContainer, excluding: Set(CodingKeys.allCases.map(\.rawValue)))
131132
}
132133
}
133134

@@ -172,7 +173,8 @@ extension Request {
172173

173174
let dynamicContainer = try decoder.container(keyedBy: DynamicCodingKey.self)
174175
_meta = try decodeMeta(from: dynamicContainer)
175-
extraFields = try decodeExtraFields(from: dynamicContainer, excluding: Set(CodingKeys.allCases.map(\.rawValue)))
176+
extraFields = try decodeExtraFields(
177+
from: dynamicContainer, excluding: Set(CodingKeys.allCases.map(\.rawValue)))
176178
}
177179
}
178180

@@ -254,17 +256,17 @@ public struct Response<M: Method>: Hashable, Identifiable, Codable, Sendable {
254256
}
255257

256258
public init(
257-
id: ID,
258-
result: M.Result,
259+
id: ID,
260+
result: M.Result,
259261
_meta: [String: Value]? = nil,
260262
extraFields: [String: Value]? = nil
261263
) {
262264
self.init(id: id, result: .success(result), _meta: _meta, extraFields: extraFields)
263265
}
264266

265267
public init(
266-
id: ID,
267-
error: MCPError,
268+
id: ID,
269+
error: MCPError,
268270
_meta: [String: Value]? = nil,
269271
extraFields: [String: Value]? = nil
270272
) {
@@ -285,11 +287,12 @@ public struct Response<M: Method>: Hashable, Identifiable, Codable, Sendable {
285287
case .failure(let error):
286288
try container.encode(error, forKey: .error)
287289
}
288-
290+
289291
// Encode _meta and extra fields, excluding JSON-RPC protocol fields
290292
var dynamicContainer = encoder.container(keyedBy: DynamicCodingKey.self)
291293
try encodeMeta(_meta, to: &dynamicContainer)
292-
try encodeExtraFields(extraFields, to: &dynamicContainer, excluding: Set(CodingKeys.allCases.map(\.rawValue)))
294+
try encodeExtraFields(
295+
extraFields, to: &dynamicContainer, excluding: Set(CodingKeys.allCases.map(\.rawValue)))
293296
}
294297

295298
public init(from decoder: Decoder) throws {
@@ -313,7 +316,8 @@ public struct Response<M: Method>: Hashable, Identifiable, Codable, Sendable {
313316

314317
let dynamicContainer = try decoder.container(keyedBy: DynamicCodingKey.self)
315318
_meta = try decodeMeta(from: dynamicContainer)
316-
extraFields = try decodeExtraFields(from: dynamicContainer, excluding: Set(CodingKeys.allCases.map(\.rawValue)))
319+
extraFields = try decodeExtraFields(
320+
from: dynamicContainer, excluding: Set(CodingKeys.allCases.map(\.rawValue)))
317321
}
318322
}
319323

Sources/MCP/Client/Sampling.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,19 +256,23 @@ public enum CreateSamplingMessage: Method {
256256

257257
var dynamicContainer = encoder.container(keyedBy: DynamicCodingKey.self)
258258
try encodeMeta(_meta, to: &dynamicContainer)
259-
try encodeExtraFields(extraFields, to: &dynamicContainer, excluding: Set(CodingKeys.allCases.map(\.rawValue)))
259+
try encodeExtraFields(
260+
extraFields, to: &dynamicContainer,
261+
excluding: Set(CodingKeys.allCases.map(\.rawValue)))
260262
}
261263

262264
public init(from decoder: Decoder) throws {
263265
let container = try decoder.container(keyedBy: CodingKeys.self)
264266
model = try container.decode(String.self, forKey: .model)
265-
stopReason = try container.decodeIfPresent(Sampling.StopReason.self, forKey: .stopReason)
267+
stopReason = try container.decodeIfPresent(
268+
Sampling.StopReason.self, forKey: .stopReason)
266269
role = try container.decode(Sampling.Message.Role.self, forKey: .role)
267270
content = try container.decode(Sampling.Message.Content.self, forKey: .content)
268271

269272
let dynamicContainer = try decoder.container(keyedBy: DynamicCodingKey.self)
270273
_meta = try decodeMeta(from: dynamicContainer)
271-
extraFields = try decodeExtraFields(from: dynamicContainer, excluding: Set(CodingKeys.allCases.map(\.rawValue)))
274+
extraFields = try decodeExtraFields(
275+
from: dynamicContainer, excluding: Set(CodingKeys.allCases.map(\.rawValue)))
272276
}
273277
}
274278
}

0 commit comments

Comments
 (0)