@nera-static/mcp 0.0.0-stage → 1.0.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/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
- "name": "@nera-static/mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@nera-static/mcp",
3
+ "version": "1.0.0",
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
+ "type": "module",
6
+ "files": [
7
+ "bin",
8
+ "docs",
9
+ "src",
10
+ "CHANGELOG.md"
11
+ ],
12
+ "scripts": {
13
+ "lint": "eslint .",
14
+ "test": "vitest",
15
+ "prepack": "node scripts/fetch-docs.js"
16
+ },
17
+ "keywords": [
18
+ "nera",
19
+ "mcp",
20
+ "model-context-protocol",
21
+ "static-site-generator",
22
+ "ai",
23
+ "claude"
24
+ ],
25
+ "author": "Michael Becker",
26
+ "license": "MIT",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/seebaermichi/nera-mcp.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/seebaermichi/nera-mcp/issues"
33
+ },
34
+ "homepage": "https://github.com/seebaermichi/nera-mcp#readme",
35
+ "engines": {
36
+ "node": ">=22.12.0"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "dependencies": {
42
+ "@modelcontextprotocol/sdk": "^1.32.2",
43
+ "@nera-static/core": "^4.18.3",
44
+ "@nera-static/nera": "^1.23.0",
45
+ "@nera-static/validate": "^1.7.0",
46
+ "yaml": "^2.9.1",
47
+ "zod": "^4.6.7"
48
+ },
49
+ "devDependencies": {
50
+ "eslint": "^10.15.0",
51
+ "vitest": "^5.1.1"
52
+ },
53
+ "bin": {
54
+ "nera-mcp": "bin/nera-mcp.js"
55
+ }
56
+ }
package/src/catalog.js ADDED
@@ -0,0 +1,145 @@
1
+ import { z } from 'zod'
2
+ import { ok, tool, ToolError } from './results.js'
3
+
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
+ /**
13
+ * The three catalogs. `prefix` names the official packages of the kind,
14
+ * `keyword` finds third-party ones, `usable` keeps only third-party names the
15
+ * consuming tool reads back as the same package (a bare unscoped name would be
16
+ * read as `@nera-static/<kind>-<name>`).
17
+ */
18
+ export const KINDS = {
19
+ starters: {
20
+ 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
+ next: 'Pass `name` as `starter` to create_site.',
26
+ },
27
+ themes: {
28
+ title: 'themes',
29
+ prefix: `${OFFICIAL_SCOPE}theme-`,
30
+ keyword: 'nera-theme',
31
+ exclude: new Set(),
32
+ usable: (name) => name.startsWith('@'),
33
+ next: 'Pass `name` as `theme` to create_site.',
34
+ },
35
+ plugins: {
36
+ title: 'plugins',
37
+ prefix: `${OFFICIAL_SCOPE}plugin-`,
38
+ keyword: 'nera-plugin',
39
+ exclude: new Set([`${OFFICIAL_SCOPE}plugin-utils`]),
40
+ usable: () => true,
41
+ next: 'Pass `name` of an official plugin to add_plugin.',
42
+ },
43
+ }
44
+
45
+ /**
46
+ * A failure to reach or read the npm registry. The tools turn it into an
47
+ * `isError` result, the resources into a resource error.
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.
88
+ *
89
+ * @param {typeof fetch} fetch
90
+ * @param {keyof typeof KINDS} kindName
91
+ * @returns {Promise<Array<{ name: string, package: string, version: string|null, description: string, official: boolean, npm: string }>>}
92
+ * @throws {CatalogError} when the registry cannot be reached or answers oddly
93
+ */
94
+ export async function loadCatalog(fetch, kindName) {
95
+ const kind = KINDS[kindName]
96
+ const [officialHits, keywordHits] = await Promise.all([
97
+ search(fetch, `keywords:${OFFICIAL_KEYWORD}`),
98
+ search(fetch, `keywords:${kind.keyword}`),
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
+ }
108
+ }
109
+ return [...byName.values()]
110
+ }
111
+
112
+ /**
113
+ * Registers `list_starters`, `list_themes` and `list_plugins`.
114
+ *
115
+ * @param {import('@modelcontextprotocol/sdk/server/mcp.js').McpServer} server
116
+ * @param {{ fetch: typeof fetch }} ctx
117
+ */
118
+ export function registerCatalogTools(server, ctx) {
119
+ 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`.',
121
+ 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
+ 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
+ }
124
+ for (const kindName of Object.keys(KINDS)) {
125
+ const kind = KINDS[kindName]
126
+ server.registerTool(`list_${kindName}`, {
127
+ title: `List Nera ${kind.title}`,
128
+ description: descriptions[kindName],
129
+ inputSchema: {
130
+ query: z.string().optional().describe('Only entries whose name or description contains this text (case-insensitive), e.g. `blog`.'),
131
+ },
132
+ annotations: { readOnlyHint: true, openWorldHint: true },
133
+ }, tool(async ({ query }) => {
134
+ const all = await loadCatalog(ctx.fetch, kindName)
135
+ const needle = query?.toLowerCase()
136
+ const items = needle
137
+ ? all.filter((item) => `${item.package} ${item.description}`.toLowerCase().includes(needle))
138
+ : all
139
+ const text = items.length
140
+ ? `Found ${items.length} ${kind.title}: ${items.map((item) => item.name).join(', ')}. ${kind.next}`
141
+ : `No ${kind.title} found${query ? ` for "${query}"` : ''}.`
142
+ return ok({ [kindName]: items }, text)
143
+ }))
144
+ }
145
+ }
package/src/paths.js ADDED
@@ -0,0 +1,115 @@
1
+ import fs from 'node:fs/promises'
2
+ import path from 'node:path'
3
+
4
+ /**
5
+ * A path a tool was given that points outside the folder it may touch, or that
6
+ * cannot be checked. Tool handlers turn it into an `isError` result; its message
7
+ * says what was wrong and what to pass instead.
8
+ */
9
+ export class PathError extends Error {
10
+ constructor(message) {
11
+ super(message)
12
+ this.name = 'PathError'
13
+ }
14
+ }
15
+
16
+ const MISSING = new Set(['ENOENT', 'ENOTDIR'])
17
+
18
+ /**
19
+ * Resolves the server's `--root` to its real, absolute path, so every later
20
+ * containment check compares real paths (on macOS `/tmp` is a symlink to
21
+ * `/private/tmp`).
22
+ *
23
+ * @param {string} root the folder given on the command line
24
+ * @returns {Promise<string>} the real path of that folder
25
+ * @throws {PathError} when it does not exist or is not a folder
26
+ */
27
+ export async function realRoot(root) {
28
+ let real
29
+ try {
30
+ real = await fs.realpath(path.resolve(root))
31
+ } catch {
32
+ throw new PathError(`Root folder "${root}" does not exist. Create it, or start the server with --root pointing at an existing folder.`)
33
+ }
34
+ const stat = await fs.stat(real)
35
+ if (!stat.isDirectory()) {
36
+ throw new PathError(`Root "${root}" is a file, not a folder. Start the server with --root pointing at a folder.`)
37
+ }
38
+ return real
39
+ }
40
+
41
+ /**
42
+ * Resolves `input` against `base` and guarantees the result stays inside
43
+ * `base`: no `..` segment, no absolute path elsewhere, no symlink leading out.
44
+ * The path need not exist yet; then the real path of its nearest existing
45
+ * ancestor decides, so a not-yet-written file below a symlinked folder is
46
+ * checked against where that folder really is.
47
+ *
48
+ * @param {string} base a real, absolute folder (from `realRoot` or an earlier call)
49
+ * @param {string} input a path relative to `base`, or absolute; `''` and `'.'` mean `base`
50
+ * @param {object} [options]
51
+ * @param {string} [options.label] what the path is, for the error message (e.g. `site`)
52
+ * @returns {Promise<string>} the real, absolute path inside `base`
53
+ * @throws {PathError} when the path is not a string, contains `..` or leads outside `base`
54
+ */
55
+ export async function resolveInRoot(base, input, { label = 'path' } = {}) {
56
+ if (typeof input !== 'string' || input.includes('\0')) {
57
+ throw new PathError(`The ${label} must be a plain text path.`)
58
+ }
59
+ if (input.split(/[\\/]/).includes('..')) {
60
+ throw new PathError(`The ${label} "${input}" contains "..". Give a path relative to ${base} without "..".`)
61
+ }
62
+
63
+ const real = await realpathOfNearest(path.resolve(base, input), input, label)
64
+ if (!isInside(base, real)) {
65
+ throw new PathError(`The ${label} "${input}" leads outside ${base}. Only files and folders inside it can be used.`)
66
+ }
67
+ return real
68
+ }
69
+
70
+ /**
71
+ * The real path of `target`, where missing trailing segments are appended to
72
+ * the real path of the nearest ancestor that exists.
73
+ */
74
+ async function realpathOfNearest(target, input, label) {
75
+ const rest = []
76
+ let current = target
77
+ for (;;) {
78
+ try {
79
+ return path.join(await fs.realpath(current), ...rest)
80
+ } catch (error) {
81
+ if (error.code === 'ELOOP') {
82
+ throw new PathError(`The ${label} "${input}" goes through a loop of symbolic links, so it cannot be checked. Remove the loop or use another path.`)
83
+ }
84
+ if (!MISSING.has(error.code)) throw error
85
+ }
86
+ if (await isDanglingLink(current)) {
87
+ throw new PathError(`The ${label} "${input}" goes through a broken symbolic link, so it cannot be checked. Remove the link or use another path.`)
88
+ }
89
+ const parent = path.dirname(current)
90
+ if (parent === current) return target
91
+ rest.unshift(path.basename(current))
92
+ current = parent
93
+ }
94
+ }
95
+
96
+ async function isDanglingLink(candidate) {
97
+ try {
98
+ return (await fs.lstat(candidate)).isSymbolicLink()
99
+ } catch {
100
+ return false
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Whether `target` is `base` itself or lies below it. Both must be real,
106
+ * absolute paths (from `realRoot` / `resolveInRoot`).
107
+ *
108
+ * @param {string} base
109
+ * @param {string} target
110
+ * @returns {boolean}
111
+ */
112
+ export function isInside(base, target) {
113
+ const relative = path.relative(base, target)
114
+ return relative === '' || (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative))
115
+ }
@@ -0,0 +1,152 @@
1
+ import { spawn as nodeSpawn } from 'node:child_process'
2
+ import { EventEmitter } from 'node:events'
3
+ import net from 'node:net'
4
+ import { capped, commandFor, KILL_GRACE_MS, spawnOptions, stopChild } from './runner.js'
5
+
6
+ /**
7
+ * A command that keeps running after the tool call that started it returned
8
+ * (`nera dev`, `nera publish`): its output so far, whether it has exited and
9
+ * with which code.
10
+ *
11
+ * @typedef {object} Tracked
12
+ * @property {string} key what it was started for, e.g. `preview:/abs/site`
13
+ * @property {string} stdout everything it wrote to stdout (its end, capped)
14
+ * @property {string} stderr everything it wrote to stderr (its end, capped)
15
+ * @property {boolean} exited
16
+ * @property {number|null} code its exit code; null while running, when it was stopped by a signal or could not start
17
+ * @property {(predicate: (tracked: Tracked) => boolean, ms: number) => Promise<boolean>} waitFor
18
+ * resolves true as soon as `predicate` holds (checked now, on every output chunk and on exit), false after `ms`
19
+ */
20
+
21
+ /**
22
+ * A free TCP port on localhost, for `nera dev --port`. Vite takes the next
23
+ * one itself if another process grabs it in between, which is why the
24
+ * preview reads the URL Vite prints rather than trusting this number.
25
+ *
26
+ * @returns {Promise<number>}
27
+ */
28
+ export function freePort() {
29
+ return new Promise((resolve, reject) => {
30
+ const probe = net.createServer()
31
+ probe.unref()
32
+ probe.on('error', reject)
33
+ probe.listen(0, 'localhost', () => {
34
+ const { port } = probe.address()
35
+ probe.close(() => resolve(port))
36
+ })
37
+ })
38
+ }
39
+
40
+ /**
41
+ * The registry of long-running children, one per key. A child is started
42
+ * like a runner's (`spawnOptions`: no shell, no stdin, output captured;
43
+ * `stopChild` ends what it started too) and stays in the registry after it
44
+ * exits, so a later tool call can still read how it ended, until it is
45
+ * `forget`-ten.
46
+ * `stopAll` stops every child that is still running — the server calls it
47
+ * when it closes.
48
+ *
49
+ * @param {object} [options]
50
+ * @param {typeof nodeSpawn} [options.spawn] injected in tests
51
+ * @param {number} [options.grace] milliseconds between SIGTERM and SIGKILL
52
+ * @param {NodeJS.Platform} [options.platform] injected in tests
53
+ */
54
+ export function createProcesses({ spawn = nodeSpawn, grace = KILL_GRACE_MS, platform = process.platform } = {}) {
55
+ /** @type {Map<string, Tracked & { child: import('node:child_process').ChildProcess }>} */
56
+ const tracked = new Map()
57
+
58
+ /**
59
+ * Starts `command args` in `cwd` under `key`; a child already running
60
+ * under that key is a caller's mistake.
61
+ *
62
+ * @param {string} key
63
+ * @param {'nera'|'npm'|'node'} command
64
+ * @param {string[]} args
65
+ * @param {{ cwd: string, env?: Record<string, string> }} options
66
+ * @returns {Tracked}
67
+ */
68
+ function start(key, command, args, { cwd, env }) {
69
+ if (tracked.get(key)?.exited === false) {
70
+ throw new Error(`"${key}" is already running.`)
71
+ }
72
+ const { file, prefix } = commandFor(command, cwd)
73
+ const child = spawn(file, [...prefix, ...args], spawnOptions(cwd, env, platform))
74
+ const changes = new EventEmitter()
75
+ const entry = {
76
+ key,
77
+ child,
78
+ stdout: '',
79
+ stderr: '',
80
+ exited: false,
81
+ code: null,
82
+ waitFor(predicate, ms) {
83
+ if (predicate(entry)) return Promise.resolve(true)
84
+ return new Promise((resolve) => {
85
+ const check = () => {
86
+ if (!predicate(entry)) return
87
+ done(true)
88
+ }
89
+ const done = (value) => {
90
+ clearTimeout(timer)
91
+ changes.off('change', check)
92
+ resolve(value)
93
+ }
94
+ const timer = setTimeout(() => done(predicate(entry)), ms)
95
+ changes.on('change', check)
96
+ })
97
+ },
98
+ }
99
+ const exit = (code) => {
100
+ if (entry.exited) return
101
+ entry.exited = true
102
+ entry.code = code
103
+ changes.emit('change')
104
+ }
105
+ child.stdout.setEncoding('utf8')
106
+ child.stderr.setEncoding('utf8')
107
+ child.stdout.on('data', (chunk) => {
108
+ entry.stdout = capped(entry.stdout + chunk)
109
+ changes.emit('change')
110
+ })
111
+ child.stderr.on('data', (chunk) => {
112
+ entry.stderr = capped(entry.stderr + chunk)
113
+ changes.emit('change')
114
+ })
115
+ child.on('error', (error) => {
116
+ entry.stderr = capped(`${entry.stderr}\nCould not start ${command}: ${error.message}`)
117
+ exit(null)
118
+ })
119
+ child.on('close', (code) => exit(code))
120
+ tracked.set(key, entry)
121
+ return entry
122
+ }
123
+
124
+ /**
125
+ * Stops the child under `key` (if it still runs) and drops it.
126
+ *
127
+ * @param {string} key
128
+ * @returns {Promise<boolean>} true when there was one
129
+ */
130
+ async function stop(key) {
131
+ const entry = tracked.get(key)
132
+ if (!entry) return false
133
+ tracked.delete(key)
134
+ await stopChild(entry.child, { grace, platform, spawn })
135
+ // its output streams close just after it exits (at once, since its group is gone)
136
+ await entry.waitFor((r) => r.exited, grace)
137
+ return true
138
+ }
139
+
140
+ return {
141
+ start,
142
+ stop,
143
+ /** @returns {Tracked|undefined} */
144
+ get: (key) => tracked.get(key),
145
+ /** Drops an exited child's record, so the next call starts afresh; a running one is kept. */
146
+ forget: (key) => {
147
+ if (tracked.get(key)?.exited) tracked.delete(key)
148
+ },
149
+ /** Stops every child; resolves once all have exited. */
150
+ stopAll: () => Promise.all([...tracked.keys()].map(stop)).then(() => undefined),
151
+ }
152
+ }
package/src/prompts.js ADDED
@@ -0,0 +1,97 @@
1
+ import { z } from 'zod'
2
+
3
+ /** What every prompt tells a model that has never heard of Nera. */
4
+ const ABOUT_NERA = 'Nera is a static site generator: a site is a folder of Markdown pages (pages/, each with YAML frontmatter that names its `layout`), Pug layouts and a config/app.yaml, built into plain HTML in public/. Use only the Nera tools of this server for it; do not write HTML files by hand and do not run commands yourself.'
5
+
6
+ const VALIDATE_AND_PREVIEW = 'Call validate and fix every error it reports (each message says how), then build, then preview and give the user the preview URL.'
7
+
8
+ function userMessage(text) {
9
+ return { messages: [{ role: 'user', content: { type: 'text', text } }] }
10
+ }
11
+
12
+ /** A `label: value` line for the prompt text when the user gave a value, else an empty string. */
13
+ function given(label, value) {
14
+ return value ? `\n${label}: ${value}` : ''
15
+ }
16
+
17
+ const siteArg = z.string().optional().describe('The site folder as list_sites returns it; leave out to choose one with list_sites.')
18
+
19
+ /**
20
+ * Registers the four task prompts: new business website, new blog, add a
21
+ * page, put my site online.
22
+ *
23
+ * @param {import('@modelcontextprotocol/sdk/server/mcp.js').McpServer} server
24
+ */
25
+ export function registerPrompts(server) {
26
+ server.registerPrompt('new_business_website', {
27
+ title: 'New business website',
28
+ description: 'Create a website for a small business with Nera: home, about, services, contact, imprint and privacy.',
29
+ argsSchema: {
30
+ business: z.string().optional().describe('What the business is and does, e.g. "a bakery in Hamburg with a café".'),
31
+ folder: z.string().optional().describe('The folder name for the new site, e.g. `my-bakery`.'),
32
+ },
33
+ }, ({ business, folder }) => userMessage(`Create a website for my business with Nera.${given('The business', business)}${given('Folder', folder)}
34
+
35
+ ${ABOUT_NERA}
36
+
37
+ Steps:
38
+ 1. Call list_sites. If a site for this business already exists, ask me whether to work on it instead of creating a new one.
39
+ 2. Call list_starters and pick the \`business\` starter (or \`portfolio\` if the business shows its work in pictures).
40
+ 3. Call create_site with that starter, a short lowercase folder name${folder ? ` (\`${folder}\`)` : ''}, the business name as \`title\` and the site language as \`lang\`.
41
+ 4. Call get_site, then read_page on each sample page and rewrite it with write_page for my business, keeping each page's \`layout\` in its frontmatter. Ask me for facts you do not know (address, opening hours, services, prices) instead of inventing them; leave a clear placeholder where I must fill something in.
42
+ 5. Fill in the imprint and privacy pages' placeholders only with what I told you, and tell me which legal details are still missing.
43
+ 6. ${VALIDATE_AND_PREVIEW}
44
+ 7. Tell me which pages exist and that put_site_online publishes the site when I am happy with it.`))
45
+
46
+ server.registerPrompt('new_blog', {
47
+ title: 'New blog',
48
+ description: 'Create a blog with Nera: posts with tags, an archive, a feed and a sitemap.',
49
+ argsSchema: {
50
+ topic: z.string().optional().describe('What the blog is about, e.g. "travel and photography".'),
51
+ folder: z.string().optional().describe('The folder name for the new site, e.g. `my-blog`.'),
52
+ },
53
+ }, ({ topic, folder }) => userMessage(`Create a blog for me with Nera.${given('Topic', topic)}${given('Folder', folder)}
54
+
55
+ ${ABOUT_NERA}
56
+
57
+ Steps:
58
+ 1. Call list_sites. If a blog already exists, ask me whether to work on it instead of creating a new one.
59
+ 2. Call list_starters and pick the \`blog\` starter.
60
+ 3. Call create_site with it, a short lowercase folder name${folder ? ` (\`${folder}\`)` : ''}, the blog's name as \`title\` and its language as \`lang\`.
61
+ 4. Call get_site and read_page on one sample post to see the frontmatter a post uses (title, date, tags, layout).
62
+ 5. Replace the sample posts with write_page: one first post on my topic, written with me, using the same frontmatter fields and \`layout\`; delete the other samples with delete_page once I agree. Update the home and about pages.
63
+ 6. ${VALIDATE_AND_PREVIEW}
64
+ 7. Tell me how to add the next post (the add_page prompt does it) and that put_site_online publishes the blog.`))
65
+
66
+ server.registerPrompt('add_page', {
67
+ title: 'Add a page',
68
+ description: 'Add a new page (or blog post) to an existing Nera site, in the style of its other pages.',
69
+ argsSchema: {
70
+ site: siteArg,
71
+ topic: z.string().optional().describe('What the new page is about, e.g. "our new opening hours" or "a post about my trip to Lisbon".'),
72
+ },
73
+ }, ({ site, topic }) => userMessage(`Add a new page to my Nera site.${given('Site', site)}${given('The page', topic)}
74
+
75
+ ${ABOUT_NERA}
76
+
77
+ Steps:
78
+ 1. ${site ? `Call get_site with site \`${site}\`.` : 'Call list_sites; if there is more than one site, ask me which one. Then call get_site.'} Read the site's AGENTS.md resource (\`nera://site/<site>/AGENTS.md\`) if it has one.
79
+ 2. Call read_page on an existing page of the same kind (a post for a post, a normal page otherwise) and copy its frontmatter fields and \`layout\`.
80
+ 3. Choose a file name that fits the site's other pages (lowercase, hyphens, \`.md\`, in the same folder as its siblings) and write the page with write_page. Ask me for content you do not know.
81
+ 4. If the site has a navigation config (e.g. config/navigation.yaml, see get_site's plugins and read_file), add the page there when it belongs in the menu, with write_file.
82
+ 5. ${VALIDATE_AND_PREVIEW}`))
83
+
84
+ server.registerPrompt('put_site_online', {
85
+ title: 'Put my site online',
86
+ description: 'Publish a Nera site on the web for free (GitHub Pages or Netlify), with no hosting knowledge needed.',
87
+ argsSchema: { site: siteArg },
88
+ }, ({ site }) => userMessage(`Put my Nera site online.${given('Site', site)}
89
+
90
+ ${ABOUT_NERA}
91
+
92
+ Steps:
93
+ 1. ${site ? `Use site \`${site}\`.` : 'Call list_sites; if there is more than one site, ask me which one.'}
94
+ 2. Call validate and fix every error; then call build with \`check: true\` and tell me about accessibility, privacy and legal findings (an imprint and a privacy page are required for many sites, e.g. in Germany). Fix what you can with my consent.
95
+ 3. Call publish for the site. It returns a short code and a GitHub web address: give me both and ask me to open the address, sign in to GitHub (or create a free account) and enter the code. Never ask me for a password or token.
96
+ 4. After I confirm, call publish again for the same site until it reports the result, and give me the address where the site is now online. Tell me that later changes go online by calling publish again.`))
97
+ }