Send initialized notification from client instead of server (#85)

This commit is contained in:
Mattt 2025-04-21 14:43:33 -07:00 • committed by GitHub
commit 25dee3bb4c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 130 additions and 12 deletions

View file

@ -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
}

View file

@ -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)
}
}
}
}