Skip to content

fix(mcp): copy resource data files to build output directory#2777

Open
shatakshiiii wants to merge 2 commits intoansible:mainfrom
shatakshiiii:fix/mcp-resource-files-missing-from-vsix
Open

fix(mcp): copy resource data files to build output directory#2777
shatakshiiii wants to merge 2 commits intoansible:mainfrom
shatakshiiii:fix/mcp-resource-files-missing-from-vsix

Conversation

@shatakshiiii
Copy link
Copy Markdown
Contributor

@shatakshiiii shatakshiiii commented Apr 30, 2026

Fix: MCP server resource files missing from VSIX

The Problem

The MCP server has 4 data files that tools need at runtime:

  • agents.md — best practices guidelines used by ansible_content_best_practices
  • ee-rules.md — execution environment rules used by define_and_build_execution_env
  • execution-environment-schema.json — JSON schema for EE validation
  • execution-environment-sample.yml — sample EE config

These files live at packages/ansible-mcp-server/src/resources/data/.

How the code finds them: When a tool like define_and_build_execution_env runs, it calls resolveResourcePath("ee-rules.md", import.meta.url) in src/utils/resourcePath.ts. This function figures out which directory the running code lives in (using __dirname for CJS or import.meta.url for ESM), then appends /data/ee-rules.md to that directory.

What happens in the packaged extension: The build tool (tsup) bundles all TypeScript into dist/cli.cjs. When this bundled file runs, __dirname resolves to dist/. So the code looks for dist/data/ee-rules.md.

But dist/data/ didn't exist. tsup only compiles .ts files — it has no built-in mechanism to copy non-code assets like .md or .json files. The data files stayed in src/resources/data/ and were never copied to the build output.

The .vscodeignore had a line !packages/ansible-mcp-server/src/resources/data/**/* which did ship the source data files inside the VSIX — but it didn't matter because the runtime code never looks in src/resources/data/. It only looks relative to where the compiled code runs from (dist/).

The Fix

1. packages/ansible-mcp-server/tsup.config.ts — Added an onSuccess callback that runs after each tsup build and copies the data files to the right location:

  • Production build (dist/): copies to dist/data/ — because the bundled cli.cjs has __dirname = dist/
  • Dev build (lib/): copies to lib/resources/data/ — because non-bundled files like lib/resources/eeSchema.js have __dirname = lib/resources/

The onSuccess hook runs after tsup finishes (and after clean: true wipes the output dir), so the copied files survive in the final output.

2. .vscodeignore — Removed the !packages/ansible-mcp-server/src/resources/data/**/* line. Since data files are now properly in dist/data/, the existing !packages/ansible-mcp-server/dist/**/* line already includes them. This avoids shipping duplicate copies of the data files in the VSIX.

3. packages/ansible-mcp-server/package.json — Removed "./src/resources/data/**/*" from the files array. Same reasoning — "dist" and "lib" already cover the data files for npm publishing now.

The MCP server data files (agents.md, ee-rules.md, etc.) were not
being copied to dist/ during the build, causing tools like
define_and_build_execution_env to fail with resource path errors
in the packaged extension.

Add an onSuccess hook to tsup that copies src/resources/data/ into
the output directory after each build. Remove the now-redundant
src/resources/data entries from .vscodeignore and package.json files
since dist/ and lib/ already cover them.

Signed-off-by: shatakshiiii <shatakshimishra01@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Warning

Rate limit exceeded

@shatakshiiii has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 35 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 0c3f4f4e-c67d-498d-9aaf-1b4da545842c

📥 Commits

Reviewing files that changed from the base of the PR and between 7e4579b and 95b0b55.

📒 Files selected for processing (1)
  • test/unit/mcp/mcpPackaging.test.ts
📝 Walkthrough

Walkthrough

Changes modify how resource data files are distributed and built. Exclusion rules are removed from version control and npm package configurations, but a post-build hook is added to copy the data files into the compiled output directory during the build process.

Changes

Cohort / File(s) Summary
Distribution Configuration
.vscodeignore, packages/ansible-mcp-server/package.json
Removes whitelist entries that previously included src/resources/data/**/* in VS Code extension package and npm distribution, making these files subject to default exclusions.
Build Configuration
packages/ansible-mcp-server/tsup.config.ts
Adds outDir constant and introduces an onSuccess hook that copies src/resources/data into the build output directory (data for production, resources/data for non-production) using filesystem synchronous copy.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A rabbit's clever scheme,
Moving data from the stream,
Build-time magic, files align,
Assets bundled, structures shine!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: copying resource data files to the build output directory, which is the core fix across all three modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 4 minutes and 35 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/ansible-mcp-server/tsup.config.ts (1)

26-30: ⚡ Quick win

Double-check watch-mode propagation for src/resources/data.

This copy only runs in onSuccess; if tsup --watch does not treat these markdown files as inputs, edits under src/resources/data will stay stale until a manual rebuild. Please verify that the watcher covers this directory, or add an explicit asset-watch step if needed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/ansible-mcp-server/tsup.config.ts` around lines 26 - 30, The copy in
onSuccess only runs after builds and doesn’t guarantee tsup’s watch picks up
changes under src/resources/data; update the tsup config so the watcher tracks
that directory (for example add watch: ['src/resources/data'] or include the
folder in tsup’s entry/watch globs), or implement an explicit file-watcher that
re-runs the cpSync copy when files change during watch mode (hooking into the
same onSuccess/cpSync logic or using chokidar) so edits to src/resources/data
are propagated immediately; reference the onSuccess handler, the cpSync call,
and the src/resources/data path when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/ansible-mcp-server/tsup.config.ts`:
- Around line 26-30: The copy in onSuccess only runs after builds and doesn’t
guarantee tsup’s watch picks up changes under src/resources/data; update the
tsup config so the watcher tracks that directory (for example add watch:
['src/resources/data'] or include the folder in tsup’s entry/watch globs), or
implement an explicit file-watcher that re-runs the cpSync copy when files
change during watch mode (hooking into the same onSuccess/cpSync logic or using
chokidar) so edits to src/resources/data are propagated immediately; reference
the onSuccess handler, the cpSync call, and the src/resources/data path when
making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 038f229b-eb6e-4c6d-a4fa-de42465a0339

📥 Commits

Reviewing files that changed from the base of the PR and between 655cff1 and 7e4579b.

📒 Files selected for processing (3)
  • .vscodeignore
  • packages/ansible-mcp-server/package.json
  • packages/ansible-mcp-server/tsup.config.ts
💤 Files with no reviewable changes (1)
  • .vscodeignore

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The test asserted that src/resources/data was whitelisted in
.vscodeignore, but that entry was removed since dist/**/* already
covers the data files after the build copy step.

Signed-off-by: shatakshiiii <shatakshimishra01@gmail.com>
Copy link
Copy Markdown
Contributor

@alisonlhart alisonlhart left a comment

Choose a reason for hiding this comment

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

LGTM, tested locally and is working!

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

Labels

Projects

Status: Review

Development

Successfully merging this pull request may close these issues.

2 participants