@@ -8,8 +8,6 @@ import MCPInterface
88
99public actor MCPClient : MCPClientInterface {
1010
11- // MARK: Lifecycle
12-
1311 /// Creates a MCP client and connects to the server through the provided transport.
1412 /// The methods completes after connecting to the server.
1513 public init (
@@ -19,7 +17,7 @@ public actor MCPClient: MCPClientInterface {
1917 async throws {
2018 try await self . init (
2119 capabilities: capabilities,
22- connection: try MCPClientConnection (
20+ connection: MCPClientConnection (
2321 info: info,
2422 capabilities: ClientCapabilities (
2523 experimental: nil , // TODO: support experimental requests
@@ -47,31 +45,29 @@ public actor MCPClient: MCPClientInterface {
4745 Task { try await self . updateResourceTemplates ( ) }
4846 }
4947
50- // MARK: Public
51-
5248 public private( set) var serverInfo : ServerInfo
5349
5450 public var tools : ReadOnlyCurrentValueSubject < CapabilityStatus < [ Tool ] > , Never > {
5551 get async {
56- await . init( _tools. compactMap { $0 } . removeDuplicates ( ) . eraseToAnyPublisher ( ) )
52+ await . init( _tools. compactMap ( \ . self ) . removeDuplicates ( ) . eraseToAnyPublisher ( ) )
5753 }
5854 }
5955
6056 public var prompts : ReadOnlyCurrentValueSubject < CapabilityStatus < [ Prompt ] > , Never > {
6157 get async {
62- await . init( _prompts. compactMap { $0 } . removeDuplicates ( ) . eraseToAnyPublisher ( ) )
58+ await . init( _prompts. compactMap ( \ . self ) . removeDuplicates ( ) . eraseToAnyPublisher ( ) )
6359 }
6460 }
6561
6662 public var resources : ReadOnlyCurrentValueSubject < CapabilityStatus < [ Resource ] > , Never > {
6763 get async {
68- await . init( _resources. compactMap { $0 } . removeDuplicates ( ) . eraseToAnyPublisher ( ) )
64+ await . init( _resources. compactMap ( \ . self ) . removeDuplicates ( ) . eraseToAnyPublisher ( ) )
6965 }
7066 }
7167
7268 public var resourceTemplates : ReadOnlyCurrentValueSubject < CapabilityStatus < [ ResourceTemplate ] > , Never > {
7369 get async {
74- await . init( _resourceTemplates. compactMap { $0 } . removeDuplicates ( ) . eraseToAnyPublisher ( ) )
70+ await . init( _resourceTemplates. compactMap ( \ . self ) . removeDuplicates ( ) . eraseToAnyPublisher ( ) )
7571 }
7672 }
7773
@@ -99,7 +95,7 @@ public actor MCPClient: MCPClientInterface {
9995 }
10096 // If there has been an error during the execution, throw it
10197 if result. isError == true {
102- let errors = result. content. compactMap { $0 . text } . map { CallToolResult . ExecutionError ( text: $0. text) }
98+ let errors = result. content. compactMap ( \ . text) . map { CallToolResult . ExecutionError ( text: $0. text) }
10399 throw MCPClientError . toolCallError ( executionErrors: errors)
104100 }
105101 return result
@@ -119,12 +115,8 @@ public actor MCPClient: MCPClientInterface {
119115 return try await connection. readResource ( . init( uri: uri) )
120116 }
121117
122- // MARK: Internal
123-
124118 let connection : MCPClientConnectionInterface
125119
126- // MARK: Private
127-
128120 private let capabilities : ClientCapabilityHandlers
129121
130122 private let _tools = CurrentValueSubject < CapabilityStatus < [ Tool ] > ? , Never > ( nil )
@@ -185,7 +177,7 @@ public actor MCPClient: MCPClientInterface {
185177 private func startListeningToRequests( ) async {
186178 let requests = await connection. requestsToHandle
187179 Task { [ weak self] in
188- for await (request, completion) in requests {
180+ for await (request, completion) in requests {
189181 guard let self else {
190182 completion ( . failure( . init(
191183 code: JRPCErrorCodes . internalError. rawValue,
@@ -210,7 +202,7 @@ public actor MCPClient: MCPClientInterface {
210202 {
211203 if let handler {
212204 do {
213- return . success ( try await handler ( params) )
205+ return try await . success ( handler ( params) )
214206 } catch {
215207 return . failure( . init(
216208 code: JRPCErrorCodes . internalError. rawValue,
0 commit comments