fix(mcp): copy resource data files to build output directory#2777
fix(mcp): copy resource data files to build output directory#2777shatakshiiii wants to merge 2 commits intoansible:mainfrom
Conversation
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>
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughChanges 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Review rate limit: 0/1 reviews remaining, refill in 4 minutes and 35 seconds.Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/ansible-mcp-server/tsup.config.ts (1)
26-30: ⚡ Quick winDouble-check watch-mode propagation for
src/resources/data.This copy only runs in
onSuccess; iftsup --watchdoes not treat these markdown files as inputs, edits undersrc/resources/datawill 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
📒 Files selected for processing (3)
.vscodeignorepackages/ansible-mcp-server/package.jsonpackages/ansible-mcp-server/tsup.config.ts
💤 Files with no reviewable changes (1)
- .vscodeignore
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
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>
alisonlhart
left a comment
There was a problem hiding this comment.
LGTM, tested locally and is working!
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 byansible_content_best_practicesee-rules.md— execution environment rules used bydefine_and_build_execution_envexecution-environment-schema.json— JSON schema for EE validationexecution-environment-sample.yml— sample EE configThese files live at
packages/ansible-mcp-server/src/resources/data/.How the code finds them: When a tool like
define_and_build_execution_envruns, it callsresolveResourcePath("ee-rules.md", import.meta.url)insrc/utils/resourcePath.ts. This function figures out which directory the running code lives in (using__dirnamefor CJS orimport.meta.urlfor ESM), then appends/data/ee-rules.mdto that directory.What happens in the packaged extension: The build tool (tsup) bundles all TypeScript into
dist/cli.cjs. When this bundled file runs,__dirnameresolves todist/. So the code looks fordist/data/ee-rules.md.But
dist/data/didn't exist. tsup only compiles.tsfiles — it has no built-in mechanism to copy non-code assets like.mdor.jsonfiles. The data files stayed insrc/resources/data/and were never copied to the build output.The
.vscodeignorehad 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 insrc/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 anonSuccesscallback that runs after each tsup build and copies the data files to the right location:dist/): copies todist/data/— because the bundledcli.cjshas__dirname = dist/lib/): copies tolib/resources/data/— because non-bundled files likelib/resources/eeSchema.jshave__dirname = lib/resources/The
onSuccesshook runs after tsup finishes (and afterclean: truewipes 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 indist/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 thefilesarray. Same reasoning —"dist"and"lib"already cover the data files for npm publishing now.