Commit 4e876be
authored
fix(mcp): copy resource data files to build output directory (#2777)
# 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.
---------
Signed-off-by: shatakshiiii <shatakshimishra01@gmail.com>1 parent c3b9b8f commit 4e876be
4 files changed
Lines changed: 59 additions & 16 deletions
File tree
- packages/ansible-mcp-server
- test/unit/mcp
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
| 26 | + | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
18 | | - | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
24 | 31 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
6 | 14 | | |
7 | 15 | | |
8 | 16 | | |
| |||
20 | 28 | | |
21 | 29 | | |
22 | 30 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | 34 | | |
39 | 35 | | |
40 | 36 | | |
| |||
54 | 50 | | |
55 | 51 | | |
56 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
57 | 95 | | |
0 commit comments