Update Client.connect(transport:) to automatically send initialize request (#100)
* Update Client to automatically call initialize in connect * Make Client.connect(transport:) return value discardable * Fix example usage in README * Update example code in transports to remove initialize call * Deprecate initialize method * Update tests * Update README * Fix sampling tests * Fix race condition tests
This commit is contained in:
parent
3b505ee575
commit
a59b50bf5a
1 changed files with 302 additions and 106 deletions
14
README.md
14
README.md
|
|
@ -54,10 +54,7 @@ let client = Client(name: "MyApp", version: "1.0.0")
|
|||
|
||||
// Create a transport and connect
|
||||
let transport = StdioTransport()
|
||||
try await client.connect(transport: transport)
|
||||
|
||||
// Initialize the connection
|
||||
let result = try await client.initialize()
|
||||
let result = try await client.connect(transport: transport)
|
||||
|
||||
// Check server capabilities
|
||||
if result.capabilities.tools != nil {
|
||||
|
|
@ -65,6 +62,11 @@ if result.capabilities.tools != nil {
|
|||
}
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> The `Client.connect(transport:)` method returns the initialization result.
|
||||
> This return value is discardable,
|
||||
> so you can ignore it if you don't need to check server capabilities.
|
||||
|
||||
### Transport Options for Clients
|
||||
|
||||
#### Stdio Transport
|
||||
|
|
@ -278,7 +280,7 @@ Handle common client errors:
|
|||
|
||||
```swift
|
||||
do {
|
||||
let result = try await client.initialize()
|
||||
try await client.connect(transport: transport)
|
||||
// Success
|
||||
} catch let error as MCPError {
|
||||
print("MCP Error: \(error.localizedDescription)")
|
||||
|
|
@ -402,7 +404,7 @@ The server component allows your application to host model capabilities and resp
|
|||
```swift
|
||||
import MCP
|
||||
|
||||
// Initialize the server with capabilities
|
||||
// Create a server with given capabilities
|
||||
let server = Server(
|
||||
name: "MyModelServer",
|
||||
version: "1.0.0",
|
||||
|
|
|
|||
Loading…
Reference in a new issue