Skip to content

Commit cda3acf

Browse files
committed
Inline JSONDecoder extension
1 parent 88a2400 commit cda3acf

File tree

2 files changed

+2
-14
lines changed

2 files changed

+2
-14
lines changed

Sources/MCP/Base/Value.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,3 @@ extension String {
400400
}
401401
}
402402
}
403-
404-
// MARK: - Decode specific type from Value
405-
406-
extension JSONDecoder {
407-
public func decode<T: Decodable>(_ type: T.Type, from value: Value) throws -> T {
408-
guard let data = try? JSONEncoder().encode(value) else {
409-
throw DecodingError.dataCorrupted(
410-
DecodingError.Context(codingPath: [], debugDescription: "Failed to encode value"))
411-
}
412-
413-
return try self.decode(T.self, from: data)
414-
}
415-
}

Sources/MCP/Client/Client.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public actor Client {
106106
if let typedValue = value as? T {
107107
request.continuation.resume(returning: typedValue)
108108
} else if let value = value as? Value,
109-
let decoded = try? JSONDecoder().decode(T.self, from: value)
109+
let data = try? JSONEncoder().encode(value),
110+
let decoded = try? JSONDecoder().decode(T.self, from: data)
110111
{
111112
request.continuation.resume(returning: decoded)
112113
} else {

0 commit comments

Comments
 (0)