Add async task support for tool calls with progress tracking#45
Open
Add async task support for tool calls with progress tracking#45
Conversation
When the server supports MCP tasks (capabilities.tasks.requests.tools.call), tools-call automatically uses task-augmented execution. In human mode, an ora spinner shows elapsed time and server status messages. In JSON mode, it blocks until completion and prints the result. - Add callToolWithTask, listTasks, getTask, cancelTask to McpClient, bridge, SessionClient, and IMcpClient interface - Extend IPC protocol with 'task-update' message type for streaming task progress from bridge to CLI - Add --sync flag to tools-call to force synchronous execution - Add tasks-list, tasks-get, tasks-cancel commands (CLI, shell, parser) - Show task capability in server details and execution.taskSupport in tools-get - Add slow-task tool with task support to E2E test server - Declare task capabilities in bridge's MCP client initialization https://claude.ai/code/session_01A1QvyZC9apAe1FPzdsTP2o
…lience - Replace --sync with --async flag: async task execution is now opt-in (previously automatic when server supported it) - Add --detach flag to start async task and return task ID immediately without waiting for completion (implies --async) - Add bridge crash resilience: persist active task IDs to disk so that on bridge restart, existing tasks are polled via getTask() instead of re-invoking the tool (which would create duplicate tasks) - Add callToolDetached() and pollTask() methods to McpClient, bridge, and SessionClient - Update shell to support --async and --detach flags in tools-call https://claude.ai/code/session_01A1QvyZC9apAe1FPzdsTP2o
…s-XUYpP # Conflicts: # src/bridge/index.ts
The test server now has 6 tools (including slow-task added for async task support) but the pagination test still expected 5. https://claude.ai/code/session_01A1QvyZC9apAe1FPzdsTP2o
Tools that declare execution.taskSupport now display [async] in the summary line of tools-list output, alongside existing annotations like [read-only] or [destructive]. https://claude.ai/code/session_01A1QvyZC9apAe1FPzdsTP2o
…to claude/mcp-async-tasks-XUYpP # Conflicts: # src/cli/output.ts
Active tasks for crash recovery were stored in a separate active-tasks.json file. This moves them into sessions.json as an activeTasks field on SessionData, reusing the existing file locking and atomic write infrastructure. https://claude.ai/code/session_01A1QvyZC9apAe1FPzdsTP2o
E2E tests covering:
- --async execution with progress
- --detach execution returning task ID immediately
- tasks-list, tasks-get, tasks-cancel management commands
- Task cancellation of running tasks
- Detached task completion verification
- Synchronous fallback without --async flag
Bug fixes discovered during testing:
- callToolStream was not sending task creation params (task: {}) to
the SDK, causing the stream to skip task-based execution entirely.
Both callToolWithTask and callToolDetached now explicitly pass
task: {} in request options.
- Test server's Task objects were missing required ttl field.
https://claude.ai/code/session_01A1QvyZC9apAe1FPzdsTP2o
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds comprehensive support for MCP's async task capability, enabling long-running tool calls to report progress and status updates to the client. When a server supports task-augmented tool execution, the CLI now automatically uses this capability with a visual progress spinner showing elapsed time and status messages.
Key Changes
Core Task Support
callToolWithTask(),listTasks(),getTask(), andcancelTask()methods that wrap the SDK's experimental task APIstaskToUpdate()helper to convert SDK Task objects to TaskUpdate format, handling optional properties correctlysupportsTasksForToolCall()to check if server supports task-augmented tool callsCLI Tool Execution
tools-callcommand now automatically uses task-augmented execution when the server supports it--syncflag to force synchronous execution, bypassing async tasksformatToolDetail()to displayexecution.taskSupportfieldNew Task Management Commands
formatTask()andformatTasks()with colored status icons (⟳ working, ? input_required, ✔ completed, ✖ failed, ⊘ cancelled)Bridge & Session Client
E2E Test Server
Type System
Implementation Details
https://claude.ai/code/session_01A1QvyZC9apAe1FPzdsTP2o