Skip to content

Commit 052bcaf

Browse files
committed
chore: fix client documentation for getTask and make impls consistent
1 parent c238541 commit 052bcaf

File tree

2 files changed

+63
-9
lines changed

2 files changed

+63
-9
lines changed

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,13 +1584,28 @@ public Mono<McpSchema.CompleteResult> completeCompletion(McpSchema.CompleteReque
15841584
};
15851585

15861586
/**
1587-
* Get the status and metadata of a task.
1587+
* Retrieves a task previously initiated by the client with the server.
1588+
*
1589+
* <p>
1590+
* This method mirrors
1591+
* {@link io.modelcontextprotocol.server.McpAsyncServerExchange#getTask(McpSchema.GetTaskRequest)},
1592+
* which is used for when the server has initiated a task with the client.
1593+
*
1594+
* <p>
1595+
* Example usage:
1596+
*
1597+
* <pre>{@code
1598+
* var result = client.getTask(GetTaskRequest.builder()
1599+
* .taskId(taskId)
1600+
* .build())
1601+
* .block();
1602+
* }</pre>
15881603
*
15891604
* <p>
15901605
* <strong>Note:</strong> This is an experimental feature that may change in future
15911606
* releases.
15921607
* @param getTaskRequest The request containing the task ID.
1593-
* @return A Mono that completes with the task status and metadata.
1608+
* @return A Mono that completes with the task information.
15941609
* @see McpSchema.GetTaskRequest
15951610
* @see McpSchema.GetTaskResult
15961611
*/
@@ -1604,13 +1619,25 @@ public Mono<McpSchema.GetTaskResult> getTask(McpSchema.GetTaskRequest getTaskReq
16041619
}
16051620

16061621
/**
1607-
* Get the status and metadata of a task by ID.
1622+
* Retrieves a task previously initiated by the client with the server by its ID.
1623+
*
1624+
* <p>
1625+
* This method mirrors
1626+
* {@link io.modelcontextprotocol.server.McpAsyncServerExchange#getTask(McpSchema.GetTaskRequest)},
1627+
* which is used for when the server has initiated a task with the client.
16081628
*
16091629
* <p>
16101630
* This is a convenience overload that creates a {@link McpSchema.GetTaskRequest} with
16111631
* the given task ID.
16121632
*
16131633
* <p>
1634+
* Example usage:
1635+
*
1636+
* <pre>{@code
1637+
* var result = client.getTask(taskId);
1638+
* }</pre>
1639+
*
1640+
* <p>
16141641
* <strong>Note:</strong> This is an experimental feature that may change in future
16151642
* releases.
16161643
* @param taskId The task identifier to query.

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,13 +509,27 @@ public TaskStore<McpSchema.ClientTaskPayloadResult> getTaskStore() {
509509
}
510510

511511
/**
512-
* Get the status and metadata of a task.
512+
* Retrieves a task previously initiated by the client with the server.
513+
*
514+
* <p>
515+
* This method mirrors
516+
* {@link io.modelcontextprotocol.server.McpSyncServerExchange#getTask(McpSchema.GetTaskRequest)},
517+
* which is used for when the server has initiated a task with the client.
518+
*
519+
* <p>
520+
* Example usage:
521+
*
522+
* <pre>{@code
523+
* var result = client.getTask(GetTaskRequest.builder()
524+
* .taskId(taskId)
525+
* .build());
526+
* }</pre>
513527
*
514528
* <p>
515529
* <strong>Note:</strong> This is an experimental feature that may change in future
516530
* releases.
517531
* @param getTaskRequest The request containing the task ID.
518-
* @return The task status and metadata.
532+
* @return The task information.
519533
* @see McpSchema.GetTaskRequest
520534
* @see McpSchema.GetTaskResult
521535
*/
@@ -524,21 +538,33 @@ public McpSchema.GetTaskResult getTask(McpSchema.GetTaskRequest getTaskRequest)
524538
}
525539

526540
/**
527-
* Get the status and metadata of a task by ID.
541+
* Retrieves a task previously initiated by the client with the server by its ID.
542+
*
543+
* <p>
544+
* 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.
528547
*
529548
* <p>
530549
* This is a convenience overload that creates a {@link McpSchema.GetTaskRequest} with
531550
* the given task ID.
532551
*
533552
* <p>
553+
* Example usage:
554+
*
555+
* <pre>{@code
556+
* var result = client.getTask(taskId);
557+
* }</pre>
558+
*
559+
* <p>
534560
* <strong>Note:</strong> This is an experimental feature that may change in future
535561
* releases.
536562
* @param taskId The task identifier to query.
537-
* @return The task status and metadata.
563+
* @return The task information.
538564
*/
539565
public McpSchema.GetTaskResult getTask(String taskId) {
540566
Assert.hasText(taskId, "Task ID must not be null or empty");
541-
return getTask(McpSchema.GetTaskRequest.builder().taskId(taskId).build());
567+
return withProvidedContext(this.delegate.getTask(taskId)).block();
542568
}
543569

544570
/**
@@ -560,7 +586,7 @@ public McpSchema.GetTaskResult getTask(String taskId) {
560586
* <pre>{@code
561587
* // For tool task results:
562588
* var result = client.getTaskResult(
563-
* new GetTaskPayloadRequest(taskId, null),
589+
* GetTaskPayloadRequest.builder().taskId(taskId).build(),
564590
* new TypeRef<McpSchema.CallToolResult>(){});
565591
* }</pre>
566592
*
@@ -619,6 +645,7 @@ public <T extends McpSchema.ServerTaskPayloadResult> T getTaskResult(
619645
* @see McpSchema.ServerTaskPayloadResult
620646
*/
621647
public <T extends McpSchema.ServerTaskPayloadResult> T getTaskResult(String taskId, TypeRef<T> resultTypeRef) {
648+
Assert.hasText(taskId, "Task ID must not be null or empty");
622649
return withProvidedContext(this.delegate.getTaskResult(taskId, resultTypeRef)).block();
623650
}
624651

0 commit comments

Comments
 (0)