@@ -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,13 @@ 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 = request(PingRequest (), options)
293286
294287 /* *
295288 * Sends a completion request to the server, typically to generate or complete some content.
@@ -299,9 +292,8 @@ public open class Client(
299292 * @return The completion result returned by the server, or `null` if none.
300293 * @throws IllegalStateException If the server does not support prompts or completion.
301294 */
302- public suspend fun complete (params : CompleteRequest , options : RequestOptions ? = null): CompleteResult ? {
303- return request<CompleteResult >(params, options)
304- }
295+ public suspend fun complete (params : CompleteRequest , options : RequestOptions ? = null): CompleteResult =
296+ request(params, options)
305297
306298 /* *
307299 * Sets the logging level on the server.
@@ -310,9 +302,8 @@ public open class Client(
310302 * @param options Optional request options.
311303 * @throws IllegalStateException If the server does not support logging.
312304 */
313- public suspend fun setLoggingLevel (level : LoggingLevel , options : RequestOptions ? = null): EmptyRequestResult {
314- return request<EmptyRequestResult >(SetLevelRequest (level), options)
315- }
305+ public suspend fun setLoggingLevel (level : LoggingLevel , options : RequestOptions ? = null): EmptyRequestResult =
306+ request(SetLevelRequest (level), options)
316307
317308 /* *
318309 * Retrieves a prompt by name from the server.
@@ -322,9 +313,8 @@ public open class Client(
322313 * @return The requested prompt details, or `null` if not found.
323314 * @throws IllegalStateException If the server does not support prompts.
324315 */
325- public suspend fun getPrompt (request : GetPromptRequest , options : RequestOptions ? = null): GetPromptResult ? {
326- return request<GetPromptResult >(request, options)
327- }
316+ public suspend fun getPrompt (request : GetPromptRequest , options : RequestOptions ? = null): GetPromptResult =
317+ request(request, options)
328318
329319 /* *
330320 * Lists all available prompts from the server.
@@ -337,9 +327,7 @@ public open class Client(
337327 public suspend fun listPrompts (
338328 request : ListPromptsRequest = ListPromptsRequest (),
339329 options : RequestOptions ? = null,
340- ): ListPromptsResult ? {
341- return request<ListPromptsResult >(request, options)
342- }
330+ ): ListPromptsResult = request(request, options)
343331
344332 /* *
345333 * Lists all available resources from the server.
@@ -352,9 +340,7 @@ public open class Client(
352340 public suspend fun listResources (
353341 request : ListResourcesRequest = ListResourcesRequest (),
354342 options : RequestOptions ? = null,
355- ): ListResourcesResult ? {
356- return request<ListResourcesResult >(request, options)
357- }
343+ ): ListResourcesResult = request(request, options)
358344
359345 /* *
360346 * Lists resource templates available on the server.
@@ -367,9 +353,7 @@ public open class Client(
367353 public suspend fun listResourceTemplates (
368354 request : ListResourceTemplatesRequest ,
369355 options : RequestOptions ? = null,
370- ): ListResourceTemplatesResult ? {
371- return request<ListResourceTemplatesResult >(request, options)
372- }
356+ ): ListResourceTemplatesResult = request(request, options)
373357
374358 /* *
375359 * Reads a resource from the server by its URI.
@@ -382,9 +366,7 @@ public open class Client(
382366 public suspend fun readResource (
383367 request : ReadResourceRequest ,
384368 options : RequestOptions ? = null,
385- ): ReadResourceResult ? {
386- return request<ReadResourceResult >(request, options)
387- }
369+ ): ReadResourceResult = request(request, options)
388370
389371 /* *
390372 * Subscribes to resource changes on the server.
@@ -396,9 +378,7 @@ public open class Client(
396378 public suspend fun subscribeResource (
397379 request : SubscribeRequest ,
398380 options : RequestOptions ? = null,
399- ): EmptyRequestResult {
400- return request<EmptyRequestResult >(request, options)
401- }
381+ ): EmptyRequestResult = request(request, options)
402382
403383 /* *
404384 * Unsubscribes from resource changes on the server.
@@ -410,9 +390,7 @@ public open class Client(
410390 public suspend fun unsubscribeResource (
411391 request : UnsubscribeRequest ,
412392 options : RequestOptions ? = null,
413- ): EmptyRequestResult {
414- return request<EmptyRequestResult >(request, options)
415- }
393+ ): EmptyRequestResult = request(request, options)
416394
417395 /* *
418396 * Calls a tool on the server by name, passing the specified arguments.
@@ -443,7 +421,7 @@ public open class Client(
443421
444422 val request = CallToolRequest (
445423 name = name,
446- arguments = JsonObject (jsonArguments)
424+ arguments = JsonObject (jsonArguments),
447425 )
448426 return callTool(request, compatibility, options)
449427 }
@@ -461,12 +439,10 @@ public open class Client(
461439 request : CallToolRequest ,
462440 compatibility : Boolean = false,
463441 options : RequestOptions ? = null,
464- ): CallToolResultBase ? {
465- return if (compatibility) {
466- request<CompatibilityCallToolResult >(request, options)
467- } else {
468- request<CallToolResult >(request, options)
469- }
442+ ): CallToolResultBase ? = if (compatibility) {
443+ request<CompatibilityCallToolResult >(request, options)
444+ } else {
445+ request<CallToolResult >(request, options)
470446 }
471447
472448 /* *
@@ -480,9 +456,7 @@ public open class Client(
480456 public suspend fun listTools (
481457 request : ListToolsRequest = ListToolsRequest (),
482458 options : RequestOptions ? = null,
483- ): ListToolsResult ? {
484- return request<ListToolsResult >(request, options)
485- }
459+ ): ListToolsResult = request(request, options)
486460
487461 /* *
488462 * Registers a single root.
@@ -491,10 +465,7 @@ public open class Client(
491465 * @param name A human-readable name for the root.
492466 * @throws IllegalStateException If the client does not support roots.
493467 */
494- public fun addRoot (
495- uri : String ,
496- name : String ,
497- ) {
468+ public fun addRoot (uri : String , name : String ) {
498469 if (capabilities.roots == null ) {
499470 logger.error { " Failed to add root '$name ': Client does not support roots capability" }
500471 throw IllegalStateException (" Client does not support roots capability." )
0 commit comments