Skip to content

Commit c4f9330

Browse files
committed
Improved cancellation message
1 parent d9fe2f3 commit c4f9330

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

posts/2025-10-23-mcp-standalone-blog.adoc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,21 @@ import jakarta.enterprise.context.ApplicationScoped;
162162
163163
@ApplicationScoped
164164
public class BasicTools {
165-
@Tool(name = "cancellationTool", title = "Cancellable tool", description = "A tool that waits to be cancelled")
166-
public String bigComputationTool(Cancellation cancellation) throws InterruptedException {
167-
String[] citiesArray = { "London", "Japan", "New York" };
168-
for (String city : citiesArray) {
165+
166+
@Tool(name = "processLargeDataset", title = "Process Large Dataset", description = "Processes data in chunks. Can be cancelled by the client.")
167+
public String processLargeDataset(Cancellation cancellation) {
168+
String[] itemsToProcess = { "Item1", "Item2", "Item3" };
169+
List<String> processedItems = new ArrayList<>();
170+
171+
for (String item : itemsToProcess) {
172+
// Throws exception if client requests cancellation
169173
cancellation.skipProcessingIfCancelled();
170-
System.out.println(city);
174+
175+
// Simulates a long running process
176+
processItem(item);
177+
processedItems.add(item);
171178
}
172-
return Arrays.toString(citiesArray);
179+
return processedItems.toString();
173180
}
174181
175182
}

0 commit comments

Comments
 (0)