Skip to content

Commit 7c02728

Browse files
committed
chore: fix client documentation for getTask and make impls consistent
1 parent d57c852 commit 7c02728

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
@@ -1579,13 +1579,28 @@ public Mono<McpSchema.CompleteResult> completeCompletion(McpSchema.CompleteReque
15791579
};
15801580

15811581
/**
1582-
* Get the status and metadata of a task.
1582+
* Retrieves a task previously initiated by the client with the server.
1583+
*
1584+
* <p>
1585+
* This method mirrors
1586+
* {@link io.modelcontextprotocol.server.McpAsyncServerExchange#getTask(McpSchema.GetTaskRequest)},
1587+
* which is used for when the server has initiated a task with the client.
1588+
*
1589+
* <p>
1590+
* Example usage:
1591+
*
1592+
* <pre>{@code
1593+
* var result = client.getTask(GetTaskRequest.builder()
1594+
* .taskId(taskId)
1595+
* .build())
1596+
* .block();
1597+
* }</pre>
15831598
*
15841599
* <p>
15851600
* <strong>Note:</strong> This is an experimental feature that may change in future
15861601
* releases.
15871602
* @param getTaskRequest The request containing the task ID.
1588-
* @return A Mono that completes with the task status and metadata.
1603+
* @return A Mono that completes with the task information.
15891604
* @see McpSchema.GetTaskRequest
15901605
* @see McpSchema.GetTaskResult
15911606
*/
@@ -1599,13 +1614,25 @@ public Mono<McpSchema.GetTaskResult> getTask(McpSchema.GetTaskRequest getTaskReq
15991614
}
16001615

16011616
/**
1602-
* Get the status and metadata of a task by ID.
1617+
* Retrieves a task previously initiated by the client with the server by its ID.
1618+
*
1619+
* <p>
1620+
* This method mirrors
1621+
* {@link io.modelcontextprotocol.server.McpAsyncServerExchange#getTask(McpSchema.GetTaskRequest)},
1622+
* which is used for when the server has initiated a task with the client.
16031623
*
16041624
* <p>
16051625
* This is a convenience overload that creates a {@link McpSchema.GetTaskRequest} with
16061626
* the given task ID.
16071627
*
16081628
* <p>
1629+
* Example usage:
1630+
*
1631+
* <pre>{@code
1632+
* var result = client.getTask(taskId);
1633+
* }</pre>
1634+
*
1635+
* <p>
16091636
* <strong>Note:</strong> This is an experimental feature that may change in future
16101637
* releases.
16111638
* @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)