Add tasks-result command to fetch final async task results#171
Merged
Conversation
Implements the MCP `tasks/result` method as a new `tasks-result <taskId>` command. Blocks until the task reaches a terminal state, then prints the `CallToolResult` payload using the same renderer as `tools-call`. `--json` returns the raw payload. Closes #168
Extracts a `renderCallToolResult` helper in `src/cli/commands/tools.ts`
so both `tools-call` and `tasks-result` render the payload through the
same code path — identical success/error banners, `formatOutput`, and
`--max-chars` handling in human mode; raw `CallToolResult` JSON in
`--json` mode.
Aligns the `mcpc help tasks-result` `--json` section with `tools-call`:
same `{ content: [{ type, text?, ... }], isError?, structuredContent? }`
shape and the `#calltoolresult` schema link.
…hpA' into claude/implement-tasks-result-djhpA # Conflicts: # src/cli/index.ts
…s-result-djhpA # Conflicts: # README.md
…hpA' into claude/implement-tasks-result-djhpA
Prints a follow-up "Run mcpc @session tasks-result <taskId> to fetch the result once the task completes" line after: - `tools-call --detach` (task started in background) - `tools-call --task` when the user presses ESC to detach - `tasks-list` (when there are tasks) — with a `<taskId>` placeholder so the user picks one from the list Hints are human-mode only; `--json` output is unchanged.
The hint previously suggested waiting for the task to complete before calling tasks-result, but the command can be called at any time — it blocks on the server until the task reaches a terminal state. All three hint sites (tools-call --detach, tools-call ESC-detach, tasks-list) now use the same wording: "fetch the task's final result (blocks until it finishes)".
Rewords the three tasks-result hints to match the existing dim/indented
hint style used elsewhere (sessions.ts, grep.ts). Drops the info icon
and splits into two lines:
To fetch the task's final result, run:
mcpc @session tasks-result <taskId>
Applies to `tools-call --detach`, `tools-call --task` ESC-detach, and
`tasks-list`.
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 a new
tasks-result <taskId>command that fetches the finalCallToolResultpayload of an async task via the MCPtasks/resultprotocol method. The command blocks on the server until the task reaches a terminal state before returning the result.Fixes #168
Key Changes
New CLI command:
tasks-result <taskId>- fetches and displays the final result of an async task--jsonflagtools-callfor consistencyCore client implementation: Added
getTaskResult()method toMcpClientthat wraps the MCPtasks/resultprotocol methodSession client support: Added
getTaskResult()toSessionClientfor bridge communicationBridge process: Added handler for
getTaskResultRPC callsShell integration: Added
tasks-resultcommand support in interactive shell modeDocumentation updates:
Test coverage: Added comprehensive e2e tests covering:
CallToolResultpayload validationImplementation Details
tools-calltasks-list,tasks-get,tasks-cancel)https://claude.ai/code/session_01KxvJ6iKNXMtWv429TA8huH