@@ -80,10 +80,8 @@ public class ClientOptions(
8080 * @param clientInfo Information about the client implementation (name, version).
8181 * @param options Configuration options for this client.
8282 */
83- public open class Client (
84- private val clientInfo : Implementation ,
85- options : ClientOptions = ClientOptions (),
86- ) : Protocol(options) {
83+ public open class Client (private val clientInfo : Implementation , options : ClientOptions = ClientOptions ()) :
84+ Protocol (options) {
8785
8886 /* *
8987 * Retrieves the server's reported capabilities after the initialization process completes.
@@ -144,13 +142,13 @@ public open class Client(
144142 val message = InitializeRequest (
145143 protocolVersion = LATEST_PROTOCOL_VERSION ,
146144 capabilities = capabilities,
147- clientInfo = clientInfo
145+ clientInfo = clientInfo,
148146 )
149147 val result = request<InitializeResult >(message)
150148
151149 if (! SUPPORTED_PROTOCOL_VERSIONS .contains(result.protocolVersion)) {
152150 throw IllegalStateException (
153- " Server's protocol version is not supported: ${result.protocolVersion} "
151+ " Server's protocol version is not supported: ${result.protocolVersion} " ,
154152 )
155153 }
156154
@@ -165,11 +163,9 @@ public open class Client(
165163 }
166164
167165 throw error
168-
169166 }
170167 }
171168
172-
173169 override fun assertCapabilityForMethod (method : Method ) {
174170 when (method) {
175171 Method .Defined .LoggingSetLevel -> {
@@ -181,7 +177,7 @@ public open class Client(
181177 Method .Defined .PromptsGet ,
182178 Method .Defined .PromptsList ,
183179 Method .Defined .CompletionComplete ,
184- -> {
180+ -> {
185181 if (serverCapabilities?.prompts == null ) {
186182 throw IllegalStateException (" Server does not support prompts (required for $method )" )
187183 }
@@ -192,28 +188,28 @@ public open class Client(
192188 Method .Defined .ResourcesRead ,
193189 Method .Defined .ResourcesSubscribe ,
194190 Method .Defined .ResourcesUnsubscribe ,
195- -> {
191+ -> {
196192 val resCaps = serverCapabilities?.resources
197193 ? : error(" Server does not support resources (required for $method )" )
198194
199195 if (method == Method .Defined .ResourcesSubscribe && resCaps.subscribe != true ) {
200196 throw IllegalStateException (
201- " Server does not support resource subscriptions (required for $method )"
197+ " Server does not support resource subscriptions (required for $method )" ,
202198 )
203199 }
204200 }
205201
206202 Method .Defined .ToolsCall ,
207203 Method .Defined .ToolsList ,
208- -> {
204+ -> {
209205 if (serverCapabilities?.tools == null ) {
210206 throw IllegalStateException (" Server does not support tools (required for $method )" )
211207 }
212208 }
213209
214210 Method .Defined .Initialize ,
215211 Method .Defined .Ping ,
216- -> {
212+ -> {
217213 // No specific capability required
218214 }
219215
@@ -228,15 +224,15 @@ public open class Client(
228224 Method .Defined .NotificationsRootsListChanged -> {
229225 if (capabilities.roots?.listChanged != true ) {
230226 throw IllegalStateException (
231- " Client does not support roots list changed notifications (required for $method )"
227+ " Client does not support roots list changed notifications (required for $method )" ,
232228 )
233229 }
234230 }
235231
236232 Method .Defined .NotificationsInitialized ,
237233 Method .Defined .NotificationsCancelled ,
238234 Method .Defined .NotificationsProgress ,
239- -> {
235+ -> {
240236 // Always allowed
241237 }
242238
@@ -251,23 +247,23 @@ public open class Client(
251247 Method .Defined .SamplingCreateMessage -> {
252248 if (capabilities.sampling == null ) {
253249 throw IllegalStateException (
254- " Client does not support sampling capability (required for $method )"
250+ " Client does not support sampling capability (required for $method )" ,
255251 )
256252 }
257253 }
258254
259255 Method .Defined .RootsList -> {
260256 if (capabilities.roots == null ) {
261257 throw IllegalStateException (
262- " Client does not support roots capability (required for $method )"
258+ " Client does not support roots capability (required for $method )" ,
263259 )
264260 }
265261 }
266262
267263 Method .Defined .ElicitationCreate -> {
268264 if (capabilities.elicitation == null ) {
269265 throw IllegalStateException (
270- " Client does not support elicitation capability (required for $method )"
266+ " Client does not support elicitation capability (required for $method )" ,
271267 )
272268 }
273269 }
@@ -280,16 +276,14 @@ public open class Client(
280276 }
281277 }
282278
283-
284279 /* *
285280 * Sends a ping request to the server to check connectivity.
286281 *
287282 * @param options Optional request options.
288283 * @throws IllegalStateException If the server does not support the ping method (unlikely).
289284 */
290- public suspend fun ping (options : RequestOptions ? = null): EmptyRequestResult {
291- return request<EmptyRequestResult >(PingRequest (), options)
292- }
285+ public suspend fun ping (options : RequestOptions ? = null): EmptyRequestResult =
286+ request<EmptyRequestResult >(PingRequest (), options)
293287
294288 /* *
295289 * Sends a completion request to the server, typically to generate or complete some content.
@@ -299,9 +293,8 @@ public open class Client(
299293 * @return The completion result returned by the server, or `null` if none.
300294 * @throws IllegalStateException If the server does not support prompts or completion.
301295 */
302- public suspend fun complete (params : CompleteRequest , options : RequestOptions ? = null): CompleteResult {
303- return request(params, options)
304- }
296+ public suspend fun complete (params : CompleteRequest , options : RequestOptions ? = null): CompleteResult =
297+ request(params, options)
305298
306299 /* *
307300 * Sets the logging level on the server.
@@ -310,9 +303,8 @@ public open class Client(
310303 * @param options Optional request options.
311304 * @throws IllegalStateException If the server does not support logging.
312305 */
313- public suspend fun setLoggingLevel (level : LoggingLevel , options : RequestOptions ? = null): EmptyRequestResult {
314- return request<EmptyRequestResult >(SetLevelRequest (level), options)
315- }
306+ public suspend fun setLoggingLevel (level : LoggingLevel , options : RequestOptions ? = null): EmptyRequestResult =
307+ request<EmptyRequestResult >(SetLevelRequest (level), options)
316308
317309 /* *
318310 * Retrieves a prompt by name from the server.
@@ -322,9 +314,8 @@ public open class Client(
322314 * @return The requested prompt details, or `null` if not found.
323315 * @throws IllegalStateException If the server does not support prompts.
324316 */
325- public suspend fun getPrompt (request : GetPromptRequest , options : RequestOptions ? = null): GetPromptResult {
326- return request(request, options)
327- }
317+ public suspend fun getPrompt (request : GetPromptRequest , options : RequestOptions ? = null): GetPromptResult =
318+ request(request, options)
328319
329320 /* *
330321 * Lists all available prompts from the server.
@@ -337,9 +328,7 @@ public open class Client(
337328 public suspend fun listPrompts (
338329 request : ListPromptsRequest = ListPromptsRequest (),
339330 options : RequestOptions ? = null,
340- ): ListPromptsResult {
341- return request(request, options)
342- }
331+ ): ListPromptsResult = request(request, options)
343332
344333 /* *
345334 * Lists all available resources from the server.
@@ -352,9 +341,7 @@ public open class Client(
352341 public suspend fun listResources (
353342 request : ListResourcesRequest = ListResourcesRequest (),
354343 options : RequestOptions ? = null,
355- ): ListResourcesResult {
356- return request(request, options)
357- }
344+ ): ListResourcesResult = request(request, options)
358345
359346 /* *
360347 * Lists resource templates available on the server.
@@ -367,9 +354,7 @@ public open class Client(
367354 public suspend fun listResourceTemplates (
368355 request : ListResourceTemplatesRequest ,
369356 options : RequestOptions ? = null,
370- ): ListResourceTemplatesResult {
371- return request(request, options)
372- }
357+ ): ListResourceTemplatesResult = request(request, options)
373358
374359 /* *
375360 * Reads a resource from the server by its URI.
@@ -382,9 +367,7 @@ public open class Client(
382367 public suspend fun readResource (
383368 request : ReadResourceRequest ,
384369 options : RequestOptions ? = null,
385- ): ReadResourceResult {
386- return request(request, options)
387- }
370+ ): ReadResourceResult = request(request, options)
388371
389372 /* *
390373 * Subscribes to resource changes on the server.
@@ -396,9 +379,7 @@ public open class Client(
396379 public suspend fun subscribeResource (
397380 request : SubscribeRequest ,
398381 options : RequestOptions ? = null,
399- ): EmptyRequestResult {
400- return request(request, options)
401- }
382+ ): EmptyRequestResult = request(request, options)
402383
403384 /* *
404385 * Unsubscribes from resource changes on the server.
@@ -410,9 +391,7 @@ public open class Client(
410391 public suspend fun unsubscribeResource (
411392 request : UnsubscribeRequest ,
412393 options : RequestOptions ? = null,
413- ): EmptyRequestResult {
414- return request(request, options)
415- }
394+ ): EmptyRequestResult = request(request, options)
416395
417396 /* *
418397 * Calls a tool on the server by name, passing the specified arguments.
@@ -443,7 +422,7 @@ public open class Client(
443422
444423 val request = CallToolRequest (
445424 name = name,
446- arguments = JsonObject (jsonArguments)
425+ arguments = JsonObject (jsonArguments),
447426 )
448427 return callTool(request, compatibility, options)
449428 }
@@ -461,12 +440,10 @@ public open class Client(
461440 request : CallToolRequest ,
462441 compatibility : Boolean = false,
463442 options : RequestOptions ? = null,
464- ): CallToolResultBase ? {
465- return if (compatibility) {
466- request<CompatibilityCallToolResult >(request, options)
467- } else {
468- request<CallToolResult >(request, options)
469- }
443+ ): CallToolResultBase ? = if (compatibility) {
444+ request<CompatibilityCallToolResult >(request, options)
445+ } else {
446+ request<CallToolResult >(request, options)
470447 }
471448
472449 /* *
@@ -480,9 +457,7 @@ public open class Client(
480457 public suspend fun listTools (
481458 request : ListToolsRequest = ListToolsRequest (),
482459 options : RequestOptions ? = null,
483- ): ListToolsResult {
484- return request(request, options)
485- }
460+ ): ListToolsResult = request(request, options)
486461
487462 /* *
488463 * Registers a single root.
@@ -491,10 +466,7 @@ public open class Client(
491466 * @param name A human-readable name for the root.
492467 * @throws IllegalStateException If the client does not support roots.
493468 */
494- public fun addRoot (
495- uri : String ,
496- name : String ,
497- ) {
469+ public fun addRoot (uri : String , name : String ) {
498470 if (capabilities.roots == null ) {
499471 logger.error { " Failed to add root '$name ': Client does not support roots capability" }
500472 throw IllegalStateException (" Client does not support roots capability." )
0 commit comments