Skip to content

fix: apply MCP directory argument as the working directory#1600

Open
jmadren wants to merge 1 commit into
VeryGoodOpenSource:mainfrom
jmadren:fix/mcp-directory-working-directory
Open

fix: apply MCP directory argument as the working directory#1600
jmadren wants to merge 1 commit into
VeryGoodOpenSource:mainfrom
jmadren:fix/mcp-directory-working-directory

Conversation

@jmadren
Copy link
Copy Markdown

@jmadren jmadren commented May 29, 2026

Description

The directory argument on the test, packages_get, and packages_check_licenses MCP tools was appended as a positional CLI argument. Those commands resolve their target package from Directory.current and treat positionals as test/target paths, so the value never changed where the command ran. In a monorepo the tools therefore executed from the MCP server's current directory (commonly a folder with no pubspec.yaml) and failed with exit code 66, regardless of whether a relative or absolute directory was supplied.

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

Fix

Apply directory by switching Directory.current for the duration of the run and restoring it in a finally afterwards. Relative paths resolve against the server's current directory, matching the intent of the path/directory parameter from VeryGoodOpenSource/vgv-ai-flutter-plugin#70. A non-existent directory now surfaces a clear tool error instead of a confusing exit code.

Refs VeryGoodOpenSource/vgv-ai-flutter-plugin#70

The `directory` argument on the `test`, `packages_get`, and
`packages_check_licenses` MCP tools was appended as a positional CLI
argument. Those commands resolve their target package from
`Directory.current` and treat positionals as test/target paths, so the
value never changed where the command ran. In a monorepo the tools
therefore executed from the MCP server's current directory (commonly a
folder with no `pubspec.yaml`) and failed with exit code 66, regardless
of whether a relative or absolute `directory` was supplied.

Apply `directory` by switching `Directory.current` for the duration of
the run and restoring it in a `finally` afterwards. Relative paths
resolve against the server's current directory, matching the intent of
the `path`/`directory` parameter from VeryGoodOpenSource/vgv-ai-flutter-plugin#70. A non-existent directory now
surfaces a clear tool error instead of a confusing exit code.

Refs VeryGoodOpenSource/vgv-ai-flutter-plugin#70

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jmadren jmadren requested a review from a team as a code owner May 29, 2026 14:13
@ryzizub ryzizub self-requested a review May 29, 2026 14:24
@ryzizub
Copy link
Copy Markdown
Contributor

ryzizub commented May 29, 2026

Thank you @jmadren for the fix and contribution! Let me take a look and test and i will get back to you 💙

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.

2 participants