Send initialized notification from client instead of server (#85)
This commit is contained in:
parent
29aa74d137
commit
25dee3bb4c
2 changed files with 130 additions and 12 deletions
|
|
@ -249,6 +249,16 @@ public actor Client {
|
|||
return self
|
||||
}
|
||||
|
||||
/// Send a notification to the server
|
||||
public func notify<N: Notification>(_ notification: Message<N>) async throws {
|
||||
guard let connection = connection else {
|
||||
throw MCPError.internalError("Client connection not initialized")
|
||||
}
|
||||
|
||||
let notificationData = try encoder.encode(notification)
|
||||
try await connection.send(notificationData)
|
||||
}
|
||||
|
||||
// MARK: - Requests
|
||||
|
||||
/// Send a request and receive its response
|
||||
|
|
@ -454,6 +464,8 @@ public actor Client {
|
|||
self.serverVersion = result.protocolVersion
|
||||
self.instructions = result.instructions
|
||||
|
||||
try await notify(InitializedNotification.message())
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -496,12 +496,6 @@ public actor Server {
|
|||
protocolVersion: params.protocolVersion
|
||||
)
|
||||
|
||||
// Send initialized notification after a short delay
|
||||
Task {
|
||||
try? await Task.sleep(for: .milliseconds(10))
|
||||
try? await self.notify(InitializedNotification.message())
|
||||
}
|
||||
|
||||
return Initialize.Result(
|
||||
protocolVersion: Version.latest,
|
||||
capabilities: await self.capabilities,
|
||||
|
|
@ -571,4 +565,4 @@ extension Server.Batch.Item: Codable {
|
|||
try notification.encode(to: encoder)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue