@nera-static/mcp 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nera",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Create, edit, build, validate, preview and publish websites made with Nera, a static site generator: the Nera skill plus the Nera MCP server, which works only inside the sites folder you pick on enable.",
5
5
  "author": {
6
6
  "name": "Michael Becker"
@@ -29,7 +29,7 @@
29
29
  "command": "npx",
30
30
  "args": [
31
31
  "-y",
32
- "@nera-static/mcp@1.2.0",
32
+ "@nera-static/mcp@1.2.1",
33
33
  "--root",
34
34
  "${user_config.root}"
35
35
  ]
package/CHANGELOG.md CHANGED
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.2.1] - 2026-11-19
9
+
10
+ ### Changed
11
+
12
+ - `add_plugin` installs the plugin with `addPlugin()` from `@nera-static/nera` inside the server instead of running `npm install`, its own config copy and the package's template script itself. Its inputs, refusals and result shape are unchanged; the result's `log` holds `addPlugin`'s progress lines, while npm's and the template script's output goes to the server's log (stderr). Cancelling the call stops the running command, and with `NERA_MCP_RUNTIME=bundled` it gets the same environment as every other command.
13
+ - `add_plugin` refuses a config folder or `config/<name>.yaml` that is a symbolic link out of the site before anything is installed.
14
+ - Requires `@nera-static/nera` ^1.26.0 (was ^1.25.0), the first release with `addPlugin`.
15
+
16
+ ### Fixed
17
+
18
+ - `add_plugin` accepts `plugin-<name>` (e.g. `plugin-tags`) like the CLI; it used to ask npm for `@nera-static/plugin-plugin-tags`.
19
+
8
20
  ## [1.2.0] - 2026-11-18
9
21
 
10
22
  ### Added
package/README.md CHANGED
@@ -106,13 +106,13 @@ A **site** is a folder under the root (or the root itself) whose `package.json`
106
106
  | `get_site` | A site's configuration, pages, plugins and theme |
107
107
  | `read_page`, `write_page`, `delete_page` | A Markdown page with its frontmatter; `write_page` refuses frontmatter without `layout` |
108
108
  | `read_file`, `write_file` | Configuration, templates and assets inside a site |
109
- | `add_plugin` | Installs an `@nera-static/plugin-*`, copies its default config and publishes its templates |
109
+ | `add_plugin` | Installs an official plugin (`@nera-static/plugin-<name>`, `plugin-<name>` or `<name>`) as `nera add` does: the package, its default config and its templates |
110
110
  | `build` | `nera build`, optionally with the output checks (`check: true`) |
111
111
  | `validate` | `nera validate`: the site's layouts, includes and YAML, as `{ file, line, severity, rule, message }` records |
112
112
  | `preview` | Starts `nera dev` and returns the local address; `stop: true` stops it |
113
113
  | `publish` | `nera publish` to GitHub Pages or Netlify; returns the sign-in code for you, then the live address |
114
114
 
115
- `create_site`, `validate` and the catalogs call `@nera-static/nera`'s own functions inside the server; `build`, `preview`, `publish` and `add_plugin` run commands, through the site's own `@nera-static/nera` when it has one installed, so the assistant gets the same results as you do in a terminal. A preview or a publish keeps running between calls and stops when the client closes the server.
115
+ `create_site`, `add_plugin`, `validate` and the catalogs call `@nera-static/nera`'s own functions inside the server; `build`, `preview` and `publish` run commands, through the site's own `@nera-static/nera` when it has one installed, so the assistant gets the same results as you do in a terminal. A preview or a publish keeps running between calls and stops when the client closes the server.
116
116
 
117
117
  ### Resources
118
118
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nera-static/mcp",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "A local MCP server for Nera: lets an AI assistant create, edit, build, validate, preview and publish Nera static sites under one folder",
5
5
  "type": "module",
6
6
  "files": [
@@ -47,7 +47,7 @@
47
47
  "dependencies": {
48
48
  "@modelcontextprotocol/sdk": "^1.32.2",
49
49
  "@nera-static/core": "^4.18.3",
50
- "@nera-static/nera": "^1.25.0",
50
+ "@nera-static/nera": "^1.26.0",
51
51
  "yaml": "^2.9.1",
52
52
  "zod": "^4.6.7"
53
53
  },
@@ -37,8 +37,9 @@ Eleventy, Hugo, Astro or Jekyll; do not apply their conventions.
37
37
  frontmatter that names its `layout`. Site name, language and texts for
38
38
  templates go in `config/app.yaml`. Shared markup goes in `theme/views/`.
39
39
  3. **Plugins.** Look for a plugin before writing a feature (see below).
40
- Install it, configure it in `config/<name>.yaml`, copy its templates with
41
- its own binary and include them in a layout.
40
+ `npx nera add <name>` installs it, copies its default `config/<name>.yaml`
41
+ (an existing one is kept) and its templates; configure it there and
42
+ include the templates in a layout.
42
43
  4. **Validate.** `npx nera validate` and fix every error it reports. It
43
44
  finds broken layouts and includes and pages the build would skip.
44
45
  5. **Build and check.** `npx nera build --check` and fix what it reports
@@ -78,8 +79,14 @@ and refreshes `AGENTS.md` and this skill.
78
79
 
79
80
  ## Look for a plugin before writing a feature
80
81
 
81
- Features come from npm packages named `@nera-static/plugin-<name>`. An
82
- installed plugin loads on the next build, with nothing to register. Do not
82
+ Features come from npm packages named `@nera-static/plugin-<name>`. Add one
83
+ with `npx nera add <name>` (e.g. `npx nera add sitemap`): it installs the
84
+ package, copies the plugin's default `config/<name>.yaml` when the site has
85
+ none and copies its templates into `theme/views/vendor/plugin-<name>/`, if
86
+ it has any. That copy is skipped when the folder already exists;
87
+ `npx nera-<name> --force`, the plugin's own binary, overwrites it. Templates
88
+ are not used until you include them. An added plugin loads on the next
89
+ build, with nothing to register. Do not
83
90
  hand-write navigation, a contact form, tags, search, pagination, image
84
91
  handling, a sitemap, a feed or a consent banner: a plugin exists for each.
85
92
  The catalog: https://github.com/seebaermichi/nera/blob/main/PLUGINS.md
@@ -89,7 +96,7 @@ feed, images, link-attributes, navigation, one-page, page-navigation,
89
96
  page-pagination, popular-content, search, simple-page-list, sitemap,
90
97
  social-media-links, stacks, statistics, tags. Each plugin's README (on npm, or
91
98
  `github.com/seebaermichi/nera-plugin-<name>`) lists its config keys and its
92
- template binary. Read it before you configure the plugin.
99
+ templates. Read it before you configure the plugin.
93
100
 
94
101
  A feature no plugin covers can be a local plugin in
95
102
  `src/plugins/<name>/index.js`; see the tutorial
@@ -21,24 +21,24 @@ different files.
21
21
  `pages/posts/first-post.md`, each with `layout`, `title`, `description`,
22
22
  `date` (`2026-10-12`) and `tags` (`tags: travel, food` or a YAML list).
23
23
  A post is served at `/posts/first-post.html`.
24
- 3. Post list: `npm install @nera-static/plugin-simple-page-list`, set
25
- `page_path: /posts`, `sortBy: date` and `sortOrder: descending` in
26
- `config/simple-page-list.yaml`, run
27
- `npx nera-simple-page-list`, and include the list in the template of the
28
- home page (data: `app.pageList`).
29
- 4. Tags: `npm install @nera-static/plugin-tags`. It builds a page per tag
30
- at `/tags/<tag>.html`. Run `npx nera-tags` and include
31
- `partials/tag-links` in the post template and `partials/tag-cloud` where
32
- you want all tags.
33
- 5. Previous/next: `npm install @nera-static/plugin-page-pagination`, give
34
- each post a `pagination_order` number, run `npx nera-page-pagination`
35
- and include it in the post template. It links pages of the same folder.
24
+ 3. Post list: `npx nera add simple-page-list`. Its copied
25
+ `config/simple-page-list.yaml` already lists `page_paths: [/posts]`,
26
+ newest `date` first; include the published template in the home page's
27
+ template (data: `app.pageList.posts`).
28
+ 4. Tags: `npx nera add tags`. It builds a page per tag at
29
+ `/tags/<tag>.html`. Include the published `partials/tag-links` in the
30
+ post template and `partials/tag-cloud` where you want all tags. Delete
31
+ the sample `tag_overview_*_image` lines and `tag_overview_meta` from the
32
+ copied `config/tags.yaml`: they point at images the site does not have.
33
+ 5. Previous/next: `npx nera add page-pagination`, give each post a
34
+ `pagination_order` number and include the published template in the post
35
+ template. It links pages of the same folder.
36
36
  6. A post template of its own: `theme/views/pages/post.pug`, extending
37
37
  `../layouts/layout` like `pages/default.pug`, with exactly one `main`.
38
38
  Posts then use `layout: pages/post.pug`.
39
- 7. Sitemap: `npm install @nera-static/plugin-sitemap` and set `origin` in
40
- `config/app.yaml`. It also writes `robots.txt`.
41
- 8. Menu: `@nera-static/plugin-navigation`, as in
39
+ 7. Sitemap: `npx nera add sitemap` and set `origin` in `config/app.yaml`.
40
+ It also writes `robots.txt`.
41
+ 8. Menu: `npx nera add navigation`, as in
42
42
  [business-site](business-site.md).
43
43
  9. `npx nera validate`, then `npx nera build --check`; fix what they report.
44
44
 
@@ -48,7 +48,8 @@ before step 3, 4 or 5.
48
48
  ## Files touched
49
49
 
50
50
  `pages/posts/*.md`, `pages/index.md`, `config/app.yaml`,
51
- `config/simple-page-list.yaml`, `config/tags.yaml` (optional),
51
+ `config/simple-page-list.yaml`, `config/tags.yaml`,
52
+ `config/page-pagination.yaml`, `config/sitemap.yaml`,
52
53
  `theme/views/pages/post.pug`, `theme/views/vendor/plugin-*/`,
53
54
  `package.json`.
54
55
 
@@ -24,16 +24,16 @@ below build the site by hand instead, with different files.
24
24
  `pages/imprint.md` and `pages/privacy.md` as placeholders, linked from
25
25
  the layout's footer: replace their text, or write them if they are
26
26
  missing.
27
- 4. Menu: `npm install @nera-static/plugin-navigation`, list the pages in
28
- `config/navigation.yaml` (`href` ending in `.html`, `name`; groups such
29
- as `main:` and `footer:`; a footer menu replaces the layout's own
30
- imprint and privacy links, so keep only one of the two), run
31
- `npx nera-navigation` and include a menu in
27
+ 4. Menu: `npx nera add navigation`, then replace the sample entry in the
28
+ copied `config/navigation.yaml` with the pages (`href` ending in
29
+ `.html`, `name`; groups such as `main:` and `footer:`; a footer menu
30
+ replaces the layout's own imprint and privacy links, so keep only one of
31
+ the two), and include a published menu in
32
32
  `theme/views/layouts/layout.pug` (see the plugin README for the mixins).
33
33
  5. Contact form: follow [contact-form](contact-form.md).
34
- 6. Optional, for search engines: `@nera-static/plugin-sitemap` (needs
35
- `origin`) and `@nera-static/plugin-canonical-links`. Social profiles:
36
- `@nera-static/plugin-social-media-links`.
34
+ 6. Optional, for search engines: `npx nera add sitemap` (needs `origin`)
35
+ and `npx nera add canonical-links`. Social profiles:
36
+ `npx nera add social-media-links`.
37
37
  7. Styles: a CSS file in `theme/assets/css/`, linked from the layout's
38
38
  `head` (`link(rel="stylesheet" href="/css/main.css")`).
39
39
  8. `npx nera validate`, then `npx nera build --check`; fix what they report.
@@ -6,10 +6,14 @@ Do not hand-write a `<form>` or post to a third-party service.
6
6
 
7
7
  ## Steps
8
8
 
9
- 1. `npm install @nera-static/plugin-contact-form`
10
- 2. Create `config/contact-form.yaml`. `recipient` and at least one field
11
- are required; without them the form does not render and the build only
12
- warns:
9
+ 1. `npx nera add contact-form` installs the plugin, copies its default
10
+ `config/contact-form.yaml`, the form to
11
+ `theme/views/vendor/plugin-contact-form/` and its script to
12
+ `theme/assets/js/contact-form.js`.
13
+ 2. Edit the copied `config/contact-form.yaml`: put the real address in
14
+ `recipient` (the copy has the placeholder `hello@example.com`).
15
+ `recipient` and at least one field are required; without them the form
16
+ does not render and the build only warns. A minimal config:
13
17
 
14
18
  ```yaml
15
19
  recipient: hello@example.com
@@ -31,10 +35,7 @@ Do not hand-write a `<form>` or post to a third-party service.
31
35
  Field types: `text`, `email`, `tel`, `textarea`, `select`, `checkbox`,
32
36
  `radio`. The README lists the optional keys (subject, labels, honeypot,
33
37
  `consent_text` with a link to the privacy page).
34
- 3. `npx nera-contact-form` copies the form to
35
- `theme/views/vendor/plugin-contact-form/` and its script to
36
- `theme/assets/js/contact-form.js`.
37
- 4. A page template for the contact page, `theme/views/pages/contact.pug`:
38
+ 3. A page template for the contact page, `theme/views/pages/contact.pug`:
38
39
 
39
40
  ```pug
40
41
  extends ../layouts/layout
@@ -45,9 +46,9 @@ Do not hand-write a `<form>` or post to a third-party service.
45
46
  include /vendor/plugin-contact-form/contact-form
46
47
  ```
47
48
 
48
- 5. `pages/contact.md` with `layout: pages/contact.pug`, a `title` and a
49
+ 4. `pages/contact.md` with `layout: pages/contact.pug`, a `title` and a
49
50
  short text above the form.
50
- 6. `npx nera validate`, then `npx nera build --check`. Open
51
+ 5. `npx nera validate`, then `npx nera build --check`. Open
51
52
  `/contact.html` with `npm run dev` and submit once: the mail client
52
53
  should open with the message filled in.
53
54
 
@@ -6,7 +6,8 @@ Responsive images with `@nera-static/plugin-images`: each picture becomes a
6
6
 
7
7
  ## Steps
8
8
 
9
- 1. `npm install @nera-static/plugin-images`
9
+ 1. `npx nera add images` installs the plugin and copies its `picture`
10
+ mixin to `theme/views/vendor/plugin-images/`.
10
11
  2. Put the originals in the assets folder, e.g. `theme/assets/images/`.
11
12
  They are referenced without `theme/assets`: `/images/photo.jpg`.
12
13
  3. In Markdown, write images as usual; the plugin rewrites them:
@@ -14,8 +15,7 @@ Responsive images with `@nera-static/plugin-images`: each picture becomes a
14
15
  (`![Alt](/images/pier.jpg "Caption")`), and query parameters crop or
15
16
  size one image (`?w=800&ratio=16:9`, see the README).
16
17
  4. In frontmatter, `image: /images/hero.jpg` gets precomputed variants for
17
- templates. Run `npx nera-images` to copy the `picture` mixin to
18
- `theme/views/vendor/plugin-images/`, then in a template:
18
+ templates. Show them with the copied `picture` mixin in a template:
19
19
 
20
20
  ```pug
21
21
  include /vendor/plugin-images/picture
@@ -24,17 +24,16 @@ instead, with different files.
24
24
  `title`, `description`, `date` and `image: /images/<file>.jpg` (the cover
25
25
  picture). Show more photos in the body with
26
26
  `![Alt text](/images/<file>.jpg "Caption")`.
27
- 4. Project list: `npm install @nera-static/plugin-simple-page-list`, set
28
- `page_path: /projects` in `config/simple-page-list.yaml`, run
29
- `npx nera-simple-page-list`, and render `app.pageList` on the home page.
30
- For a grid with cover images, loop over `app.pageList` in your own Pug
31
- template instead of the published one.
27
+ 4. Project list: `npx nera add simple-page-list`, change `page_paths` in
28
+ the copied `config/simple-page-list.yaml` to `[/projects]`, and render
29
+ `app.pageList.projects` on the home page. For a grid with cover images,
30
+ loop over it in your own Pug template instead of the published one.
32
31
  5. A project template, `theme/views/pages/project.pug`, extending
33
32
  `../layouts/layout`, that shows the cover with the images plugin's
34
33
  `+picture` mixin and then `content`, with exactly one `main`.
35
- 6. Optional: `@nera-static/plugin-tags` to group projects by kind,
36
- `@nera-static/plugin-page-pagination` for previous/next project,
37
- `@nera-static/plugin-social-media-links`, `@nera-static/plugin-sitemap`.
34
+ 6. Optional, each with `npx nera add <name>`: `tags` to group projects by
35
+ kind, `page-pagination` for previous/next project, `social-media-links`,
36
+ `sitemap`.
38
37
  7. `npx nera validate`, then `npx nera build --check`. The check reports
39
38
  images without alt text; describe what each picture shows.
40
39
 
@@ -5,13 +5,12 @@ JSON index, a small script searches it in the browser. No backend.
5
5
 
6
6
  ## Steps
7
7
 
8
- 1. `npm install @nera-static/plugin-search`. It works without config;
9
- `config/search.yaml` can change the indexed `fields` or set
10
- `group_by_lang: true` for one index per language.
11
- 2. `npx nera-search` copies the search template to
12
- `theme/views/vendor/plugin-search/` and its script to
8
+ 1. `npx nera add search` installs the plugin, copies its default
9
+ `config/search.yaml` (change the indexed `fields` there, or set
10
+ `group_by_lang: true` for one index per language), the search template
11
+ to `theme/views/vendor/plugin-search/` and its script to
13
12
  `theme/assets/js/search.js`.
14
- 3. A page template for the search page, `theme/views/pages/search.pug`:
13
+ 2. A page template for the search page, `theme/views/pages/search.pug`:
15
14
 
16
15
  ```pug
17
16
  extends ../layouts/layout
@@ -22,27 +21,27 @@ JSON index, a small script searches it in the browser. No backend.
22
21
  include /vendor/plugin-search/search.pug
23
22
  ```
24
23
 
25
- 4. `pages/search.md` with `layout: pages/search.pug`, a `title` and a
24
+ 3. `pages/search.md` with `layout: pages/search.pug`, a `title` and a
26
25
  `# Search` heading, and `show_title: false` in `config/search.yaml`, so
27
- that heading is the page's only `h1` (without the key the template adds
28
- its own and `nera build --check` warns `a11y-h1`). Link the page from
29
- the menu.
30
- 5. The template's input is already labelled (`aria-label`, default
26
+ that heading is the page's only `h1` (with the copy's `show_title: true`
27
+ the template adds its own and `nera build --check` warns `a11y-h1`).
28
+ Link the page from the menu.
29
+ 4. The template's input is already labelled (`aria-label`, default
31
30
  "Search"). To translate the template, add `search_label`, `search_title`
32
31
  and `search_placeholder` to the site's translations. A copy published
33
32
  before plugin-search 2.3.0 lacks both: refresh it with
34
33
  `npx nera-search --force` if it was never edited.
35
- 6. The index is written to `theme/assets/search-index.json` on every build
34
+ 5. The index is written to `theme/assets/search-index.json` on every build
36
35
  and served as `/search-index.json`. It is generated: add
37
36
  `theme/assets/search-index*.json` to `.gitignore`.
38
- 7. Only pages with a `layout` are indexed. If other plugins add pages (tags),
37
+ 6. Only pages with a `layout` are indexed. If other plugins add pages (tags),
39
38
  run search last with `config/plugin-order.yaml` as the README shows.
40
- 8. `npx nera validate`, then `npx nera build --check`; try a query with
39
+ 7. `npx nera validate`, then `npx nera build --check`; try a query with
41
40
  `npm run dev`.
42
41
 
43
42
  ## Files touched
44
43
 
45
- `package.json`, `config/search.yaml` (optional), `pages/search.md`,
44
+ `package.json`, `config/search.yaml`, `pages/search.md`,
46
45
  `theme/views/pages/search.pug`, `theme/views/vendor/plugin-search/`,
47
46
  `theme/assets/js/search.js`, `.gitignore`.
48
47
 
package/src/server.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2
- import { createSite as neraCreateSite } from '@nera-static/nera'
2
+ import { addPlugin as neraAddPlugin, createSite as neraCreateSite } from '@nera-static/nera'
3
3
  import pkg from '../package.json' with { type: 'json' }
4
4
  import { registerCatalogTools } from './catalog.js'
5
5
  import { realRoot } from './paths.js'
@@ -19,8 +19,9 @@ import { registerSiteTools } from './tools/sites.js'
19
19
  *
20
20
  * @param {object} options
21
21
  * @param {string} options.root the folder the server may work in; every path a tool takes is checked against it
22
- * @param {ReturnType<typeof createRunner>} [options.runner] runs the `nera`, `npm` and `node` commands (injected so tests spawn nothing)
22
+ * @param {ReturnType<typeof createRunner>} [options.runner] runs the `nera` commands `build` starts (injected so tests spawn nothing)
23
23
  * @param {typeof neraCreateSite} [options.createSite] writes a new site's files for `create_site` (the CLI's `createSite`; injected so tests need no network for package and GitHub starters)
24
+ * @param {typeof neraAddPlugin} [options.addPlugin] installs a plugin for `add_plugin` (the CLI's `addPlugin`; injected so tests need no network)
24
25
  * @param {typeof fetch} [options.fetch] fetches the npm registry catalogs (injected so tests stay offline)
25
26
  * @param {string} [options.docsFile] the bundled `llms-full.txt` (default: the package's `docs/`; injected so tests can point at a missing one)
26
27
  * @param {ReturnType<typeof createProcesses>} [options.processes] tracks the children that outlive a call (`preview`, `publish`); all are stopped when the server closes
@@ -28,8 +29,8 @@ import { registerSiteTools } from './tools/sites.js'
28
29
  * @returns {Promise<McpServer>}
29
30
  * @throws {import('./paths.js').PathError} when `root` does not exist or is not a folder
30
31
  */
31
- export async function createServer({ root, runner = createRunner(), createSite = neraCreateSite, fetch = globalThis.fetch, docsFile, processes = createProcesses(), timing }) {
32
- const ctx = { root: await realRoot(root), runner, createSite, fetch, docsFile, processes, timing }
32
+ export async function createServer({ root, runner = createRunner(), createSite = neraCreateSite, addPlugin = neraAddPlugin, fetch = globalThis.fetch, docsFile, processes = createProcesses(), timing }) {
33
+ const ctx = { root: await realRoot(root), runner, createSite, addPlugin, fetch, docsFile, processes, timing }
33
34
  const server = new McpServer(
34
35
  { name: pkg.name, version: pkg.version },
35
36
  {
package/src/tools/cli.js CHANGED
@@ -2,7 +2,7 @@ import fs from 'node:fs/promises'
2
2
  import path from 'node:path'
3
3
  import { hasErrors, validate } from '@nera-static/nera'
4
4
  import { z } from 'zod'
5
- import { PathError, resolveInRoot } from '../paths.js'
5
+ import { resolveInRoot } from '../paths.js'
6
6
  import { ok, tool, ToolError } from '../results.js'
7
7
  import { childEnv } from '../runner.js'
8
8
  import { relativeTo, resolveSite, siteFolders, siteInput } from './sites.js'
@@ -58,67 +58,24 @@ async function starterArg(ctx, starter) {
58
58
  }
59
59
 
60
60
  /**
61
- * The npm package of an `add_plugin` spec: `@nera-static/plugin-<name>` or
62
- * just `<name>`; anything else (another scope, a version, a path, a URL) is
61
+ * The npm package of an `add_plugin` spec, in the same forms the CLI's
62
+ * addPlugin takes: `@nera-static/plugin-<name>`, `plugin-<name>` or just
63
+ * `<name>`; anything else (another scope, a version, a path, a URL) is
63
64
  * refused.
64
65
  */
65
66
  function pluginPackage(spec) {
66
- const name = spec.startsWith(`${PLUGIN_SCOPE}plugin-`) ? spec.slice(`${PLUGIN_SCOPE}plugin-`.length) : spec
67
+ const name = spec.replace(new RegExp(`^(${PLUGIN_SCOPE}plugin-|plugin-)`), '')
67
68
  if (!PLUGIN_NAME.test(name) || NOT_PLUGINS.has(name)) {
68
- throw new ToolError(`"${spec}" is not a Nera plugin. Pass an official plugin as \`@nera-static/plugin-<name>\` or just \`<name>\` (e.g. \`sitemap\`); call list_plugins for the catalog.`)
69
+ throw new ToolError(`"${spec}" is not a Nera plugin. Pass an official plugin as \`@nera-static/plugin-<name>\`, \`plugin-<name>\` or just \`<name>\` (e.g. \`sitemap\`); call list_plugins for the catalog.`)
69
70
  }
70
71
  return { name, pkg: `${PLUGIN_SCOPE}plugin-${name}` }
71
72
  }
72
73
 
73
- /**
74
- * Copies the plugin's default `config/<name>.yaml` into the site's config
75
- * folder when the site has none, so the model can read and edit it.
76
- *
77
- * @returns {Promise<{ file: string, status: 'copied'|'kept'|'none' }>}
78
- */
79
- async function copyDefaultConfig(dir, packageDir, configFolder, name) {
80
- const target = await resolveInRoot(dir, path.join(configFolder, `${name}.yaml`), { label: 'plugin config file' })
81
- const file = relativeTo(dir, target)
82
- let source
83
- try {
84
- source = await resolveInRoot(dir, path.join(packageDir, 'config', `${name}.yaml`), { label: 'plugin default config' })
85
- await fs.access(source)
86
- } catch (error) {
87
- if (error instanceof PathError || error.code === 'ENOENT') return { file, status: 'none' }
88
- throw error
89
- }
90
- await fs.mkdir(path.dirname(target), { recursive: true })
91
- try {
92
- await fs.copyFile(source, target, fs.constants.COPYFILE_EXCL)
93
- return { file, status: 'copied' }
94
- } catch (error) {
95
- if (error.code === 'EEXIST') return { file, status: 'kept' }
96
- throw error
97
- }
98
- }
99
-
100
- /**
101
- * The package's template-publishing script (the `bin` entry that points at
102
- * `publish-template.js`), checked to stay inside the site, or null.
103
- */
104
- async function publishTemplateScript(dir, packageDir) {
105
- let pkg
106
- try {
107
- pkg = JSON.parse(await fs.readFile(path.join(dir, packageDir, 'package.json'), 'utf8'))
108
- } catch {
109
- return null
110
- }
111
- const bins = typeof pkg.bin === 'string' ? [pkg.bin] : Object.values(pkg.bin ?? {})
112
- const script = bins.find((bin) => typeof bin === 'string' && path.basename(bin) === 'publish-template.js')
113
- if (!script) return null
114
- return resolveInRoot(dir, path.join(packageDir, script), { label: 'plugin template script' })
115
- }
116
-
117
74
  /**
118
75
  * Registers `create_site`, `build`, `validate` and `add_plugin`.
119
76
  *
120
77
  * @param {import('@modelcontextprotocol/sdk/server/mcp.js').McpServer} server
121
- * @param {{ root: string, runner: ReturnType<typeof import('../runner.js').createRunner>, createSite: typeof import('@nera-static/nera').createSite }} ctx `create_site` installs through `createSite`, the other tools through `runner`
78
+ * @param {{ root: string, runner: ReturnType<typeof import('../runner.js').createRunner>, createSite: typeof import('@nera-static/nera').createSite, addPlugin: typeof import('@nera-static/nera').addPlugin }} ctx `create_site` installs through `createSite`, `add_plugin` through `addPlugin`, `build` through `runner`
122
79
  */
123
80
  export function registerCliTools(server, ctx) {
124
81
  server.registerTool('create_site', {
@@ -225,38 +182,41 @@ export function registerCliTools(server, ctx) {
225
182
  description: 'Installs an official Nera plugin into a site (npm install), copies its default configuration to `config/<name>.yaml` when the site has none, and copies its Pug templates to `views/vendor/plugin-<name>/` when it ships any. Call list_plugins for the catalog. Afterwards read the plugin\'s config with read_file and include its templates in a layout with write_file, then validate.',
226
183
  inputSchema: {
227
184
  site: siteInput,
228
- plugin: z.string().describe('The plugin, as `@nera-static/plugin-<name>` or just `<name>` (e.g. `sitemap`, `tags`).'),
185
+ plugin: z.string().describe('The plugin, as `@nera-static/plugin-<name>`, `plugin-<name>` or just `<name>` (e.g. `sitemap`, `tags`).'),
229
186
  },
230
187
  }, tool(async ({ site, plugin }, { signal }) => {
231
188
  const { name, pkg } = pluginPackage(plugin)
232
189
  const resolved = await resolveSite(ctx, site)
233
- const install = await ctx.runner('npm', ['install', pkg], { cwd: resolved.dir, signal })
234
- if (install.code !== 0) {
235
- throw new ToolError(`Installing ${pkg} failed: ${failureText(install)}`)
236
- }
237
-
238
- const packageDir = path.join('node_modules', ...pkg.split('/'))
190
+ // addPlugin writes `<folders.config>/<name>.yaml` without checking
191
+ // where it leads, so a config folder or file that is a symbolic link
192
+ // out of the site is refused here, before npm runs.
239
193
  const { model } = await siteFolders(resolved.dir)
240
- const config = await copyDefaultConfig(resolved.dir, packageDir, model.folders.config, name)
194
+ await resolveInRoot(resolved.dir, path.join(model.folders.config, `${name}.yaml`), { label: 'plugin config file' })
241
195
 
242
- let templates = 'none'
243
- const script = await publishTemplateScript(resolved.dir, packageDir)
244
- if (script) {
245
- const publish = await ctx.runner('node', [script], { cwd: resolved.dir, signal })
246
- if (publish.code !== 0) {
247
- throw new ToolError(`${pkg} is installed, but copying its templates failed: ${failureText(publish)}`)
248
- }
249
- templates = 'published'
196
+ // As for create_site: every progress line is collected for the
197
+ // result, npm's and the template script's output goes to stderr
198
+ // (addPlugin's default), `env` is a child's and the call's signal
199
+ // stops the running child.
200
+ const lines = []
201
+ let added
202
+ try {
203
+ added = await ctx.addPlugin(pkg, { cwd: resolved.dir, signal, env: childEnv(), log: (line) => lines.push(line) })
204
+ } catch (error) {
205
+ // A command that ran and failed (npm install, the template
206
+ // script) carries its exit code; its own output is not captured.
207
+ const childFailed = !signal.aborted && typeof error.cause?.code === 'number'
208
+ throw new ToolError(childFailed ? `${error.message}\nThe command's own output is in the server's log. Fix what it reports (for npm often the network connection), then call add_plugin again.` : error.message)
250
209
  }
251
210
 
211
+ const { config, templates } = added
252
212
  const steps = [
253
213
  config.status === 'copied' ? `its configuration is in ${config.file}` : null,
254
214
  config.status === 'kept' ? `the site's own ${config.file} was kept` : null,
255
215
  templates === 'published' ? 'its templates are in the site\'s views/vendor folder' : null,
256
216
  ].filter(Boolean)
257
217
  return ok(
258
- { site: resolved.site, plugin: pkg, config, templates, log: tail(install.stdout) },
259
- `Installed ${pkg} in "${resolved.site}"${steps.length ? `; ${steps.join(', ')}` : ''}. Then call validate.`,
218
+ { site: resolved.site, plugin: added.plugin, config, templates, log: tail(lines.join('\n')) },
219
+ `Installed ${added.plugin} in "${resolved.site}"${steps.length ? `; ${steps.join(', ')}` : ''}. Then call validate.`,
260
220
  )
261
221
  }))
262
222
  }