Skip to content

Add tasks-result command to fetch final async task results#171

Merged
jancurn merged 14 commits into
mainfrom
claude/implement-tasks-result-djhpA
Apr 15, 2026
Merged

Add tasks-result command to fetch final async task results#171
jancurn merged 14 commits into
mainfrom
claude/implement-tasks-result-djhpA

Conversation

@jancurn

@jancurn jancurn commented Apr 15, 2026

Copy link
Copy Markdown
Member

Summary

This PR adds a new tasks-result <taskId> command that fetches the final CallToolResult payload of an async task via the MCP tasks/result protocol 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

    • Blocks until the task reaches a terminal state (per MCP spec)
    • Outputs formatted result in human-readable mode or raw JSON with --json flag
    • Uses the same output renderer as tools-call for consistency
  • Core client implementation: Added getTaskResult() method to McpClient that wraps the MCP tasks/result protocol method

  • Session client support: Added getTaskResult() to SessionClient for bridge communication

  • Bridge process: Added handler for getTaskResult RPC calls

  • Shell integration: Added tasks-result command support in interactive shell mode

  • Documentation updates:

    • Updated help text and README with new command
    • Added usage examples in async tasks documentation
    • Updated CHANGELOG with feature description
  • Test coverage: Added comprehensive e2e tests covering:

    • Basic result fetching with human and JSON output modes
    • Blocking behavior until task completion
    • Proper CallToolResult payload validation

Implementation Details

  • The command integrates seamlessly with existing task infrastructure, reusing the same output formatting as tools-call
  • Properly handles both successful and error task results
  • Maintains consistency with other task commands (tasks-list, tasks-get, tasks-cancel)
  • Includes proper error handling and logging throughout the call chain

https://claude.ai/code/session_01KxvJ6iKNXMtWv429TA8huH

claude and others added 14 commits April 15, 2026 14:00
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
…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`.
@jancurn jancurn merged commit 5642960 into main Apr 15, 2026
6 checks passed
@jancurn jancurn deleted the claude/implement-tasks-result-djhpA branch April 15, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tasks-result command

3 participants