@nera-static/mcp 1.1.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.
- package/.claude-plugin/plugin.json +2 -2
- package/CHANGELOG.md +26 -0
- package/README.md +6 -6
- package/package.json +2 -3
- package/skills/nera/SKILL.md +12 -5
- package/skills/nera/recipes/blog.md +17 -16
- package/skills/nera/recipes/business-site.md +8 -8
- package/skills/nera/recipes/contact-form.md +11 -10
- package/skills/nera/recipes/images.md +3 -3
- package/skills/nera/recipes/portfolio.md +7 -8
- package/skills/nera/recipes/search.md +14 -15
- package/src/catalog.js +20 -85
- package/src/resources.js +2 -2
- package/src/runner.js +23 -8
- package/src/runtime.js +9 -6
- package/src/server.js +6 -3
- package/src/tools/cli.js +63 -86
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nera",
|
|
3
|
-
"version": "1.1
|
|
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.1
|
|
32
|
+
"@nera-static/mcp@1.2.1",
|
|
33
33
|
"--root",
|
|
34
34
|
"${user_config.root}"
|
|
35
35
|
]
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,32 @@ 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
|
+
|
|
20
|
+
## [1.2.0] - 2026-11-18
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- `create_site` returns the starter's `## First steps` (from its README) as `firstSteps`, `null` without a starter, and its text points to them.
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- `create_site` creates and installs the site with `createSite()` from `@nera-static/nera` inside the server instead of spawning `nera new`. Cancelling the call stops the install and removes the new folder again; npm's output goes to the server's log (stderr). Its inputs, checks and result shape are unchanged.
|
|
29
|
+
- `list_starters`, `list_themes`, `list_plugins` and the `nera://catalog/*` resources come from `listCatalog()` of `@nera-static/nera` instead of the server's own registry search. Offline, the starters fall back to the official list the CLI bundles; themes and plugins still report the registry error.
|
|
30
|
+
- `validate` calls `validate()` from `@nera-static/nera`, so it runs the validator version the CLI pins; its records are unchanged. `@nera-static/validate` is no longer a direct dependency.
|
|
31
|
+
- With `NERA_MCP_RUNTIME=bundled` (the Desktop extension), `create_site` hands `createSite` the same environment as every other command, shim folder first on the PATH, so its starter download and `npm install` find the bundled `npm`.
|
|
32
|
+
- Requires `@nera-static/nera` ^1.25.0 (was ^1.23.0), the first release whose `createSite` installs without blocking and takes `signal` and `env`.
|
|
33
|
+
|
|
8
34
|
## [1.1.0] - 2026-11-18
|
|
9
35
|
|
|
10
36
|
### Added
|
package/README.md
CHANGED
|
@@ -100,19 +100,19 @@ A **site** is a folder under the root (or the root itself) whose `package.json`
|
|
|
100
100
|
|
|
101
101
|
| Tool | Does |
|
|
102
102
|
| --- | --- |
|
|
103
|
-
| `list_starters`, `list_themes`, `list_plugins` | The starter kits, themes and plugins on npm, official ones first |
|
|
104
|
-
| `create_site` | Creates a site
|
|
103
|
+
| `list_starters`, `list_themes`, `list_plugins` | The starter kits, themes and plugins on npm, official ones first; offline, `list_starters` falls back to the official starters |
|
|
104
|
+
| `create_site` | Creates a site as `nera new` does (`name`, optional `starter`, `theme`, `title`, `lang`) and installs its packages; returns the starter's first steps as `firstSteps` |
|
|
105
105
|
| `list_sites` | The Nera sites under the root |
|
|
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
|
|
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
|
-
|
|
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
|
|
|
@@ -136,12 +136,12 @@ The commands run through the site's own `@nera-static/nera` when it has one inst
|
|
|
136
136
|
- The server only touches files below `--root`. A path outside it is refused with an error, never quietly corrected.
|
|
137
137
|
- It never asks for input and never prompts in a terminal; long-running commands run in the background and are stopped when the server exits.
|
|
138
138
|
- `publish` signs in through GitHub's device flow: you enter the code in your browser. Tokens stay where `nera publish` keeps them (the system keychain, or a file only you can read) and are never returned to the assistant or written into a site.
|
|
139
|
-
- The catalogs are read from the public npm registry. Nothing else leaves your computer unless you publish.
|
|
139
|
+
- The catalogs are read from the public npm registry (the starters fall back to the official list when it cannot be reached). `create_site` and `add_plugin` install packages from npm. Nothing else leaves your computer unless you publish.
|
|
140
140
|
|
|
141
141
|
## Compatibility
|
|
142
142
|
|
|
143
143
|
- Node.js 22.12 or later
|
|
144
|
-
- Brings `@nera-static/nera` 1.
|
|
144
|
+
- Brings `@nera-static/nera` 1.25.0 for sites that have none installed. A site with its own CLI installed runs that one: `build` needs 1.9.0 or later (`--json`), `publish` 1.19.0 (1.20.0 for Netlify). `npm update` in the site brings it up to date.
|
|
145
145
|
|
|
146
146
|
## License
|
|
147
147
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nera-static/mcp",
|
|
3
|
-
"version": "1.1
|
|
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,8 +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.
|
|
51
|
-
"@nera-static/validate": "^1.7.0",
|
|
50
|
+
"@nera-static/nera": "^1.26.0",
|
|
52
51
|
"yaml": "^2.9.1",
|
|
53
52
|
"zod": "^4.6.7"
|
|
54
53
|
},
|
package/skills/nera/SKILL.md
CHANGED
|
@@ -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
|
-
|
|
41
|
-
|
|
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>`.
|
|
82
|
-
|
|
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
|
-
|
|
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: `
|
|
25
|
-
`
|
|
26
|
-
`
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
`
|
|
32
|
-
|
|
33
|
-
5. Previous/next: `
|
|
34
|
-
|
|
35
|
-
|
|
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: `
|
|
40
|
-
|
|
41
|
-
8. Menu:
|
|
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
|
|
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: `
|
|
28
|
-
`config/navigation.yaml` (`href` ending in
|
|
29
|
-
as `main:` and `footer:`; a footer menu
|
|
30
|
-
imprint and privacy links, so keep only one of
|
|
31
|
-
|
|
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:
|
|
35
|
-
`
|
|
36
|
-
|
|
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. `
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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.
|
|
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
|
-
|
|
49
|
+
4. `pages/contact.md` with `layout: pages/contact.pug`, a `title` and a
|
|
49
50
|
short text above the form.
|
|
50
|
-
|
|
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. `
|
|
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
|
(``), 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.
|
|
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
|
``.
|
|
27
|
-
4. Project list: `
|
|
28
|
-
|
|
29
|
-
`
|
|
30
|
-
|
|
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
|
|
36
|
-
|
|
37
|
-
|
|
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. `
|
|
9
|
-
`config/search.yaml`
|
|
10
|
-
`group_by_lang: true` for one index per language
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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` (
|
|
28
|
-
its own and `nera build --check` warns `a11y-h1`).
|
|
29
|
-
the menu.
|
|
30
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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/catalog.js
CHANGED
|
@@ -1,112 +1,47 @@
|
|
|
1
|
+
import { CatalogError, listCatalog } from '@nera-static/nera'
|
|
1
2
|
import { z } from 'zod'
|
|
2
3
|
import { ok, tool, ToolError } from './results.js'
|
|
3
4
|
|
|
4
|
-
export const REGISTRY_SEARCH = 'https://registry.npmjs.org/-/v1/search'
|
|
5
|
-
/** Every official package carries this keyword; not every one carries `nera-<kind>`. */
|
|
6
|
-
const OFFICIAL_KEYWORD = 'nera'
|
|
7
|
-
const OFFICIAL_SCOPE = '@nera-static/'
|
|
8
|
-
/** The most results one registry search returns. */
|
|
9
|
-
const SEARCH_SIZE = 250
|
|
10
|
-
const TIMEOUT_MS = 10000
|
|
11
|
-
|
|
12
5
|
/**
|
|
13
|
-
* The three catalogs
|
|
14
|
-
*
|
|
15
|
-
* consuming tool reads back as the same package (a bare unscoped name would be
|
|
16
|
-
* read as `@nera-static/<kind>-<name>`).
|
|
6
|
+
* The three catalogs, as the tools and resources present them. The registry
|
|
7
|
+
* search itself is the CLI's `listCatalog` (ROADMAP principle 4).
|
|
17
8
|
*/
|
|
18
9
|
export const KINDS = {
|
|
19
10
|
starters: {
|
|
20
11
|
title: 'starter kits',
|
|
21
|
-
prefix: `${OFFICIAL_SCOPE}starter-`,
|
|
22
|
-
keyword: 'nera-starter',
|
|
23
|
-
exclude: new Set(),
|
|
24
|
-
usable: (name) => name.startsWith('@') || /^nera-starter-[a-z0-9][a-z0-9._-]*$/.test(name),
|
|
25
12
|
next: 'Pass `name` as `starter` to create_site.',
|
|
26
13
|
},
|
|
27
14
|
themes: {
|
|
28
15
|
title: 'themes',
|
|
29
|
-
prefix: `${OFFICIAL_SCOPE}theme-`,
|
|
30
|
-
keyword: 'nera-theme',
|
|
31
|
-
exclude: new Set(),
|
|
32
|
-
usable: (name) => name.startsWith('@'),
|
|
33
16
|
next: 'Pass `name` as `theme` to create_site.',
|
|
34
17
|
},
|
|
35
18
|
plugins: {
|
|
36
19
|
title: 'plugins',
|
|
37
|
-
prefix: `${OFFICIAL_SCOPE}plugin-`,
|
|
38
|
-
keyword: 'nera-plugin',
|
|
39
|
-
exclude: new Set([`${OFFICIAL_SCOPE}plugin-utils`]),
|
|
40
|
-
usable: () => true,
|
|
41
20
|
next: 'Pass `name` of an official plugin to add_plugin.',
|
|
42
21
|
},
|
|
43
22
|
}
|
|
44
23
|
|
|
45
24
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
|
|
49
|
-
export class CatalogError extends ToolError {
|
|
50
|
-
constructor(message) {
|
|
51
|
-
super(message)
|
|
52
|
-
this.name = 'CatalogError'
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async function search(fetch, text) {
|
|
57
|
-
const url = `${REGISTRY_SEARCH}?text=${encodeURIComponent(text)}&size=${SEARCH_SIZE}`
|
|
58
|
-
let body
|
|
59
|
-
try {
|
|
60
|
-
const response = await fetch(url, { signal: AbortSignal.timeout(TIMEOUT_MS) })
|
|
61
|
-
if (!response.ok) throw new Error(`HTTP ${response.status}`)
|
|
62
|
-
body = await response.json()
|
|
63
|
-
} catch (error) {
|
|
64
|
-
throw new CatalogError(`The npm registry could not be reached (${error.message}), so the catalog is not available. Check the network connection and try again, or use a name you already know (official ones are listed on https://nera.js.org).`)
|
|
65
|
-
}
|
|
66
|
-
if (!Array.isArray(body?.objects)) {
|
|
67
|
-
throw new CatalogError('The npm registry answered with an unexpected search result, so the catalog is not available. Try again later.')
|
|
68
|
-
}
|
|
69
|
-
return body.objects.map((object) => object?.package).filter((pkg) => typeof pkg?.name === 'string')
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function entry(kind, pkg, official) {
|
|
73
|
-
return {
|
|
74
|
-
name: official ? pkg.name.slice(kind.prefix.length) : pkg.name,
|
|
75
|
-
package: pkg.name,
|
|
76
|
-
version: typeof pkg.version === 'string' ? pkg.version : null,
|
|
77
|
-
description: typeof pkg.description === 'string' ? pkg.description : '',
|
|
78
|
-
official,
|
|
79
|
-
npm: pkg.links?.npm ?? `https://www.npmjs.com/package/${pkg.name}`,
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* One catalog from the npm registry: the official `@nera-static/<kind>-*`
|
|
85
|
-
* packages (keyword `nera`, which every official package carries, while only
|
|
86
|
-
* some carry `nera-<kind>`), then third-party ones (keyword `nera-<kind>`),
|
|
87
|
-
* each group sorted by package name and listed once.
|
|
25
|
+
* One catalog, from the CLI's `listCatalog`: official packages first, then
|
|
26
|
+
* third-party ones. Starters fall back to the official starters bundled with
|
|
27
|
+
* the CLI when the registry cannot be reached.
|
|
88
28
|
*
|
|
89
|
-
*
|
|
29
|
+
* The CLI's `CatalogError` extends `Error`, not our `ToolError`, so it is
|
|
30
|
+
* rethrown as a `ToolError`: the tools turn that into an `isError` result, the
|
|
31
|
+
* resources into an `InvalidParams` error, both with the CLI's message.
|
|
32
|
+
*
|
|
33
|
+
* @param {{ fetch: typeof fetch }} ctx
|
|
90
34
|
* @param {keyof typeof KINDS} kindName
|
|
91
35
|
* @returns {Promise<Array<{ name: string, package: string, version: string|null, description: string, official: boolean, npm: string }>>}
|
|
92
|
-
* @throws {
|
|
36
|
+
* @throws {ToolError} when the registry cannot be reached or answers oddly (themes, plugins)
|
|
93
37
|
*/
|
|
94
|
-
export async function
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const official = [...officialHits, ...keywordHits].filter((pkg) => pkg.name.startsWith(kind.prefix) && !kind.exclude.has(pkg.name))
|
|
101
|
-
const thirdParty = keywordHits.filter((pkg) => !pkg.name.startsWith(OFFICIAL_SCOPE) && kind.usable(pkg.name))
|
|
102
|
-
const byName = new Map()
|
|
103
|
-
for (const [group, isOfficial] of [[official, true], [thirdParty, false]]) {
|
|
104
|
-
const sorted = [...group].sort((a, b) => a.name.localeCompare(b.name))
|
|
105
|
-
for (const pkg of sorted) {
|
|
106
|
-
if (!byName.has(pkg.name)) byName.set(pkg.name, entry(kind, pkg, isOfficial))
|
|
107
|
-
}
|
|
38
|
+
export async function readCatalog(ctx, kindName) {
|
|
39
|
+
try {
|
|
40
|
+
return await listCatalog(kindName, { fetch: ctx.fetch })
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (error instanceof CatalogError) throw new ToolError(error.message)
|
|
43
|
+
throw error
|
|
108
44
|
}
|
|
109
|
-
return [...byName.values()]
|
|
110
45
|
}
|
|
111
46
|
|
|
112
47
|
/**
|
|
@@ -117,7 +52,7 @@ export async function loadCatalog(fetch, kindName) {
|
|
|
117
52
|
*/
|
|
118
53
|
export function registerCatalogTools(server, ctx) {
|
|
119
54
|
const descriptions = {
|
|
120
|
-
starters: 'Lists the Nera starter kits on npm: ready-to-edit sites with sample pages, a theme and plugins (e.g. `blog`, `business`, `portfolio`, `blank`). Call it before create_site when the user wants a site of a certain kind, and pass the chosen entry\'s `name` as `starter`.',
|
|
55
|
+
starters: 'Lists the Nera starter kits on npm: ready-to-edit sites with sample pages, a theme and plugins (e.g. `blog`, `business`, `portfolio`, `blank`). Call it before create_site when the user wants a site of a certain kind, and pass the chosen entry\'s `name` as `starter`. Without a network connection it lists the official starters only.',
|
|
121
56
|
themes: 'Lists the Nera themes on npm: the layouts and styles of a site, installable as a package. A starter already brings its theme; use this only for create_site without a starter, and pass the chosen entry\'s `name` as `theme`.',
|
|
122
57
|
plugins: 'Lists the Nera plugins on npm: features such as navigation, tags, a sitemap, a feed, image resizing, code highlighting or a contact form. Call it when the user wants a feature the site lacks; official plugins (`official: true`) are installed with add_plugin by their `name`.',
|
|
123
58
|
}
|
|
@@ -131,7 +66,7 @@ export function registerCatalogTools(server, ctx) {
|
|
|
131
66
|
},
|
|
132
67
|
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
133
68
|
}, tool(async ({ query }) => {
|
|
134
|
-
const all = await
|
|
69
|
+
const all = await readCatalog(ctx, kindName)
|
|
135
70
|
const needle = query?.toLowerCase()
|
|
136
71
|
const items = needle
|
|
137
72
|
? all.filter((item) => `${item.package} ${item.description}`.toLowerCase().includes(needle))
|
package/src/resources.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'node:fs/promises'
|
|
|
2
2
|
import { fileURLToPath } from 'node:url'
|
|
3
3
|
import { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
4
4
|
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js'
|
|
5
|
-
import { KINDS,
|
|
5
|
+
import { KINDS, readCatalog } from './catalog.js'
|
|
6
6
|
import { PathError, resolveInRoot } from './paths.js'
|
|
7
7
|
import { ToolError } from './results.js'
|
|
8
8
|
import { findSites, resolveSite } from './tools/sites.js'
|
|
@@ -80,7 +80,7 @@ export function registerResources(server, ctx) {
|
|
|
80
80
|
description: `The Nera ${KINDS[kindName].title} on npm as JSON, official ones first (the same list as the list_${kindName} tool).`,
|
|
81
81
|
mimeType: 'application/json',
|
|
82
82
|
}, resource(async (uri) => {
|
|
83
|
-
const items = await
|
|
83
|
+
const items = await readCatalog(ctx, kindName)
|
|
84
84
|
return text(uri, 'application/json', JSON.stringify({ [kindName]: items }, null, 2))
|
|
85
85
|
}))
|
|
86
86
|
}
|
package/src/runner.js
CHANGED
|
@@ -74,15 +74,31 @@ export function capped(text) {
|
|
|
74
74
|
return text.length > MAX_CAPTURE ? text.slice(-MAX_CAPTURE) : text
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* The environment every child gets: this process's, without colour codes and
|
|
79
|
+
* with `env` added. Under the bundled runtime the shim folder
|
|
80
|
+
* (`src/runtime.js`) comes first on the PATH, so the child and everything it
|
|
81
|
+
* starts find `node`, `npm` and `npx`. Also what `create_site` hands
|
|
82
|
+
* `createSite`, whose children (`npm pack`, `tar`, `npm install`) the runner
|
|
83
|
+
* does not start.
|
|
84
|
+
*
|
|
85
|
+
* @param {Record<string, string>} [env] added to this process's environment
|
|
86
|
+
* @param {NodeJS.Platform} [platform] injected in tests
|
|
87
|
+
* @param {string|null} [shim] the shim folder; the active one by default
|
|
88
|
+
* @returns {Record<string, string|undefined>}
|
|
89
|
+
*/
|
|
90
|
+
export function childEnv(env = {}, platform = process.platform, shim = activeShim()) {
|
|
91
|
+
const merged = { ...process.env, NO_COLOR: '1', FORCE_COLOR: '0', ...env }
|
|
92
|
+
return shim ? withPathPrefix(merged, shim, platform) : merged
|
|
93
|
+
}
|
|
94
|
+
|
|
77
95
|
/**
|
|
78
96
|
* The options every child is spawned with: no shell (arguments are never
|
|
79
97
|
* interpreted), no stdin (nothing can wait for an answer), both output streams
|
|
80
|
-
* piped (none of it reaches this process's stdout),
|
|
81
|
-
* POSIX — its own process group, so `stopChild` reaches the
|
|
82
|
-
* starts in turn (npm's scripts, Vite's workers). Windows has no
|
|
83
|
-
* groups to signal; `stopChild` ends the tree with `taskkill /T` there.
|
|
84
|
-
* Under the bundled runtime the shim folder (`src/runtime.js`) comes first on
|
|
85
|
-
* the PATH, so the child and everything it starts find `node`, `npm` and `npx`.
|
|
98
|
+
* piped (none of it reaches this process's stdout), the env of `childEnv`,
|
|
99
|
+
* and — on POSIX — its own process group, so `stopChild` reaches the
|
|
100
|
+
* processes it starts in turn (npm's scripts, Vite's workers). Windows has no
|
|
101
|
+
* process groups to signal; `stopChild` ends the tree with `taskkill /T` there.
|
|
86
102
|
*
|
|
87
103
|
* @param {string} cwd
|
|
88
104
|
* @param {Record<string, string>} [env] added to this process's environment
|
|
@@ -91,13 +107,12 @@ export function capped(text) {
|
|
|
91
107
|
* @returns {import('node:child_process').SpawnOptions}
|
|
92
108
|
*/
|
|
93
109
|
export function spawnOptions(cwd, env = {}, platform = process.platform, shim = activeShim()) {
|
|
94
|
-
const merged = { ...process.env, NO_COLOR: '1', FORCE_COLOR: '0', ...env }
|
|
95
110
|
return {
|
|
96
111
|
cwd,
|
|
97
112
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
98
113
|
shell: false,
|
|
99
114
|
detached: platform !== 'win32',
|
|
100
|
-
env:
|
|
115
|
+
env: childEnv(env, platform, shim),
|
|
101
116
|
}
|
|
102
117
|
}
|
|
103
118
|
|
package/src/runtime.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// The bundled runtime of the Claude Desktop extension: Claude Desktop runs the
|
|
2
2
|
// server on the Node it ships, which comes without npm and puts nothing on the
|
|
3
|
-
// PATH. Every child (`
|
|
4
|
-
// `#!/usr/bin/env node` scripts, npm's lifecycle scripts) looks
|
|
5
|
-
// and `npx` up on the PATH, so under `NERA_MCP_RUNTIME=bundled`
|
|
6
|
-
// a shim folder for the three and every child gets it first on
|
|
3
|
+
// PATH. Every child (`createSite`'s `npm pack` and `npm install`, `nera dev`
|
|
4
|
+
// → Vite's `#!/usr/bin/env node` scripts, npm's lifecycle scripts) looks
|
|
5
|
+
// `node`, `npm` and `npx` up on the PATH, so under `NERA_MCP_RUNTIME=bundled`
|
|
6
|
+
// the bin writes a shim folder for the three and every child gets it first on
|
|
7
|
+
// its PATH (`childEnv` in `src/runner.js`).
|
|
7
8
|
import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
8
9
|
import { createRequire } from 'node:module'
|
|
9
10
|
import os from 'node:os'
|
|
@@ -195,10 +196,12 @@ export function activeShim() {
|
|
|
195
196
|
|
|
196
197
|
/**
|
|
197
198
|
* What the bin calls at start: under `NERA_MCP_RUNTIME=bundled` it writes the
|
|
198
|
-
* shim folder and activates it; otherwise it does nothing.
|
|
199
|
+
* shim folder and activates it; otherwise it does nothing. The env it reads is
|
|
200
|
+
* never changed: the shim reaches every child through `childEnv`, also the
|
|
201
|
+
* ones `createSite` starts in-process (it takes that env).
|
|
199
202
|
*
|
|
200
203
|
* @param {object} [options]
|
|
201
|
-
* @param {Record<string, string|undefined>} [options.env]
|
|
204
|
+
* @param {Record<string, string|undefined>} [options.env] read for the switch only
|
|
202
205
|
* @param {Parameters<typeof writeShim>[0]} [options.shim] passed to `writeShim` (tests)
|
|
203
206
|
* @returns {ReturnType<typeof writeShim>|null} the shim, whose `remove` the bin calls on exit
|
|
204
207
|
*/
|
package/src/server.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
2
|
+
import { addPlugin as neraAddPlugin, createSite as neraCreateSite } from '@nera-static/nera'
|
|
2
3
|
import pkg from '../package.json' with { type: 'json' }
|
|
3
4
|
import { registerCatalogTools } from './catalog.js'
|
|
4
5
|
import { realRoot } from './paths.js'
|
|
@@ -18,7 +19,9 @@ import { registerSiteTools } from './tools/sites.js'
|
|
|
18
19
|
*
|
|
19
20
|
* @param {object} options
|
|
20
21
|
* @param {string} options.root the folder the server may work in; every path a tool takes is checked against it
|
|
21
|
-
* @param {ReturnType<typeof createRunner>} [options.runner] runs the `nera
|
|
22
|
+
* @param {ReturnType<typeof createRunner>} [options.runner] runs the `nera` commands `build` starts (injected so tests spawn nothing)
|
|
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)
|
|
22
25
|
* @param {typeof fetch} [options.fetch] fetches the npm registry catalogs (injected so tests stay offline)
|
|
23
26
|
* @param {string} [options.docsFile] the bundled `llms-full.txt` (default: the package's `docs/`; injected so tests can point at a missing one)
|
|
24
27
|
* @param {ReturnType<typeof createProcesses>} [options.processes] tracks the children that outlive a call (`preview`, `publish`); all are stopped when the server closes
|
|
@@ -26,8 +29,8 @@ import { registerSiteTools } from './tools/sites.js'
|
|
|
26
29
|
* @returns {Promise<McpServer>}
|
|
27
30
|
* @throws {import('./paths.js').PathError} when `root` does not exist or is not a folder
|
|
28
31
|
*/
|
|
29
|
-
export async function createServer({ root, runner = createRunner(), fetch = globalThis.fetch, docsFile, processes = createProcesses(), timing }) {
|
|
30
|
-
const ctx = { root: await realRoot(root), runner, 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 }
|
|
31
34
|
const server = new McpServer(
|
|
32
35
|
{ name: pkg.name, version: pkg.version },
|
|
33
36
|
{
|
package/src/tools/cli.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import fs from 'node:fs/promises'
|
|
2
2
|
import path from 'node:path'
|
|
3
|
-
import { hasErrors,
|
|
3
|
+
import { hasErrors, validate } from '@nera-static/nera'
|
|
4
4
|
import { z } from 'zod'
|
|
5
|
-
import {
|
|
5
|
+
import { resolveInRoot } from '../paths.js'
|
|
6
6
|
import { ok, tool, ToolError } from '../results.js'
|
|
7
|
+
import { childEnv } from '../runner.js'
|
|
7
8
|
import { relativeTo, resolveSite, siteFolders, siteInput } from './sites.js'
|
|
8
9
|
|
|
9
10
|
const PLUGIN_SCOPE = '@nera-static/'
|
|
@@ -41,9 +42,9 @@ function countBySeverity(results) {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
/**
|
|
44
|
-
* The
|
|
45
|
-
*
|
|
46
|
-
*
|
|
45
|
+
* The `starter` for `createSite`: a package name as given, or a local starter
|
|
46
|
+
* folder checked against the root and passed relative to it (`createSite`
|
|
47
|
+
* runs with the root as its `cwd`).
|
|
47
48
|
*/
|
|
48
49
|
async function starterArg(ctx, starter) {
|
|
49
50
|
if (PACKAGE_SPEC.test(starter) || GITHUB_STARTER.test(starter)) {
|
|
@@ -57,72 +58,29 @@ async function starterArg(ctx, starter) {
|
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
/**
|
|
60
|
-
* The npm package of an `add_plugin` spec
|
|
61
|
-
*
|
|
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
|
|
62
64
|
* refused.
|
|
63
65
|
*/
|
|
64
66
|
function pluginPackage(spec) {
|
|
65
|
-
const name = spec.
|
|
67
|
+
const name = spec.replace(new RegExp(`^(${PLUGIN_SCOPE}plugin-|plugin-)`), '')
|
|
66
68
|
if (!PLUGIN_NAME.test(name) || NOT_PLUGINS.has(name)) {
|
|
67
|
-
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.`)
|
|
68
70
|
}
|
|
69
71
|
return { name, pkg: `${PLUGIN_SCOPE}plugin-${name}` }
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
/**
|
|
73
|
-
* Copies the plugin's default `config/<name>.yaml` into the site's config
|
|
74
|
-
* folder when the site has none, so the model can read and edit it.
|
|
75
|
-
*
|
|
76
|
-
* @returns {Promise<{ file: string, status: 'copied'|'kept'|'none' }>}
|
|
77
|
-
*/
|
|
78
|
-
async function copyDefaultConfig(dir, packageDir, configFolder, name) {
|
|
79
|
-
const target = await resolveInRoot(dir, path.join(configFolder, `${name}.yaml`), { label: 'plugin config file' })
|
|
80
|
-
const file = relativeTo(dir, target)
|
|
81
|
-
let source
|
|
82
|
-
try {
|
|
83
|
-
source = await resolveInRoot(dir, path.join(packageDir, 'config', `${name}.yaml`), { label: 'plugin default config' })
|
|
84
|
-
await fs.access(source)
|
|
85
|
-
} catch (error) {
|
|
86
|
-
if (error instanceof PathError || error.code === 'ENOENT') return { file, status: 'none' }
|
|
87
|
-
throw error
|
|
88
|
-
}
|
|
89
|
-
await fs.mkdir(path.dirname(target), { recursive: true })
|
|
90
|
-
try {
|
|
91
|
-
await fs.copyFile(source, target, fs.constants.COPYFILE_EXCL)
|
|
92
|
-
return { file, status: 'copied' }
|
|
93
|
-
} catch (error) {
|
|
94
|
-
if (error.code === 'EEXIST') return { file, status: 'kept' }
|
|
95
|
-
throw error
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* The package's template-publishing script (the `bin` entry that points at
|
|
101
|
-
* `publish-template.js`), checked to stay inside the site, or null.
|
|
102
|
-
*/
|
|
103
|
-
async function publishTemplateScript(dir, packageDir) {
|
|
104
|
-
let pkg
|
|
105
|
-
try {
|
|
106
|
-
pkg = JSON.parse(await fs.readFile(path.join(dir, packageDir, 'package.json'), 'utf8'))
|
|
107
|
-
} catch {
|
|
108
|
-
return null
|
|
109
|
-
}
|
|
110
|
-
const bins = typeof pkg.bin === 'string' ? [pkg.bin] : Object.values(pkg.bin ?? {})
|
|
111
|
-
const script = bins.find((bin) => typeof bin === 'string' && path.basename(bin) === 'publish-template.js')
|
|
112
|
-
if (!script) return null
|
|
113
|
-
return resolveInRoot(dir, path.join(packageDir, script), { label: 'plugin template script' })
|
|
114
|
-
}
|
|
115
|
-
|
|
116
74
|
/**
|
|
117
75
|
* Registers `create_site`, `build`, `validate` and `add_plugin`.
|
|
118
76
|
*
|
|
119
77
|
* @param {import('@modelcontextprotocol/sdk/server/mcp.js').McpServer} server
|
|
120
|
-
* @param {{ root: string, runner: ReturnType<typeof import('../runner.js').createRunner
|
|
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`
|
|
121
79
|
*/
|
|
122
80
|
export function registerCliTools(server, ctx) {
|
|
123
81
|
server.registerTool('create_site', {
|
|
124
82
|
title: 'Create a Nera site',
|
|
125
|
-
description: 'Creates a new Nera static site in a new folder of the root folder (`nera new`), installs its packages and returns the folder to pass as `site` to every other tool. Pick a starter from list_starters (`blank`, `blog`, `business`, `portfolio`) to begin with sample pages and a theme, or a theme from list_themes; with neither you get a minimal site. This can take a minute (npm install). Afterwards call get_site, then edit pages with write_page.',
|
|
83
|
+
description: 'Creates a new Nera static site in a new folder of the root folder (like `nera new`), installs its packages and returns the folder to pass as `site` to every other tool. Pick a starter from list_starters (`blank`, `blog`, `business`, `portfolio`) to begin with sample pages and a theme, or a theme from list_themes; with neither you get a minimal site. This can take a minute (npm install). A starter\'s suggested first steps come back as `firstSteps`. Afterwards call get_site, then edit pages with write_page.',
|
|
126
84
|
inputSchema: {
|
|
127
85
|
name: z.string().describe('The new folder, created directly in the root: letters, digits, `.`, `-`, `_` (e.g. `my-bakery`). `.` creates the site in the root itself, which must then be empty.'),
|
|
128
86
|
starter: z.string().optional().describe('A starter kit from list_starters, e.g. `blog` or `@nera-static/starter-business`. Leave out for a minimal site.'),
|
|
@@ -143,20 +101,36 @@ export function registerCliTools(server, ctx) {
|
|
|
143
101
|
throw new ToolError(`Invalid theme "${theme}". Use a theme name from list_themes (e.g. \`blog\`) or a package name (\`@nera-static/theme-blog\`).`)
|
|
144
102
|
}
|
|
145
103
|
|
|
146
|
-
const
|
|
147
|
-
if (starter !== undefined) args.push(`--starter=${await starterArg(ctx, starter)}`)
|
|
148
|
-
if (theme !== undefined) args.push(`--theme=${theme}`)
|
|
149
|
-
if (title !== undefined) args.push(`--name=${title}`)
|
|
150
|
-
if (lang !== undefined) args.push(`--lang=${lang}`)
|
|
104
|
+
const spec = starter === undefined ? undefined : await starterArg(ctx, starter)
|
|
151
105
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
106
|
+
// Every progress line is collected for the result and npm install's
|
|
107
|
+
// output goes to stderr (createSite's default): stdout belongs to the
|
|
108
|
+
// protocol. `env` is a child's (the shim first under the bundled
|
|
109
|
+
// runtime) and reaches createSite's own children; the call's signal
|
|
110
|
+
// stops them.
|
|
156
111
|
const site = relativeTo(ctx.root, target)
|
|
112
|
+
const lines = []
|
|
113
|
+
let created
|
|
114
|
+
try {
|
|
115
|
+
created = await ctx.createSite(inRoot ? '.' : name, {
|
|
116
|
+
cwd: ctx.root, starter: spec, theme, name: title, lang,
|
|
117
|
+
install: true, signal, env: childEnv(), log: (line) => lines.push(line),
|
|
118
|
+
})
|
|
119
|
+
} catch (error) {
|
|
120
|
+
// A failed install keeps the written site (npm install can be
|
|
121
|
+
// rerun there); after anything else, an abort included,
|
|
122
|
+
// createSite has removed a new folder again.
|
|
123
|
+
if (!signal.aborted && typeof error.code === 'number' && await exists(path.join(target, 'package.json'))) {
|
|
124
|
+
throw new ToolError(`The files of the site "${site}" are written, but installing its packages failed: ${error.message}\nnpm's own output is in the server's log. Fix what npm reports (often the network connection), then run \`npm install\` in that folder, or call create_site again with another name.`)
|
|
125
|
+
}
|
|
126
|
+
throw new ToolError(`Creating the site failed: ${error.message}`)
|
|
127
|
+
}
|
|
128
|
+
const firstSteps = created.firstSteps ?? null
|
|
157
129
|
return ok(
|
|
158
|
-
{ site, log: tail(
|
|
159
|
-
|
|
130
|
+
{ site, log: tail(lines.join('\n')), firstSteps },
|
|
131
|
+
firstSteps
|
|
132
|
+
? `Created the Nera site "${site}". Its starter suggests first steps (in firstSteps); follow them, starting with get_site with site "${site}".`
|
|
133
|
+
: `Created the Nera site "${site}". Call get_site with site "${site}" to see its pages, then edit them with write_page.`,
|
|
160
134
|
)
|
|
161
135
|
}))
|
|
162
136
|
|
|
@@ -195,7 +169,7 @@ export function registerCliTools(server, ctx) {
|
|
|
195
169
|
annotations: { readOnlyHint: true },
|
|
196
170
|
}, tool(async ({ site }) => {
|
|
197
171
|
const resolved = await resolveSite(ctx, site)
|
|
198
|
-
const results =
|
|
172
|
+
const results = validate({ cwd: resolved.dir })
|
|
199
173
|
const { errors, warnings } = countBySeverity(results)
|
|
200
174
|
const text = results.length
|
|
201
175
|
? `"${resolved.site}" has ${errors} error(s) and ${warnings} warning(s); each message says how to fix it.`
|
|
@@ -208,38 +182,41 @@ export function registerCliTools(server, ctx) {
|
|
|
208
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.',
|
|
209
183
|
inputSchema: {
|
|
210
184
|
site: siteInput,
|
|
211
|
-
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`).'),
|
|
212
186
|
},
|
|
213
187
|
}, tool(async ({ site, plugin }, { signal }) => {
|
|
214
188
|
const { name, pkg } = pluginPackage(plugin)
|
|
215
189
|
const resolved = await resolveSite(ctx, site)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
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.
|
|
222
193
|
const { model } = await siteFolders(resolved.dir)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
194
|
+
await resolveInRoot(resolved.dir, path.join(model.folders.config, `${name}.yaml`), { label: 'plugin config file' })
|
|
195
|
+
|
|
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)
|
|
233
209
|
}
|
|
234
210
|
|
|
211
|
+
const { config, templates } = added
|
|
235
212
|
const steps = [
|
|
236
213
|
config.status === 'copied' ? `its configuration is in ${config.file}` : null,
|
|
237
214
|
config.status === 'kept' ? `the site's own ${config.file} was kept` : null,
|
|
238
215
|
templates === 'published' ? 'its templates are in the site\'s views/vendor folder' : null,
|
|
239
216
|
].filter(Boolean)
|
|
240
217
|
return ok(
|
|
241
|
-
{ site: resolved.site, plugin:
|
|
242
|
-
`Installed ${
|
|
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.`,
|
|
243
220
|
)
|
|
244
221
|
}))
|
|
245
222
|
}
|