Skip to content

Commit b44384f

Browse files
committed
chore: fix server documentation for getTask/getTaskResult
Also added taskId convenience overloads.
1 parent 052bcaf commit b44384f

File tree

4 files changed

+264
-22
lines changed

4 files changed

+264
-22
lines changed

mcp-core/src/main/java/io/modelcontextprotocol/client/McpAsyncClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,7 @@ public Mono<McpSchema.GetTaskResult> getTask(String taskId) {
16581658
*
16591659
* <p>
16601660
* This method mirrors
1661-
* {@link io.modelcontextprotocol.server.McpSyncServerExchange#getTaskResult(McpSchema.GetTaskPayloadRequest, TypeRef)},
1661+
* {@link io.modelcontextprotocol.server.McpAsyncServerExchange#getTaskResult(McpSchema.GetTaskPayloadRequest, TypeRef)},
16621662
* which is used for when the server has initiated a task with the client.
16631663
*
16641664
* <p>

mcp-core/src/main/java/io/modelcontextprotocol/client/McpSyncClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,8 @@ public McpSchema.GetTaskResult getTask(McpSchema.GetTaskRequest getTaskRequest)
542542
*
543543
* <p>
544544
* This method mirrors
545-
* {@link io.modelcontextprotocol.server.McpSyncServerExchange#getTask(McpSchema.GetTaskRequest)},
546-
* which is used for when the server has initiated a task with the client.
545+
* {@link io.modelcontextprotocol.server.McpSyncServerExchange#getTask(String)}, which
546+
* is used for when the server has initiated a task with the client.
547547
*
548548
* <p>
549549
* This is a convenience overload that creates a {@link McpSchema.GetTaskRequest} with
@@ -620,7 +620,7 @@ public <T extends McpSchema.ServerTaskPayloadResult> T getTaskResult(
620620
*
621621
* <p>
622622
* This method mirrors
623-
* {@link io.modelcontextprotocol.server.McpSyncServerExchange#getTaskResult(McpSchema.GetTaskPayloadRequest, TypeRef)},
623+
* {@link io.modelcontextprotocol.server.McpSyncServerExchange#getTaskResult(String, TypeRef)},
624624
* which is used for when the server has initiated a task with the client.
625625
*
626626
* <p>

mcp-core/src/main/java/io/modelcontextprotocol/server/McpAsyncServerExchange.java

Lines changed: 132 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,30 @@ void setMinLoggingLevel(LoggingLevel minLoggingLevel) {
508508
// --------------------------
509509

510510
/**
511-
* Get the status of a task hosted by the client. This is used when the server has
512-
* sent a task-augmented request to the client and needs to poll for status updates.
513-
* @param getTaskRequest The request containing the task ID
514-
* @return A Mono that emits the task status
511+
* Retrieves a task previously initiated by the server with the client.
512+
*
513+
* <p>
514+
* This method mirrors
515+
* {@link io.modelcontextprotocol.client.McpAsyncClient#getTask(McpSchema.GetTaskRequest)},
516+
* which is used for when the client has initiated a task with the server.
517+
*
518+
* <p>
519+
* Example usage:
520+
*
521+
* <pre>{@code
522+
* var result = exchange.getTask(GetTaskRequest.builder()
523+
* .taskId(taskId)
524+
* .build())
525+
* .block();
526+
* }</pre>
527+
*
528+
* <p>
529+
* <strong>Note:</strong> This is an experimental feature that may change in future
530+
* releases.
531+
* @param getTaskRequest The request containing the task ID.
532+
* @return A Mono that completes with the task information.
533+
* @see McpSchema.GetTaskRequest
534+
* @see McpSchema.GetTaskResult
515535
*/
516536
public Mono<McpSchema.GetTaskResult> getTask(McpSchema.GetTaskRequest getTaskRequest) {
517537
if (this.clientCapabilities == null) {
@@ -525,11 +545,69 @@ public Mono<McpSchema.GetTaskResult> getTask(McpSchema.GetTaskRequest getTaskReq
525545
}
526546

527547
/**
528-
* Get the result of a completed task hosted by the client.
529-
* @param <T> The expected result type
530-
* @param getTaskPayloadRequest The request containing the task ID
531-
* @param resultTypeRef Type reference for deserializing the result
532-
* @return A Mono that emits the task result
548+
* Retrieves a task previously initiated by the server with the client by its ID.
549+
*
550+
* <p>
551+
* This method mirrors
552+
* {@link io.modelcontextprotocol.client.McpAsyncClient#getTask(String)}, which is
553+
* used for when the client has initiated a task with the server.
554+
*
555+
* <p>
556+
* This is a convenience overload that creates a {@link McpSchema.GetTaskRequest} with
557+
* the given task ID.
558+
*
559+
* <p>
560+
* Example usage:
561+
*
562+
* <pre>{@code
563+
* var result = exchange.getTask(taskId);
564+
* }</pre>
565+
*
566+
* <p>
567+
* <strong>Note:</strong> This is an experimental feature that may change in future
568+
* releases.
569+
* @param taskId The task identifier to query.
570+
* @return A Mono that completes with the task status and metadata.
571+
*/
572+
public Mono<McpSchema.GetTaskResult> getTask(String taskId) {
573+
return this.getTask(McpSchema.GetTaskRequest.builder().taskId(taskId).build());
574+
}
575+
576+
/**
577+
* Get the result of a completed task previously initiated by the server with the
578+
* client.
579+
*
580+
* <p>
581+
* The result type depends on the original request that created the task. For sampling
582+
* requests, use {@code new TypeRef<McpSchema.CreateMessageResult>(){}}. For
583+
* elicitation requests, use {@code new TypeRef<McpSchema.ElicitResult>(){}}.
584+
*
585+
* <p>
586+
* This method mirrors
587+
* {@link io.modelcontextprotocol.client.McpAsyncClient#getTaskResult(McpSchema.GetTaskPayloadRequest, TypeRef)},
588+
* which is used for when the client has initiated a task with the server.
589+
*
590+
* <p>
591+
* Example usage:
592+
*
593+
* <pre>{@code
594+
* // For sampling task results:
595+
* var result = exchange.getTaskResult(
596+
* new GetTaskPayloadRequest(taskId, null),
597+
* new TypeRef<McpSchema.CreateMessageResult>(){})
598+
* .block();
599+
* }</pre>
600+
*
601+
* <p>
602+
* <strong>Note:</strong> This is an experimental feature that may change in future
603+
* releases.
604+
* @param <T> The expected result type, must extend
605+
* {@link McpSchema.ClientTaskPayloadResult}
606+
* @param getTaskPayloadRequest The request containing the task ID.
607+
* @param resultTypeRef Type reference for deserializing the result.
608+
* @return A Mono that completes with the task result.
609+
* @see McpSchema.GetTaskPayloadRequest
610+
* @see McpSchema.ClientTaskPayloadResult
533611
*/
534612
public <T extends McpSchema.ClientTaskPayloadResult> Mono<T> getTaskResult(
535613
McpSchema.GetTaskPayloadRequest getTaskPayloadRequest, TypeRef<T> resultTypeRef) {
@@ -543,6 +621,51 @@ public <T extends McpSchema.ClientTaskPayloadResult> Mono<T> getTaskResult(
543621
return this.session.sendRequest(McpSchema.METHOD_TASKS_RESULT, getTaskPayloadRequest, resultTypeRef);
544622
}
545623

624+
/**
625+
* Get the result of a completed task previously initiated by the server with the
626+
* client by its task ID.
627+
*
628+
* <p>
629+
* This is a convenience overload that creates a
630+
* {@link McpSchema.GetTaskPayloadRequest} from the task ID.
631+
*
632+
* <p>
633+
* The result type depends on the original request that created the task. For sampling
634+
* requests, use {@code new TypeRef<McpSchema.CreateMessageResult>(){}}. For
635+
* elicitation requests, use {@code new TypeRef<McpSchema.ElicitResult>(){}}.
636+
*
637+
* <p>
638+
* This method mirrors
639+
* {@link io.modelcontextprotocol.client.McpAsyncClient#getTaskResult(String, TypeRef)},
640+
* which is used for when the client has initiated a task with the server.
641+
*
642+
* <p>
643+
* Example usage:
644+
*
645+
* <pre>{@code
646+
* // For sampling task results:
647+
* var result = exchange.getTaskResult(
648+
* taskId,
649+
* new TypeRef<McpSchema.CreateMessageResult>(){})
650+
* .block();
651+
* }</pre>
652+
*
653+
* <p>
654+
* <strong>Note:</strong> This is an experimental feature that may change in future
655+
* releases.
656+
* @param <T> The expected result type, must extend
657+
* {@link McpSchema.ClientTaskPayloadResult}
658+
* @param taskId The task identifier.
659+
* @param resultTypeRef Type reference for deserializing the result.
660+
* @return A Mono that completes with the task result.
661+
* @see McpSchema.GetTaskPayloadRequest
662+
* @see McpSchema.ClientTaskPayloadResult
663+
*/
664+
public <T extends McpSchema.ClientTaskPayloadResult> Mono<T> getTaskResult(String taskId,
665+
TypeRef<T> resultTypeRef) {
666+
return this.getTaskResult(McpSchema.GetTaskPayloadRequest.builder().taskId(taskId).build(), resultTypeRef);
667+
}
668+
546669
/**
547670
* List all tasks hosted by the client.
548671
*

mcp-core/src/main/java/io/modelcontextprotocol/server/McpSyncServerExchange.java

Lines changed: 128 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,27 +212,146 @@ public Object ping() {
212212
// --------------------------
213213

214214
/**
215-
* Get the status of a task hosted by the client. This is used when the server has
216-
* sent a task-augmented request to the client and needs to poll for status updates.
217-
* @param getTaskRequest The request containing the task ID
218-
* @return The task status
215+
* Retrieves a task previously initiated by the server with the client.
216+
*
217+
* <p>
218+
* This method mirrors
219+
* {@link io.modelcontextprotocol.client.McpSyncClient#getTask(McpSchema.GetTaskRequest)},
220+
* which is used for when the client has initiated a task with the server.
221+
*
222+
* <p>
223+
* Example usage:
224+
*
225+
* <pre>{@code
226+
* var result = exchange.getTask(GetTaskRequest.builder()
227+
* .taskId(taskId)
228+
* .build());
229+
* }</pre>
230+
*
231+
* <p>
232+
* <strong>Note:</strong> This is an experimental feature that may change in future
233+
* releases.
234+
* @param getTaskRequest The request containing the task ID.
235+
* @return The task information.
236+
* @see McpSchema.GetTaskRequest
237+
* @see McpSchema.GetTaskResult
219238
*/
220239
public McpSchema.GetTaskResult getTask(McpSchema.GetTaskRequest getTaskRequest) {
221240
return this.exchange.getTask(getTaskRequest).block();
222241
}
223242

224243
/**
225-
* Get the result of a completed task hosted by the client.
226-
* @param <T> The expected result type
227-
* @param getTaskPayloadRequest The request containing the task ID
228-
* @param resultTypeRef Type reference for deserializing the result
229-
* @return The task result
244+
* Retrieves a task previously initiated by the server with the client by its ID.
245+
*
246+
* <p>
247+
* This method mirrors
248+
* {@link io.modelcontextprotocol.client.McpSyncClient#getTask(String)}, which is used
249+
* for when the client has initiated a task with the server.
250+
*
251+
* <p>
252+
* This is a convenience overload that creates a {@link McpSchema.GetTaskRequest} with
253+
* the given task ID.
254+
*
255+
* <p>
256+
* Example usage:
257+
*
258+
* <pre>{@code
259+
* var result = exchange.getTask(taskId);
260+
* }</pre>
261+
*
262+
* <p>
263+
* <strong>Note:</strong> This is an experimental feature that may change in future
264+
* releases.
265+
* @param taskId The task identifier to query.
266+
* @return The task status and metadata.
267+
*/
268+
public McpSchema.GetTaskResult getTask(String taskId) {
269+
return this.exchange.getTask(McpSchema.GetTaskRequest.builder().taskId(taskId).build()).block();
270+
}
271+
272+
/**
273+
* Get the result of a completed task previously initiated by the server with the
274+
* client.
275+
*
276+
* <p>
277+
* The result type depends on the original request that created the task. For sampling
278+
* requests, use {@code new TypeRef<McpSchema.CreateMessageResult>(){}}. For
279+
* elicitation requests, use {@code new TypeRef<McpSchema.ElicitResult>(){}}.
280+
*
281+
* <p>
282+
* This method mirrors
283+
* {@link io.modelcontextprotocol.client.McpSyncClient#getTaskResult(McpSchema.GetTaskPayloadRequest, TypeRef)},
284+
* which is used for when the client has initiated a task with the server.
285+
*
286+
* <p>
287+
* Example usage:
288+
*
289+
* <pre>{@code
290+
* // For sampling task results:
291+
* var result = exchange.getTaskResult(
292+
* new GetTaskPayloadRequest(taskId, null),
293+
* new TypeRef<McpSchema.CreateMessageResult>(){});
294+
* }</pre>
295+
*
296+
* <p>
297+
* <strong>Note:</strong> This is an experimental feature that may change in future
298+
* releases.
299+
* @param <T> The expected result type, must extend
300+
* {@link McpSchema.ClientTaskPayloadResult}
301+
* @param getTaskPayloadRequest The request containing the task ID.
302+
* @param resultTypeRef Type reference for deserializing the result.
303+
* @return The task result.
304+
* @see McpSchema.GetTaskPayloadRequest
305+
* @see McpSchema.ClientTaskPayloadResult
230306
*/
231307
public <T extends McpSchema.ClientTaskPayloadResult> T getTaskResult(
232308
McpSchema.GetTaskPayloadRequest getTaskPayloadRequest, TypeRef<T> resultTypeRef) {
233309
return this.exchange.getTaskResult(getTaskPayloadRequest, resultTypeRef).block();
234310
}
235311

312+
/**
313+
* Get the result of a completed task previously initiated by the server with the
314+
* client by its task ID.
315+
*
316+
* <p>
317+
* This is a convenience overload that creates a
318+
* {@link McpSchema.GetTaskPayloadRequest} from the task ID.
319+
*
320+
* <p>
321+
* The result type depends on the original request that created the task. For sampling
322+
* requests, use {@code new TypeRef<McpSchema.CreateMessageResult>(){}}. For
323+
* elicitation requests, use {@code new TypeRef<McpSchema.ElicitResult>(){}}.
324+
*
325+
* <p>
326+
* This method mirrors
327+
* {@link io.modelcontextprotocol.client.McpSyncClient#getTaskResult(String, TypeRef)},
328+
* which is used for when the client has initiated a task with the server.
329+
*
330+
* <p>
331+
* Example usage:
332+
*
333+
* <pre>{@code
334+
* // For sampling task results:
335+
* var result = exchange.getTaskResult(
336+
* taskId,
337+
* new TypeRef<McpSchema.CreateMessageResult>(){});
338+
* }</pre>
339+
*
340+
* <p>
341+
* <strong>Note:</strong> This is an experimental feature that may change in future
342+
* releases.
343+
* @param <T> The expected result type, must extend
344+
* {@link McpSchema.ClientTaskPayloadResult}
345+
* @param taskId The task identifier.
346+
* @param resultTypeRef Type reference for deserializing the result.
347+
* @return The task result.
348+
* @see McpSchema.GetTaskPayloadRequest
349+
* @see McpSchema.ClientTaskPayloadResult
350+
*/
351+
public <T extends McpSchema.ClientTaskPayloadResult> T getTaskResult(String taskId, TypeRef<T> resultTypeRef) {
352+
return this.getTaskResult(McpSchema.GetTaskPayloadRequest.builder().taskId(taskId).build(), resultTypeRef);
353+
}
354+
236355
/**
237356
* List all tasks hosted by the client.
238357
*

0 commit comments

Comments
 (0)