Return run outputs in MCP run reads and wait results
Summary
Closes #3630.
An MCP client couldn't get a run's result from the run itself. dagu_read target=run, dagu_execute with wait: true and the dagu://runs/... resources returned status and steps but no outputs, so a chat client had to dig through step logs or call REST.
How it happens: start any DAG with a step that has output: GREETING, wait for it to finish, then call dagu_read with target=run. The response has no outputs, while GET /dag-runs/{name}/{dagRunId}/outputs returns {"greeting": "hello"}.
Changes
- New
API.GetDAGRunDetailsWithOutputsDataloads a run's details and its outputs in one pass, under the same read timeout and visibility checks asGetDAGRunDetailsDataandGetSubDAGRunDetailsData. For a root run it builds the details throughgetDAGRunDetailsData, the same code REST and SSE use, which now also hands back the attempt and status it read, so the outputs come from that attempt with no second lookup. For a sub run it checks the child's workspace first, then does one extra attempt lookup, sinceFindSubDAGRunStatusdoesn't return its attempt.GetSubDAGRunDetailsDatanow sharesgetSubDAGRunDetailswith it. - Outputs are only read for a run with a terminal status (finished and won't change again), since
outputs.jsonis written before that status. The check is a newir.Status.IsTerminal(), and the MCP wait loop'sisTerminalStatusnow calls it too, so the two can't disagree when a status is added. dagu_read target=run(root andsubRunId),dagu_executewait results and both run resources now carryoutputs. A run without outputs keeps today's shape.- Limits: 50 values, 4 KiB per value, 32 KiB in total. A value that doesn't fit is left out whole, never cut, and
outputsOmittedsays how many were left out. If nothing fits, there's nooutputsfield, onlyoutputsOmitted. - If outputs can't be read, or they were written by a different attempt than the
attemptIdbeing returned, the run still comes back withoutputsErrortext. That text is only "outputs could not be read", since the raw file error can include server paths. The API logs the full error, including a failed sub-run attempt lookup, tagged with the root and sub run name and ID. - The resources keep the REST
dagRunDetailsbody and add the same fields at the top level beside it. The body is serialized once, and an unexpected details type is passed through unchanged. - Specs 020, 021 and 036 and the tool reference in
internal/service/mcp/reference.godescribe the new fields.
Not in this PR: step-level outputs, as the issue says. The caps count raw bytes, not JSON-escaped size, and outputsOmitted is a count, not a list of names. The whole outputs.json is still read before the caps apply, the same as the REST endpoint.
Testing
TestBoundedRunOutputs,TestBoundedRunOutputsLimitsandTestWithRunOutputs(internal/service/mcp) cover the resource body shape and no outputs, normal outputs, a read error, another attempt's outputs, the count, per-value and total limits, and the case where no value fits.TestStatus_IsTerminal(internal/ir) covers every status plus an unknown one.TestReadRunOutputs(spec021) reads a parent and a sub-DAG run through the read tool and the resources.TestReadRunWithoutOutputschecks a run with no outputs gets no new fields.TestExecuteStartWithWaitReturnsRunResult(spec036) now checksrun.outputs.- Before the fix:
run has no outputs: map[attemptId:... status:4 ...], and in spec036expected: map[result:done] actual: <nil>. After: all pass. - Ran
go vet,go testandgolangci-linton./internal/ir/...,./internal/service/mcp/...,./internal/service/frontend/...,./conformance/spec020_mcp_server/...,./conformance/spec021_mcp_read_tool/...and./conformance/spec036_mcp_execute_tool/.... I didn't runmake test,make conformanceor the UI checks. The sub-run access rule and the new log lines aren't covered by a test.
Environment: main @ 52aee31 + f8ad9b98, go1.27.3, darwin/arm64.
Checklist
- Code follows the project style guidelines
- Self-review of the code has been performed
- Tests have been added or updated as needed
- Documentation has been updated as needed
- Changes have been tested locally