@@ -80,10 +80,8 @@ public class ClientOptions(
80
80
* @param clientInfo Information about the client implementation (name, version).
81
81
* @param options Configuration options for this client.
82
82
*/
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) {
87
85
88
86
/* *
89
87
* Retrieves the server's reported capabilities after the initialization process completes.
@@ -144,13 +142,13 @@ public open class Client(
144
142
val message = InitializeRequest (
145
143
protocolVersion = LATEST_PROTOCOL_VERSION ,
146
144
capabilities = capabilities,
147
- clientInfo = clientInfo
145
+ clientInfo = clientInfo,
148
146
)
149
147
val result = request<InitializeResult >(message)
150
148
151
149
if (! SUPPORTED_PROTOCOL_VERSIONS .contains(result.protocolVersion)) {
152
150
throw IllegalStateException (
153
- " Server's protocol version is not supported: ${result.protocolVersion} "
151
+ " Server's protocol version is not supported: ${result.protocolVersion} " ,
154
152
)
155
153
}
156
154
@@ -165,11 +163,9 @@ public open class Client(
165
163
}
166
164
167
165
throw error
168
-
169
166
}
170
167
}
171
168
172
-
173
169
override fun assertCapabilityForMethod (method : Method ) {
174
170
when (method) {
175
171
Method .Defined .LoggingSetLevel -> {
@@ -181,7 +177,7 @@ public open class Client(
181
177
Method .Defined .PromptsGet ,
182
178
Method .Defined .PromptsList ,
183
179
Method .Defined .CompletionComplete ,
184
- -> {
180
+ -> {
185
181
if (serverCapabilities?.prompts == null ) {
186
182
throw IllegalStateException (" Server does not support prompts (required for $method )" )
187
183
}
@@ -192,28 +188,28 @@ public open class Client(
192
188
Method .Defined .ResourcesRead ,
193
189
Method .Defined .ResourcesSubscribe ,
194
190
Method .Defined .ResourcesUnsubscribe ,
195
- -> {
191
+ -> {
196
192
val resCaps = serverCapabilities?.resources
197
193
? : error(" Server does not support resources (required for $method )" )
198
194
199
195
if (method == Method .Defined .ResourcesSubscribe && resCaps.subscribe != true ) {
200
196
throw IllegalStateException (
201
- " Server does not support resource subscriptions (required for $method )"
197
+ " Server does not support resource subscriptions (required for $method )" ,
202
198
)
203
199
}
204
200
}
205
201
206
202
Method .Defined .ToolsCall ,
207
203
Method .Defined .ToolsList ,
208
- -> {
204
+ -> {
209
205
if (serverCapabilities?.tools == null ) {
210
206
throw IllegalStateException (" Server does not support tools (required for $method )" )
211
207
}
212
208
}
213
209
214
210
Method .Defined .Initialize ,
215
211
Method .Defined .Ping ,
216
- -> {
212
+ -> {
217
213
// No specific capability required
218
214
}
219
215
@@ -228,15 +224,15 @@ public open class Client(
228
224
Method .Defined .NotificationsRootsListChanged -> {
229
225
if (capabilities.roots?.listChanged != true ) {
230
226
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 )" ,
232
228
)
233
229
}
234
230
}
235
231
236
232
Method .Defined .NotificationsInitialized ,
237
233
Method .Defined .NotificationsCancelled ,
238
234
Method .Defined .NotificationsProgress ,
239
- -> {
235
+ -> {
240
236
// Always allowed
241
237
}
242
238
@@ -251,23 +247,23 @@ public open class Client(
251
247
Method .Defined .SamplingCreateMessage -> {
252
248
if (capabilities.sampling == null ) {
253
249
throw IllegalStateException (
254
- " Client does not support sampling capability (required for $method )"
250
+ " Client does not support sampling capability (required for $method )" ,
255
251
)
256
252
}
257
253
}
258
254
259
255
Method .Defined .RootsList -> {
260
256
if (capabilities.roots == null ) {
261
257
throw IllegalStateException (
262
- " Client does not support roots capability (required for $method )"
258
+ " Client does not support roots capability (required for $method )" ,
263
259
)
264
260
}
265
261
}
266
262
267
263
Method .Defined .ElicitationCreate -> {
268
264
if (capabilities.elicitation == null ) {
269
265
throw IllegalStateException (
270
- " Client does not support elicitation capability (required for $method )"
266
+ " Client does not support elicitation capability (required for $method )" ,
271
267
)
272
268
}
273
269
}
@@ -280,16 +276,14 @@ public open class Client(
280
276
}
281
277
}
282
278
283
-
284
279
/* *
285
280
* Sends a ping request to the server to check connectivity.
286
281
*
287
282
* @param options Optional request options.
288
283
* @throws IllegalStateException If the server does not support the ping method (unlikely).
289
284
*/
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)
293
287
294
288
/* *
295
289
* Sends a completion request to the server, typically to generate or complete some content.
@@ -299,9 +293,8 @@ public open class Client(
299
293
* @return The completion result returned by the server, or `null` if none.
300
294
* @throws IllegalStateException If the server does not support prompts or completion.
301
295
*/
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)
305
298
306
299
/* *
307
300
* Sets the logging level on the server.
@@ -310,9 +303,8 @@ public open class Client(
310
303
* @param options Optional request options.
311
304
* @throws IllegalStateException If the server does not support logging.
312
305
*/
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)
316
308
317
309
/* *
318
310
* Retrieves a prompt by name from the server.
@@ -322,9 +314,8 @@ public open class Client(
322
314
* @return The requested prompt details, or `null` if not found.
323
315
* @throws IllegalStateException If the server does not support prompts.
324
316
*/
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)
328
319
329
320
/* *
330
321
* Lists all available prompts from the server.
@@ -337,9 +328,7 @@ public open class Client(
337
328
public suspend fun listPrompts (
338
329
request : ListPromptsRequest = ListPromptsRequest (),
339
330
options : RequestOptions ? = null,
340
- ): ListPromptsResult {
341
- return request(request, options)
342
- }
331
+ ): ListPromptsResult = request(request, options)
343
332
344
333
/* *
345
334
* Lists all available resources from the server.
@@ -352,9 +341,7 @@ public open class Client(
352
341
public suspend fun listResources (
353
342
request : ListResourcesRequest = ListResourcesRequest (),
354
343
options : RequestOptions ? = null,
355
- ): ListResourcesResult {
356
- return request(request, options)
357
- }
344
+ ): ListResourcesResult = request(request, options)
358
345
359
346
/* *
360
347
* Lists resource templates available on the server.
@@ -367,9 +354,7 @@ public open class Client(
367
354
public suspend fun listResourceTemplates (
368
355
request : ListResourceTemplatesRequest ,
369
356
options : RequestOptions ? = null,
370
- ): ListResourceTemplatesResult {
371
- return request(request, options)
372
- }
357
+ ): ListResourceTemplatesResult = request(request, options)
373
358
374
359
/* *
375
360
* Reads a resource from the server by its URI.
@@ -382,9 +367,7 @@ public open class Client(
382
367
public suspend fun readResource (
383
368
request : ReadResourceRequest ,
384
369
options : RequestOptions ? = null,
385
- ): ReadResourceResult {
386
- return request(request, options)
387
- }
370
+ ): ReadResourceResult = request(request, options)
388
371
389
372
/* *
390
373
* Subscribes to resource changes on the server.
@@ -396,9 +379,7 @@ public open class Client(
396
379
public suspend fun subscribeResource (
397
380
request : SubscribeRequest ,
398
381
options : RequestOptions ? = null,
399
- ): EmptyRequestResult {
400
- return request(request, options)
401
- }
382
+ ): EmptyRequestResult = request(request, options)
402
383
403
384
/* *
404
385
* Unsubscribes from resource changes on the server.
@@ -410,9 +391,7 @@ public open class Client(
410
391
public suspend fun unsubscribeResource (
411
392
request : UnsubscribeRequest ,
412
393
options : RequestOptions ? = null,
413
- ): EmptyRequestResult {
414
- return request(request, options)
415
- }
394
+ ): EmptyRequestResult = request(request, options)
416
395
417
396
/* *
418
397
* Calls a tool on the server by name, passing the specified arguments.
@@ -443,7 +422,7 @@ public open class Client(
443
422
444
423
val request = CallToolRequest (
445
424
name = name,
446
- arguments = JsonObject (jsonArguments)
425
+ arguments = JsonObject (jsonArguments),
447
426
)
448
427
return callTool(request, compatibility, options)
449
428
}
@@ -461,12 +440,10 @@ public open class Client(
461
440
request : CallToolRequest ,
462
441
compatibility : Boolean = false,
463
442
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)
470
447
}
471
448
472
449
/* *
@@ -480,9 +457,7 @@ public open class Client(
480
457
public suspend fun listTools (
481
458
request : ListToolsRequest = ListToolsRequest (),
482
459
options : RequestOptions ? = null,
483
- ): ListToolsResult {
484
- return request(request, options)
485
- }
460
+ ): ListToolsResult = request(request, options)
486
461
487
462
/* *
488
463
* Registers a single root.
@@ -491,10 +466,7 @@ public open class Client(
491
466
* @param name A human-readable name for the root.
492
467
* @throws IllegalStateException If the client does not support roots.
493
468
*/
494
- public fun addRoot (
495
- uri : String ,
496
- name : String ,
497
- ) {
469
+ public fun addRoot (uri : String , name : String ) {
498
470
if (capabilities.roots == null ) {
499
471
logger.error { " Failed to add root '$name ': Client does not support roots capability" }
500
472
throw IllegalStateException (" Client does not support roots capability." )
0 commit comments