@nera-static/mcp 1.1.0 → 1.2.0
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 +14 -0
- package/README.md +5 -5
- package/package.json +2 -3
- 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 +4 -2
- package/src/tools/cli.js +35 -18
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nera",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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.
|
|
32
|
+
"@nera-static/mcp@1.2.0",
|
|
33
33
|
"--root",
|
|
34
34
|
"${user_config.root}"
|
|
35
35
|
]
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,20 @@ 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.0] - 2026-11-18
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `create_site` returns the starter's `## First steps` (from its README) as `firstSteps`, `null` without a starter, and its text points to them.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- `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.
|
|
17
|
+
- `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.
|
|
18
|
+
- `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.
|
|
19
|
+
- 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`.
|
|
20
|
+
- Requires `@nera-static/nera` ^1.25.0 (was ^1.23.0), the first release whose `createSite` installs without blocking and takes `signal` and `env`.
|
|
21
|
+
|
|
8
22
|
## [1.1.0] - 2026-11-18
|
|
9
23
|
|
|
10
24
|
### Added
|
package/README.md
CHANGED
|
@@ -100,8 +100,8 @@ 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` |
|
|
@@ -112,7 +112,7 @@ A **site** is a folder under the root (or the root itself) whose `package.json`
|
|
|
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`, `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.
|
|
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.
|
|
3
|
+
"version": "1.2.0",
|
|
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.25.0",
|
|
52
51
|
"yaml": "^2.9.1",
|
|
53
52
|
"zod": "^4.6.7"
|
|
54
53
|
},
|
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 { 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'
|
|
@@ -19,6 +20,7 @@ import { registerSiteTools } from './tools/sites.js'
|
|
|
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
22
|
* @param {ReturnType<typeof createRunner>} [options.runner] runs the `nera`, `npm` and `node` commands (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)
|
|
22
24
|
* @param {typeof fetch} [options.fetch] fetches the npm registry catalogs (injected so tests stay offline)
|
|
23
25
|
* @param {string} [options.docsFile] the bundled `llms-full.txt` (default: the package's `docs/`; injected so tests can point at a missing one)
|
|
24
26
|
* @param {ReturnType<typeof createProcesses>} [options.processes] tracks the children that outlive a call (`preview`, `publish`); all are stopped when the server closes
|
|
@@ -26,8 +28,8 @@ import { registerSiteTools } from './tools/sites.js'
|
|
|
26
28
|
* @returns {Promise<McpServer>}
|
|
27
29
|
* @throws {import('./paths.js').PathError} when `root` does not exist or is not a folder
|
|
28
30
|
*/
|
|
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 }
|
|
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 }
|
|
31
33
|
const server = new McpServer(
|
|
32
34
|
{ name: pkg.name, version: pkg.version },
|
|
33
35
|
{
|
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
5
|
import { PathError, 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)) {
|
|
@@ -117,12 +118,12 @@ async function publishTemplateScript(dir, packageDir) {
|
|
|
117
118
|
* Registers `create_site`, `build`, `validate` and `add_plugin`.
|
|
118
119
|
*
|
|
119
120
|
* @param {import('@modelcontextprotocol/sdk/server/mcp.js').McpServer} server
|
|
120
|
-
* @param {{ root: string, runner: ReturnType<typeof import('../runner.js').createRunner
|
|
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`
|
|
121
122
|
*/
|
|
122
123
|
export function registerCliTools(server, ctx) {
|
|
123
124
|
server.registerTool('create_site', {
|
|
124
125
|
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.',
|
|
126
|
+
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
127
|
inputSchema: {
|
|
127
128
|
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
129
|
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 +144,36 @@ export function registerCliTools(server, ctx) {
|
|
|
143
144
|
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
145
|
}
|
|
145
146
|
|
|
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}`)
|
|
147
|
+
const spec = starter === undefined ? undefined : await starterArg(ctx, starter)
|
|
151
148
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
149
|
+
// Every progress line is collected for the result and npm install's
|
|
150
|
+
// output goes to stderr (createSite's default): stdout belongs to the
|
|
151
|
+
// protocol. `env` is a child's (the shim first under the bundled
|
|
152
|
+
// runtime) and reaches createSite's own children; the call's signal
|
|
153
|
+
// stops them.
|
|
156
154
|
const site = relativeTo(ctx.root, target)
|
|
155
|
+
const lines = []
|
|
156
|
+
let created
|
|
157
|
+
try {
|
|
158
|
+
created = await ctx.createSite(inRoot ? '.' : name, {
|
|
159
|
+
cwd: ctx.root, starter: spec, theme, name: title, lang,
|
|
160
|
+
install: true, signal, env: childEnv(), log: (line) => lines.push(line),
|
|
161
|
+
})
|
|
162
|
+
} catch (error) {
|
|
163
|
+
// A failed install keeps the written site (npm install can be
|
|
164
|
+
// rerun there); after anything else, an abort included,
|
|
165
|
+
// createSite has removed a new folder again.
|
|
166
|
+
if (!signal.aborted && typeof error.code === 'number' && await exists(path.join(target, 'package.json'))) {
|
|
167
|
+
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.`)
|
|
168
|
+
}
|
|
169
|
+
throw new ToolError(`Creating the site failed: ${error.message}`)
|
|
170
|
+
}
|
|
171
|
+
const firstSteps = created.firstSteps ?? null
|
|
157
172
|
return ok(
|
|
158
|
-
{ site, log: tail(
|
|
159
|
-
|
|
173
|
+
{ site, log: tail(lines.join('\n')), firstSteps },
|
|
174
|
+
firstSteps
|
|
175
|
+
? `Created the Nera site "${site}". Its starter suggests first steps (in firstSteps); follow them, starting with get_site with site "${site}".`
|
|
176
|
+
: `Created the Nera site "${site}". Call get_site with site "${site}" to see its pages, then edit them with write_page.`,
|
|
160
177
|
)
|
|
161
178
|
}))
|
|
162
179
|
|
|
@@ -195,7 +212,7 @@ export function registerCliTools(server, ctx) {
|
|
|
195
212
|
annotations: { readOnlyHint: true },
|
|
196
213
|
}, tool(async ({ site }) => {
|
|
197
214
|
const resolved = await resolveSite(ctx, site)
|
|
198
|
-
const results =
|
|
215
|
+
const results = validate({ cwd: resolved.dir })
|
|
199
216
|
const { errors, warnings } = countBySeverity(results)
|
|
200
217
|
const text = results.length
|
|
201
218
|
? `"${resolved.site}" has ${errors} error(s) and ${warnings} warning(s); each message says how to fix it.`
|