Skip to content

fix(mcp): surface command output and run tools in the requested directory#1612

Open
ryzizub wants to merge 1 commit into
mainfrom
claude/romantic-villani-93b902
Open

fix(mcp): surface command output and run tools in the requested directory#1612
ryzizub wants to merge 1 commit into
mainfrom
claude/romantic-villani-93b902

Conversation

@ryzizub

@ryzizub ryzizub commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Status

READY

Description

The very_good_cli MCP test, packages_get, and packages_check_licenses tools had two problems:

  1. Command output was discarded. A failed run returned only "<tool>" failed with exit code 69. — the actual failing tests, compile errors, and logs (written by the in-process mason Logger to stdout/stderr, which the stdio transport shares with the JSON-RPC stream) never reached the client. Agents saw an opaque exit code and could not diagnose failures.
  2. directory did nothing useful. It was appended as a positional CLI argument; the commands resolve their target from the process current directory, so in a monorepo the tool ran from the wrong place and failed with exit code 66.

Changes

  • Capture the in-process command output by redirecting stdout/stderr to a buffer via IOOverrides.runZoned, constructing the mason Logger inside the zone (mason pins IOOverrides.current at construction, so a Logger built outside would still write to the real stdout). The captured output is returned in CallToolResult.content with isError on success and every failure path, and non-JSON is kept off the real stdout that carries the MCP JSON-RPC stream (per the stdio transport spec).
  • Apply directory as the real working directory (Directory.current) for the run and restore it in finally; remove the positional misuse.
  • Serialize tool runs behind an async mutex so the process-global working-directory switch is safe under concurrent/pipelined tool calls (the json_rpc_2 transport can dispatch handlers concurrently).
  • Ignore generated *.vm.json test artifacts.

Connections

Verification

  • MCP suite: 40 tests pass, lib/src/mcp/mcp_server.dart at 100% coverage.
  • dart analyze --fatal-infos --fatal-warnings clean; dart format clean.
  • Verified live through the MCP test tool: a failing package now returns the real failure output and runs in the requested directory. The concurrency fix is covered by a mutation-proven regression test.

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

🤖 Generated with Claude Code

…tory

The `test`, `packages_get`, and `packages_check_licenses` MCP tools
previously returned only an exit code (e.g. 69) and discarded the command
output, and appended `directory` as a positional argument instead of using
it as the working directory.

- Capture the in-process command's mason Logger output via an IOOverrides
  stdout/stderr redirect (with the Logger constructed inside the zone, since
  mason pins IOOverrides.current at construction) and return it in
  CallToolResult.content with isError, so failures are diagnosable. This also
  keeps non-JSON off the real stdout that carries the MCP JSON-RPC stream.
- Apply `directory` as the real working directory for the run and restore it
  afterwards; remove the positional misuse.
- Serialize tool runs so the process-global working-directory switch is safe
  under concurrent (pipelined) tool calls.
- Ignore generated *.vm.json test artifacts.

Closes #1611
Refs #1599, #1600
Refs VeryGoodOpenSource/vgv-ai-flutter-plugin#94

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ryzizub ryzizub marked this pull request as ready for review June 15, 2026 09:06
@ryzizub ryzizub requested a review from a team as a code owner June 15, 2026 09:06
@very-good-code-bot

Copy link
Copy Markdown
Contributor

Sorry, I ran into an error while processing your request. Please try again later.

1 similar comment
@very-good-code-bot

Copy link
Copy Markdown
Contributor

Sorry, I ran into an error while processing your request. Please try again later.

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.

fix: MCP tools report only an exit code and discard the command output

1 participant