@@ -168,7 +168,8 @@ public actor Client {
168
168
}
169
169
170
170
/// Connect to the server using the given transport
171
- public func connect( transport: any Transport ) async throws {
171
+ @discardableResult
172
+ public func connect( transport: any Transport ) async throws -> Initialize . Result {
172
173
self . connection = transport
173
174
try await self . connection? . connect ( )
174
175
@@ -217,6 +218,9 @@ public actor Client {
217
218
} while true
218
219
await self . logger? . info ( " Client message handling loop task is terminating. " )
219
220
}
221
+
222
+ // Automatically initialize after connecting
223
+ return try await _initialize ( )
220
224
}
221
225
222
226
/// Disconnect the client and cancel all pending requests
@@ -480,7 +484,23 @@ public actor Client {
480
484
481
485
// MARK: - Lifecycle
482
486
487
+ /// Initialize the connection with the server.
488
+ ///
489
+ /// - Important: This method is deprecated. Initialization now happens automatically
490
+ /// when calling `connect(transport:)`. You should use that method instead.
491
+ ///
492
+ /// - Returns: The server's initialization response containing capabilities and server info
493
+ @available (
494
+ * , deprecated,
495
+ message:
496
+ " Initialization now happens automatically during connect. Use connect(transport:) instead. "
497
+ )
483
498
public func initialize( ) async throws -> Initialize . Result {
499
+ return try await _initialize ( )
500
+ }
501
+
502
+ /// Internal initialization implementation
503
+ private func _initialize( ) async throws -> Initialize . Result {
484
504
let request = Initialize . request (
485
505
. init(
486
506
protocolVersion: Version . latest,
0 commit comments