Skip to content

fix(mcp): apply directory argument as the working directory#1600

Open
jmadren wants to merge 2 commits into
VeryGoodOpenSource:mainfrom
jmadren:fix/mcp-directory-working-directory
Open

fix(mcp): apply directory argument as the working directory#1600
jmadren wants to merge 2 commits into
VeryGoodOpenSource:mainfrom
jmadren:fix/mcp-directory-working-directory

Conversation

@jmadren

@jmadren jmadren commented May 29, 2026

Copy link
Copy Markdown

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.

Closes #1599

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

ryzizub commented May 29, 2026

Copy link
Copy Markdown
Contributor

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

@ryzizub ryzizub left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, this is an awesome contribution and it actually solves the issue!
But I think we could add that option to the test command itself and not doing this override. That way both the MCP and the command can change the directory and also select the test (which is what's working right now).
Would you be open to making that update?

@jmadren

jmadren commented Jun 1, 2026

Copy link
Copy Markdown
Author

I'm not sure I follow. I thought the issue was the MCP command didn't use the directory parameter correctly, so how would adding (another) option to the test command fix this?

@marcossevilla marcossevilla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good to approve/merge this, thoughts @ryzizub ?

@ryzizub

ryzizub commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Yeah @marcossevilla, I'm good too. I'll do a couple of tests, but I think it's great :)

@jmadren just for context, the questions earlier were about the idea of adding a --directory option to the test command. But we agreed internally that your PR is good and less invasive ❤️

@marcossevilla marcossevilla moved this from Needs Triage to In Review in VGV Open Source 🦄 🧙🌟 Jun 4, 2026
@marcossevilla marcossevilla changed the title fix: apply MCP directory argument as the working directory fix(mcp): apply directory argument as the working directory Jun 9, 2026

@ryzizub ryzizub left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, good job @jmadren

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

vgv-ai-flutter-plugin feat #70 doesn't work

3 participants