Skip to content

Commit 69e45d5

Browse files
committed
Make Client.connect(transport:) return value discardable
1 parent 14567e7 commit 69e45d5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ if result.capabilities.tools != nil {
6262
}
6363
```
6464

65+
> [!NOTE]
66+
> The `Client.connect(transport:)` method returns the initialization result.
67+
> This return value is discardable,
68+
> so you can ignore it if you don't need to check server capabilities.
69+
6570
### Transport Options for Clients
6671

6772
#### Stdio Transport
@@ -71,7 +76,7 @@ For local subprocess communication:
7176
```swift
7277
// Create a stdio transport (simplest option)
7378
let transport = StdioTransport()
74-
let result = try await client.connect(transport: transport)
79+
try await client.connect(transport: transport)
7580
```
7681

7782
#### HTTP Transport
@@ -84,7 +89,7 @@ let transport = HTTPClientTransport(
8489
endpoint: URL(string: "http://localhost:8080")!,
8590
streaming: true // Enable Server-Sent Events for real-time updates
8691
)
87-
let result = try await client.connect(transport: transport)
92+
try await client.connect(transport: transport)
8893
```
8994

9095
### Tools
@@ -192,7 +197,7 @@ Handle common client errors:
192197

193198
```swift
194199
do {
195-
let result = try await client.initialize()
200+
try await client.connect()
196201
// Success
197202
} catch let error as MCPError {
198203
print("MCP Error: \(error.localizedDescription)")

Sources/MCP/Client/Client.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public actor Client {
168168
}
169169

170170
/// Connect to the server using the given transport
171+
@discardableResult
171172
public func connect(transport: any Transport) async throws -> Initialize.Result {
172173
self.connection = transport
173174
try await self.connection?.connect()

0 commit comments

Comments
 (0)