@nera-static/mcp 1.3.0 → 1.4.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 +42 -0
- package/README.md +58 -1
- package/bin/nera-mcp.js +211 -63
- package/docs/llms-full.txt +2336 -179
- package/package.json +31 -18
- package/skills/nera/SKILL.md +3 -0
- package/skills/nera/recipes/blog.md +9 -5
- package/src/catalog.js +1 -1
- package/src/hosted/app.js +131 -0
- package/src/hosted/checkout.js +417 -0
- package/src/hosted/config.js +93 -0
- package/src/hosted/consent.js +146 -0
- package/src/hosted/crypto.js +91 -0
- package/src/hosted/github.js +160 -0
- package/src/hosted/mcp.js +62 -0
- package/src/hosted/provider.js +376 -0
- package/src/hosted/repo.js +489 -0
- package/src/hosted/store.js +490 -0
- package/src/hosted/tools/publish.js +192 -0
- package/src/hosted/tools/read.js +351 -0
- package/src/hosted/tools/validate.js +51 -0
- package/src/hosted/tools/write.js +201 -0
- package/src/pages.js +171 -0
- package/src/paths.js +11 -18
- package/src/prompts.js +80 -10
- package/src/resources.js +22 -6
- package/src/runner.js +27 -17
- package/src/server-info.js +11 -0
- package/src/server.js +14 -4
- package/src/tools/cli.js +47 -23
- package/src/tools/files.js +19 -111
- package/src/tools/long-running.js +14 -33
- package/src/tools/sites.js +39 -13
package/src/pages.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// The page and path rules both modes share: how a page file splits into
|
|
2
|
+
// frontmatter and body, how new frontmatter is edited into an existing
|
|
3
|
+
// block, that a page names its `layout`, and which paths no tool reads or
|
|
4
|
+
// writes. Pure functions only — the local file tools (src/tools/files.js) and
|
|
5
|
+
// the hosted repo tools apply them to a file on disk and a file on GitHub alike.
|
|
6
|
+
import path from 'node:path'
|
|
7
|
+
import { isDeepStrictEqual } from 'node:util'
|
|
8
|
+
import { FRONTMATTER_OPTIONS, splitFrontmatter } from '@nera-static/plugin-utils/frontmatter'
|
|
9
|
+
import yaml from 'yaml'
|
|
10
|
+
import { ToolError } from './results.js'
|
|
11
|
+
|
|
12
|
+
export const FENCE = '---'
|
|
13
|
+
/** Path segments no file tool reads or writes: git internals may hold credentials. */
|
|
14
|
+
export const FORBIDDEN_SEGMENTS = new Set(['.git'])
|
|
15
|
+
/** File names no file tool reads or writes: `.env` files and `.npmrc` (npm `_authToken`) hold tokens. */
|
|
16
|
+
export const SECRET_FILE = /^(\.env(\..*)?|\.npmrc)$/
|
|
17
|
+
/** Path segments write_file refuses: installed packages belong to npm. */
|
|
18
|
+
export const NO_WRITE_SEGMENTS = new Set(['node_modules'])
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The YAML options page frontmatter is read with: core's
|
|
22
|
+
* (`FRONTMATTER_OPTIONS`, so merge keys and repeated keys behave as in the
|
|
23
|
+
* build) without the `timestamp` tag, so an unquoted `date: 2026-11-28` stays
|
|
24
|
+
* the text the author wrote instead of becoming a date-time. The hosted
|
|
25
|
+
* checkout (src/hosted/checkout.js) reads layouts with them too, as the
|
|
26
|
+
* validator does.
|
|
27
|
+
*/
|
|
28
|
+
export const PAGE_YAML_OPTIONS = Object.freeze({ ...FRONTMATTER_OPTIONS, customTags: Object.freeze([]) })
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Splits a page into its frontmatter YAML and its Markdown body by the
|
|
32
|
+
* build's rule (`splitFrontmatter`); a page without a `---` first line is
|
|
33
|
+
* body only.
|
|
34
|
+
*
|
|
35
|
+
* @param {string} raw the file's text
|
|
36
|
+
* @returns {{ yamlText: string|null, body: string }} `yamlText` null when the page has no frontmatter
|
|
37
|
+
*/
|
|
38
|
+
function pageParts(raw) {
|
|
39
|
+
return splitFrontmatter(raw) ?? { yamlText: null, body: raw }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Parses frontmatter YAML into a document that keeps comments and quoting.
|
|
44
|
+
*
|
|
45
|
+
* @param {string|null} yamlText
|
|
46
|
+
* @returns {{ doc: import('yaml').Document|null, error: string|null }}
|
|
47
|
+
*/
|
|
48
|
+
export function parseFrontmatter(yamlText) {
|
|
49
|
+
const doc = yaml.parseDocument(yamlText ?? '', PAGE_YAML_OPTIONS)
|
|
50
|
+
if (doc.errors.length) {
|
|
51
|
+
return { doc: null, error: doc.errors[0].message }
|
|
52
|
+
}
|
|
53
|
+
if (doc.contents !== null && !yaml.isMap(doc.contents)) {
|
|
54
|
+
return { doc: null, error: 'The frontmatter is not a list of `key: value` lines.' }
|
|
55
|
+
}
|
|
56
|
+
return { doc, error: null }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Reads a page's text the way read_page returns it: the frontmatter as JSON
|
|
61
|
+
* (null when its YAML is invalid, with `error` saying why) and the body
|
|
62
|
+
* without its leading blank lines.
|
|
63
|
+
*
|
|
64
|
+
* @param {string} raw the file's text
|
|
65
|
+
* @returns {{ frontmatter: object|null, body: string, error: string|null }}
|
|
66
|
+
*/
|
|
67
|
+
export function parsePage(raw) {
|
|
68
|
+
const { yamlText, body } = pageParts(raw)
|
|
69
|
+
const { doc, error } = parseFrontmatter(yamlText)
|
|
70
|
+
return { frontmatter: doc ? (doc.toJS() ?? {}) : null, body: body.replace(/^\n+/, ''), error }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The frontmatter YAML for `frontmatter`, edited into the page's existing
|
|
75
|
+
* frontmatter when it has one that parses: unchanged keys keep their comments,
|
|
76
|
+
* quoting and order, a changed value keeps its quoting style, keys left out are
|
|
77
|
+
* removed, new keys are appended. Nothing changed: the block stays byte for byte.
|
|
78
|
+
*
|
|
79
|
+
* @param {string|null} existingYaml the page's current frontmatter, null for none
|
|
80
|
+
* @param {Record<string, unknown>} frontmatter
|
|
81
|
+
* @returns {string}
|
|
82
|
+
*/
|
|
83
|
+
export function frontmatterText(existingYaml, frontmatter) {
|
|
84
|
+
const { doc } = existingYaml === null ? { doc: null } : parseFrontmatter(existingYaml)
|
|
85
|
+
if (!doc || doc.contents === null) {
|
|
86
|
+
return new yaml.Document(frontmatter).toString({ flowCollectionPadding: false })
|
|
87
|
+
}
|
|
88
|
+
const current = doc.toJS() ?? {}
|
|
89
|
+
let changed = false
|
|
90
|
+
for (const key of Object.keys(current)) {
|
|
91
|
+
if (!Object.hasOwn(frontmatter, key)) {
|
|
92
|
+
doc.delete(key)
|
|
93
|
+
changed = true
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (const [key, value] of Object.entries(frontmatter)) {
|
|
97
|
+
if (!isDeepStrictEqual(current[key], value)) {
|
|
98
|
+
doc.set(key, value)
|
|
99
|
+
changed = true
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (!changed) return withTrailingNewline(existingYaml)
|
|
103
|
+
return doc.toString({ flowCollectionPadding: false })
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {string} text
|
|
108
|
+
* @returns {string} `text`, ending in exactly the newline it had or one added
|
|
109
|
+
*/
|
|
110
|
+
export function withTrailingNewline(text) {
|
|
111
|
+
return text.endsWith('\n') ? text : `${text}\n`
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Refuses frontmatter without `layout`: core never renders such a page.
|
|
116
|
+
*
|
|
117
|
+
* @param {Record<string, unknown>} frontmatter
|
|
118
|
+
* @throws {ToolError}
|
|
119
|
+
*/
|
|
120
|
+
export function requireLayout(frontmatter) {
|
|
121
|
+
if (typeof frontmatter.layout !== 'string' || frontmatter.layout.trim() === '') {
|
|
122
|
+
throw new ToolError('The frontmatter has no `layout`. Nera only renders pages that name their layout — add e.g. `layout: pages/default.pug` (read an existing page with read_page to see which layout the site uses).')
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The new text of a page written by write_page.
|
|
128
|
+
*
|
|
129
|
+
* @param {string|null} raw the page's current text, null for a new page
|
|
130
|
+
* @param {Record<string, unknown>} frontmatter
|
|
131
|
+
* @param {string} [body] the new Markdown body; undefined keeps the existing one
|
|
132
|
+
* @returns {string}
|
|
133
|
+
*/
|
|
134
|
+
export function composePage(raw, frontmatter, body) {
|
|
135
|
+
const existing = raw === null ? null : pageParts(raw)
|
|
136
|
+
const head = `${FENCE}\n${frontmatterText(existing?.yamlText ?? null, frontmatter)}${FENCE}\n`
|
|
137
|
+
return body === undefined
|
|
138
|
+
? head + (existing?.body ?? '')
|
|
139
|
+
: `${head}\n${withTrailingNewline(body.replace(/^\n+/, ''))}`
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Refuses `input` when it, or the site-relative real path it resolved to (a
|
|
144
|
+
* symbolic link may point into `.git/`), has a segment from `segments`.
|
|
145
|
+
*
|
|
146
|
+
* @param {string} input the path as the model gave it
|
|
147
|
+
* @param {string} resolved the site-relative path it resolved to
|
|
148
|
+
* @param {Set<string>} segments
|
|
149
|
+
* @param {string} why completes "…, which <why>."
|
|
150
|
+
* @throws {ToolError}
|
|
151
|
+
*/
|
|
152
|
+
export function refuseSegments(input, resolved, segments, why) {
|
|
153
|
+
const hit = [input, resolved]
|
|
154
|
+
.flatMap((candidate) => candidate.split(/[\\/]/))
|
|
155
|
+
.find((segment) => segments.has(segment))
|
|
156
|
+
if (hit) throw new ToolError(`"${input}" is inside ${hit}/, which ${why}.`)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Refuses git internals and files that can hold secrets (`.env*`, `.npmrc`).
|
|
161
|
+
*
|
|
162
|
+
* @param {string} input the path as the model gave it
|
|
163
|
+
* @param {string} resolved the site-relative path it resolved to
|
|
164
|
+
* @throws {ToolError}
|
|
165
|
+
*/
|
|
166
|
+
export function refuseSecrets(input, resolved) {
|
|
167
|
+
refuseSegments(input, resolved, FORBIDDEN_SEGMENTS, 'these tools never read or change')
|
|
168
|
+
if ([input, resolved].some((candidate) => SECRET_FILE.test(path.basename(candidate)))) {
|
|
169
|
+
throw new ToolError(`"${input}" can hold secrets (tokens, passwords); these tools never read or change it.`)
|
|
170
|
+
}
|
|
171
|
+
}
|
package/src/paths.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs/promises'
|
|
2
2
|
import path from 'node:path'
|
|
3
|
+
import { isInside } from '@nera-static/plugin-utils/urls'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* A path a tool was given that points outside the folder it may touch, or that
|
|
@@ -29,11 +30,13 @@ export async function realRoot(root) {
|
|
|
29
30
|
try {
|
|
30
31
|
real = await fs.realpath(path.resolve(root))
|
|
31
32
|
} catch {
|
|
32
|
-
throw new PathError(`Root folder "${root}" does not exist. Create it, or start the server with --root
|
|
33
|
+
throw new PathError(`Root folder "${root}" does not exist. Create it, or start the server with --root ` +
|
|
34
|
+
'pointing at an existing folder.')
|
|
33
35
|
}
|
|
34
36
|
const stat = await fs.stat(real)
|
|
35
37
|
if (!stat.isDirectory()) {
|
|
36
|
-
throw new PathError(`Root "${root}" is a file, not a folder. Start the server with
|
|
38
|
+
throw new PathError(`Root "${root}" is a file, not a folder. Start the server with ` +
|
|
39
|
+
'--root pointing at a folder.')
|
|
37
40
|
}
|
|
38
41
|
return real
|
|
39
42
|
}
|
|
@@ -62,7 +65,8 @@ export async function resolveInRoot(base, input, { label = 'path' } = {}) {
|
|
|
62
65
|
|
|
63
66
|
const real = await realpathOfNearest(path.resolve(base, input), input, label)
|
|
64
67
|
if (!isInside(base, real)) {
|
|
65
|
-
throw new PathError(`The ${label} "${input}" leads outside ${base}. Only files and
|
|
68
|
+
throw new PathError(`The ${label} "${input}" leads outside ${base}. Only files and ` +
|
|
69
|
+
'folders inside it can be used.')
|
|
66
70
|
}
|
|
67
71
|
return real
|
|
68
72
|
}
|
|
@@ -79,12 +83,14 @@ async function realpathOfNearest(target, input, label) {
|
|
|
79
83
|
return path.join(await fs.realpath(current), ...rest)
|
|
80
84
|
} catch (error) {
|
|
81
85
|
if (error.code === 'ELOOP') {
|
|
82
|
-
throw new PathError(`The ${label} "${input}" goes through a loop of symbolic links, so it cannot be
|
|
86
|
+
throw new PathError(`The ${label} "${input}" goes through a loop of symbolic links, so it cannot be ` +
|
|
87
|
+
'checked. Remove the loop or use another path.')
|
|
83
88
|
}
|
|
84
89
|
if (!MISSING.has(error.code)) throw error
|
|
85
90
|
}
|
|
86
91
|
if (await isDanglingLink(current)) {
|
|
87
|
-
throw new PathError(`The ${label} "${input}" goes through a broken symbolic link, so it cannot be
|
|
92
|
+
throw new PathError(`The ${label} "${input}" goes through a broken symbolic link, so it cannot be ` +
|
|
93
|
+
'checked. Remove the link or use another path.')
|
|
88
94
|
}
|
|
89
95
|
const parent = path.dirname(current)
|
|
90
96
|
if (parent === current) return target
|
|
@@ -100,16 +106,3 @@ async function isDanglingLink(candidate) {
|
|
|
100
106
|
return false
|
|
101
107
|
}
|
|
102
108
|
}
|
|
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
|
-
}
|
package/src/prompts.js
CHANGED
|
@@ -35,11 +35,15 @@ export function registerPrompts(server) {
|
|
|
35
35
|
${ABOUT_NERA}
|
|
36
36
|
|
|
37
37
|
Steps:
|
|
38
|
-
1. Call list_sites. If a site for this business already exists, ask me whether to work on it
|
|
38
|
+
1. Call list_sites. If a site for this business already exists, ask me whether to work on it \
|
|
39
|
+
instead of creating a new one.
|
|
39
40
|
2. Call list_starters and pick the \`business\` starter (or \`portfolio\` if the business shows its work in pictures).
|
|
40
41
|
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
|
|
42
|
-
|
|
42
|
+
4. Call get_site, then read_page on each sample page and rewrite it with write_page for my business, keeping each \
|
|
43
|
+
page's \`layout\` in its frontmatter. Ask me for facts you do not know (address, opening hours, services, prices) \
|
|
44
|
+
instead of inventing them; leave a clear placeholder where I must fill something in.
|
|
45
|
+
5. Fill in the imprint and privacy pages' placeholders only with what I told you, and tell me which legal details are \
|
|
46
|
+
still missing.
|
|
43
47
|
6. ${VALIDATE_AND_PREVIEW}
|
|
44
48
|
7. Tell me which pages exist and that put_site_online publishes the site when I am happy with it.`))
|
|
45
49
|
|
|
@@ -59,7 +63,8 @@ Steps:
|
|
|
59
63
|
2. Call list_starters and pick the \`blog\` starter.
|
|
60
64
|
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
65
|
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
|
|
66
|
+
5. Replace the sample posts with write_page: one first post on my topic, written with me, using the same frontmatter \
|
|
67
|
+
fields and \`layout\`; delete the other samples with delete_page once I agree. Update the home and about pages.
|
|
63
68
|
6. ${VALIDATE_AND_PREVIEW}
|
|
64
69
|
7. Tell me how to add the next post (the add_page prompt does it) and that put_site_online publishes the blog.`))
|
|
65
70
|
|
|
@@ -76,9 +81,12 @@ ${ABOUT_NERA}
|
|
|
76
81
|
|
|
77
82
|
Steps:
|
|
78
83
|
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
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
2. Call read_page on an existing page of the same kind (a post for a post, a normal page otherwise) and copy its \
|
|
85
|
+
frontmatter fields and \`layout\`.
|
|
86
|
+
3. Choose a file name that fits the site's other pages (lowercase, hyphens, \`.md\`, in the same folder as its \
|
|
87
|
+
siblings) and write the page with write_page. Ask me for content you do not know.
|
|
88
|
+
4. If the site has a navigation config (e.g. config/navigation.yaml, see get_site's plugins and read_file), add the \
|
|
89
|
+
page there when it belongs in the menu, with write_file.
|
|
82
90
|
5. ${VALIDATE_AND_PREVIEW}`))
|
|
83
91
|
|
|
84
92
|
server.registerPrompt('put_site_online', {
|
|
@@ -91,7 +99,69 @@ ${ABOUT_NERA}
|
|
|
91
99
|
|
|
92
100
|
Steps:
|
|
93
101
|
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
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
2. Call validate and fix every error; then call build with \`check: true\` and tell me about accessibility, privacy \
|
|
103
|
+
and legal findings (an imprint and a privacy page are required for many sites, e.g. in Germany). Fix what you can with \
|
|
104
|
+
my consent.
|
|
105
|
+
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 \
|
|
106
|
+
address, sign in to GitHub (or create a free account) and enter the code. Never ask me for a password or token.
|
|
107
|
+
4. After I confirm, call publish again for the same site until it reports the result, and give me the address where \
|
|
108
|
+
the site is now online. Tell me that later changes go online by calling publish again.`))
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** What the hosted prompts add: the site is a GitHub repository and changes wait on a draft. */
|
|
112
|
+
const ABOUT_HOSTED = 'Here each site is a GitHub repository of the user. write_page, write_file and delete_page commit to its draft branch nera-draft, one commit each with the message you pass; nothing goes live until publish merges the draft into main, which starts the site\'s deploy workflow once for all changes.'
|
|
113
|
+
|
|
114
|
+
const VALIDATE_AND_PUBLISH = 'Call validate and fix every error it reports (each message says how). Then ask me whether to put the changes live; when I agree, call publish, give me the address it reports and tell me the deploy takes a minute or two (preview shows how it went).'
|
|
115
|
+
|
|
116
|
+
const hostedSiteArg = z.string().optional().describe('The site as `owner/name`, as list_sites returns it; leave out to choose one with list_sites.')
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Registers the task prompts of the hosted mode, worded for its tools (write
|
|
120
|
+
* → validate → publish, no build): add a page, put my site online. The
|
|
121
|
+
* `new_*` prompts need `create_site`, which the hosted mode does not have.
|
|
122
|
+
*
|
|
123
|
+
* @param {import('@modelcontextprotocol/sdk/server/mcp.js').McpServer} server
|
|
124
|
+
*/
|
|
125
|
+
export function registerHostedPrompts(server) {
|
|
126
|
+
server.registerPrompt('add_page', {
|
|
127
|
+
title: 'Add a page',
|
|
128
|
+
description: 'Add a new page (or blog post) to a Nera site in a GitHub repository, in the style of its other pages, and put it live.',
|
|
129
|
+
argsSchema: {
|
|
130
|
+
site: hostedSiteArg,
|
|
131
|
+
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".'),
|
|
132
|
+
},
|
|
133
|
+
}, ({ site, topic }) => userMessage(`Add a new page to my Nera site.${given('Site', site)}${given('The page', topic)}
|
|
134
|
+
|
|
135
|
+
${ABOUT_NERA}
|
|
136
|
+
|
|
137
|
+
${ABOUT_HOSTED}
|
|
138
|
+
|
|
139
|
+
Steps:
|
|
140
|
+
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 with read_file if it has one.
|
|
141
|
+
2. Call read_page on an existing page of the same kind (a post for a post, a normal page otherwise) and copy its \
|
|
142
|
+
frontmatter fields and \`layout\`.
|
|
143
|
+
3. Choose a file name that fits the site's other pages (lowercase, hyphens, \`.md\`, in the same folder as its \
|
|
144
|
+
siblings) and write the page with write_page, with a short commit message. Ask me for content you do not know.
|
|
145
|
+
4. If the site has a navigation config (e.g. config/navigation.yaml, see get_site's plugins and read_file), add the \
|
|
146
|
+
page there when it belongs in the menu, with write_file.
|
|
147
|
+
5. ${VALIDATE_AND_PUBLISH}`))
|
|
148
|
+
|
|
149
|
+
server.registerPrompt('put_site_online', {
|
|
150
|
+
title: 'Put my site online',
|
|
151
|
+
description: 'Put the unpublished changes of a Nera site in a GitHub repository live: check them, publish them in one deploy and report the live address.',
|
|
152
|
+
argsSchema: { site: hostedSiteArg },
|
|
153
|
+
}, ({ site }) => userMessage(`Put my Nera site online.${given('Site', site)}
|
|
154
|
+
|
|
155
|
+
${ABOUT_NERA}
|
|
156
|
+
|
|
157
|
+
${ABOUT_HOSTED}
|
|
158
|
+
|
|
159
|
+
Steps:
|
|
160
|
+
1. ${site ? `Use site \`${site}\`.` : 'Call list_sites; if there is more than one site, ask me which one.'} Call preview to see the live address, the last deploy and how many changes wait unpublished.
|
|
161
|
+
2. Call validate and fix every error with write_page or write_file; tell me what you changed.
|
|
162
|
+
3. Call publish for the site. It merges the draft into main in one push and returns the deploy run and the address. If \
|
|
163
|
+
it reports that the repository has no deploy workflow, tell me to run \`nera publish\` once in the site on my \
|
|
164
|
+
computer, which sets it up.
|
|
165
|
+
4. Call preview after a minute or two and tell me whether the deploy succeeded and where the site is live. Tell me \
|
|
166
|
+
that later changes go live by calling publish again.`))
|
|
97
167
|
}
|
package/src/resources.js
CHANGED
|
@@ -48,17 +48,20 @@ function decodeSite(site) {
|
|
|
48
48
|
try {
|
|
49
49
|
return decodeURIComponent(String(site))
|
|
50
50
|
} catch {
|
|
51
|
-
throw new PathError(`The site "${site}" in the resource URI is not validly percent-encoded. Use the URI
|
|
51
|
+
throw new PathError(`The site "${site}" in the resource URI is not validly percent-encoded. Use the URI ` +
|
|
52
|
+
'list_sites or the resource list gives.')
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
/**
|
|
56
|
-
* Registers the
|
|
57
|
+
* Registers the resources that need no folder: the docs and the three
|
|
58
|
+
* catalogs. The hosted mode offers these alone; a site's `AGENTS.md` is its
|
|
59
|
+
* `read_file` there.
|
|
57
60
|
*
|
|
58
61
|
* @param {import('@modelcontextprotocol/sdk/server/mcp.js').McpServer} server
|
|
59
|
-
* @param {{
|
|
62
|
+
* @param {{ fetch: typeof fetch, docsFile?: string }} ctx
|
|
60
63
|
*/
|
|
61
|
-
export function
|
|
64
|
+
export function registerDocsResources(server, ctx) {
|
|
62
65
|
const docsFile = ctx.docsFile ?? BUNDLED_DOCS
|
|
63
66
|
|
|
64
67
|
server.registerResource('nera_docs', 'nera://docs/llms-full.txt', {
|
|
@@ -77,13 +80,24 @@ export function registerResources(server, ctx) {
|
|
|
77
80
|
for (const kindName of Object.keys(KINDS)) {
|
|
78
81
|
server.registerResource(`nera_${kindName}`, `nera://catalog/${kindName}`, {
|
|
79
82
|
title: `Nera ${KINDS[kindName].title}`,
|
|
80
|
-
description: `The Nera ${KINDS[kindName].title} on npm as JSON, official ones first (the same list as
|
|
83
|
+
description: `The Nera ${KINDS[kindName].title} on npm as JSON, official ones first (the same list as ` +
|
|
84
|
+
`the list_${kindName} tool).`,
|
|
81
85
|
mimeType: 'application/json',
|
|
82
86
|
}, resource(async (uri) => {
|
|
83
87
|
const items = await readCatalog(ctx, kindName)
|
|
84
88
|
return text(uri, 'application/json', JSON.stringify({ [kindName]: items }, null, 2))
|
|
85
89
|
}))
|
|
86
90
|
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Registers the docs, the three catalogs and each site's `AGENTS.md`.
|
|
95
|
+
*
|
|
96
|
+
* @param {import('@modelcontextprotocol/sdk/server/mcp.js').McpServer} server
|
|
97
|
+
* @param {{ root: string, fetch: typeof fetch, docsFile?: string }} ctx
|
|
98
|
+
*/
|
|
99
|
+
export function registerResources(server, ctx) {
|
|
100
|
+
registerDocsResources(server, ctx)
|
|
87
101
|
|
|
88
102
|
const readAgents = resource(async (uri, { site = '.' } = {}) => {
|
|
89
103
|
const resolved = await resolveSite(ctx, decodeSite(site))
|
|
@@ -92,7 +106,9 @@ export function registerResources(server, ctx) {
|
|
|
92
106
|
return text(uri, 'text/markdown', await fs.readFile(file, 'utf8'))
|
|
93
107
|
} catch (error) {
|
|
94
108
|
if (error.code !== 'ENOENT') throw error
|
|
95
|
-
throw new ToolError(`The site "${resolved.site}" has no ${AGENTS_FILE} (sites created before
|
|
109
|
+
throw new ToolError(`The site "${resolved.site}" has no ${AGENTS_FILE} (sites created before ` +
|
|
110
|
+
'@nera-static/nera 1.6.0 lack it; running `nera update` in the site writes one). ' +
|
|
111
|
+
'Call get_site instead.')
|
|
96
112
|
}
|
|
97
113
|
})
|
|
98
114
|
const listAgents = async () => {
|
package/src/runner.js
CHANGED
|
@@ -61,23 +61,27 @@ export function npmCommand(execPath = process.execPath, own = ownNpm()) {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
* The executable and leading arguments for `nera`, `npm` or `
|
|
64
|
+
* The executable and leading arguments for `nera`, `npm`, `node` or `tar` in
|
|
65
|
+
* `cwd`. `tar` is the system's, found on the child's PATH (the hosted
|
|
66
|
+
* `validate` unpacks a checkout with it).
|
|
65
67
|
*
|
|
66
|
-
* @param {'nera'|'npm'|'node'} command
|
|
68
|
+
* @param {'nera'|'npm'|'node'|'tar'} command
|
|
67
69
|
* @param {string} cwd
|
|
68
70
|
* @returns {{ file: string, prefix: string[] }}
|
|
69
71
|
* @throws {Error} for any other command
|
|
70
72
|
*/
|
|
71
73
|
export function commandFor(command, cwd) {
|
|
72
74
|
switch (command) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
case 'nera':
|
|
76
|
+
return { file: process.execPath, prefix: [neraBin(cwd)] }
|
|
77
|
+
case 'npm':
|
|
78
|
+
return npmCommand()
|
|
79
|
+
case 'node':
|
|
80
|
+
return { file: process.execPath, prefix: [] }
|
|
81
|
+
case 'tar':
|
|
82
|
+
return { file: 'tar', prefix: [] }
|
|
83
|
+
default:
|
|
84
|
+
throw new Error(`Unknown command "${command}": the runner starts nera, npm, node or tar only.`)
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
87
|
|
|
@@ -235,9 +239,11 @@ export function stopChild(child, { grace = KILL_GRACE_MS, platform = process.pla
|
|
|
235
239
|
}
|
|
236
240
|
|
|
237
241
|
/**
|
|
238
|
-
* Creates the function the tools run `nera`, `npm` and `
|
|
239
|
-
* commands that finish (`nera new`, `nera build`, `npm install`). Every
|
|
240
|
-
* gets its arguments as an array and the options of `spawnOptions
|
|
242
|
+
* Creates the function the tools run `nera`, `npm`, `node` and `tar` through,
|
|
243
|
+
* for commands that finish (`nera new`, `nera build`, `npm install`). Every
|
|
244
|
+
* run gets its arguments as an array and the options of `spawnOptions`; a run
|
|
245
|
+
* given `env` gets exactly that environment instead of `childEnv`'s (the
|
|
246
|
+
* hosted checkout strips it to PATH). A run is
|
|
241
247
|
* stopped (with everything it started) when it exceeds `timeout` or when `signal`
|
|
242
248
|
* aborts — the client cancelled the request, or the server closed.
|
|
243
249
|
*
|
|
@@ -246,17 +252,21 @@ export function stopChild(child, { grace = KILL_GRACE_MS, platform = process.pla
|
|
|
246
252
|
* @param {number} [options.timeout] milliseconds before a run is stopped
|
|
247
253
|
* @param {number} [options.grace] milliseconds between SIGTERM and SIGKILL
|
|
248
254
|
* @param {NodeJS.Platform} [options.platform] injected in tests
|
|
249
|
-
* @returns {(command: 'nera'|'npm'|'node', args: string[], options: { cwd: string, signal?: AbortSignal }) => Promise<{ code: number|null, stdout: string, stderr: string, timedOut: boolean, cancelled: boolean }>}
|
|
255
|
+
* @returns {(command: 'nera'|'npm'|'node'|'tar', args: string[], options: { cwd: string, signal?: AbortSignal, env?: Record<string, string> }) => Promise<{ code: number|null, stdout: string, stderr: string, timedOut: boolean, cancelled: boolean }>}
|
|
250
256
|
* `code` is null when the process was stopped or could not start; `stderr` then says why
|
|
251
257
|
*/
|
|
252
|
-
export function createRunner({
|
|
253
|
-
|
|
258
|
+
export function createRunner({
|
|
259
|
+
spawn = nodeSpawn, timeout = DEFAULT_TIMEOUT_MS, grace = KILL_GRACE_MS, platform = process.platform,
|
|
260
|
+
} = {}) {
|
|
261
|
+
return (command, args, { cwd, signal, env }) => new Promise((resolve) => {
|
|
254
262
|
const { file, prefix } = commandFor(command, cwd)
|
|
255
263
|
if (signal?.aborted) {
|
|
256
264
|
resolve({ code: null, stdout: '', stderr: 'Cancelled before it started.', timedOut: false, cancelled: true })
|
|
257
265
|
return
|
|
258
266
|
}
|
|
259
|
-
const
|
|
267
|
+
const options = spawnOptions(cwd, {}, platform)
|
|
268
|
+
if (env) options.env = env
|
|
269
|
+
const child = spawn(file, [...prefix, ...args], options)
|
|
260
270
|
let stdout = ''
|
|
261
271
|
let stderr = ''
|
|
262
272
|
let timedOut = false
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ownVersion } from '@nera-static/plugin-utils/packages'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The name and version both modes report in the MCP handshake and in their
|
|
5
|
+
* start-up log line. The version is read from this package's own
|
|
6
|
+
* `package.json`, wherever it is installed or bundled.
|
|
7
|
+
*/
|
|
8
|
+
export const SERVER_INFO = Object.freeze({
|
|
9
|
+
name: '@nera-static/mcp',
|
|
10
|
+
version: ownVersion(import.meta.url),
|
|
11
|
+
})
|
package/src/server.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
2
2
|
import { addPlugin as neraAddPlugin, createSite as neraCreateSite } from '@nera-static/nera'
|
|
3
|
-
import pkg from '../package.json' with { type: 'json' }
|
|
4
3
|
import { registerCatalogTools } from './catalog.js'
|
|
5
4
|
import { realRoot } from './paths.js'
|
|
6
5
|
import { createProcesses } from './processes.js'
|
|
7
6
|
import { registerPrompts } from './prompts.js'
|
|
8
7
|
import { registerResources } from './resources.js'
|
|
9
8
|
import { createRunner } from './runner.js'
|
|
9
|
+
import { SERVER_INFO } from './server-info.js'
|
|
10
10
|
import { registerCliTools } from './tools/cli.js'
|
|
11
11
|
import { registerFileTools } from './tools/files.js'
|
|
12
12
|
import { registerLongRunningTools } from './tools/long-running.js'
|
|
@@ -29,10 +29,19 @@ import { registerSiteTools } from './tools/sites.js'
|
|
|
29
29
|
* @returns {Promise<McpServer>}
|
|
30
30
|
* @throws {import('./paths.js').PathError} when `root` does not exist or is not a folder
|
|
31
31
|
*/
|
|
32
|
-
export async function createServer({
|
|
32
|
+
export async function createServer({
|
|
33
|
+
root,
|
|
34
|
+
runner = createRunner(),
|
|
35
|
+
createSite = neraCreateSite,
|
|
36
|
+
addPlugin = neraAddPlugin,
|
|
37
|
+
fetch = globalThis.fetch,
|
|
38
|
+
docsFile,
|
|
39
|
+
processes = createProcesses(),
|
|
40
|
+
timing,
|
|
41
|
+
}) {
|
|
33
42
|
const ctx = { root: await realRoot(root), runner, createSite, addPlugin, fetch, docsFile, processes, timing }
|
|
34
43
|
const server = new McpServer(
|
|
35
|
-
{
|
|
44
|
+
{ ...SERVER_INFO },
|
|
36
45
|
{
|
|
37
46
|
instructions: `Tools for Nera, a static site generator: a site is Markdown pages (pages/) rendered through Pug layouts into plain HTML. You work in ${ctx.root}. Start with list_sites; read get_site before editing a site. The prompts walk through whole tasks, the nera://docs/llms-full.txt resource holds the full documentation.`,
|
|
38
47
|
},
|
|
@@ -48,7 +57,8 @@ export async function createServer({ root, runner = createRunner(), createSite =
|
|
|
48
57
|
// call, which stops the short commands through their signal; the
|
|
49
58
|
// long-running children are stopped here.
|
|
50
59
|
server.server.onclose = () => {
|
|
51
|
-
processes.stopAll().catch((error) => console.error(
|
|
60
|
+
processes.stopAll().catch((error) => console.error('Stopping the preview and publish processes ' +
|
|
61
|
+
`failed: ${error.message}`))
|
|
52
62
|
}
|
|
53
63
|
return server
|
|
54
64
|
}
|