@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/package.json CHANGED
@@ -1,8 +1,21 @@
1
1
  {
2
2
  "name": "@nera-static/mcp",
3
- "version": "1.3.0",
3
+ "version": "1.4.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
+ "bin": {
7
+ "nera-mcp": "bin/nera-mcp.js"
8
+ },
9
+ "scripts": {
10
+ "lint": "nera-stan",
11
+ "test": "vitest run",
12
+ "test:watch": "vitest",
13
+ "prepack": "node scripts/fetch-docs.js && node scripts/sync-skill.js",
14
+ "mcpb": "node scripts/fetch-docs.js && node scripts/build-mcpb.js",
15
+ "skill": "node scripts/sync-skill.js",
16
+ "version": "node scripts/sync-version.js && git add .claude-plugin/plugin.json",
17
+ "prepare": "husky"
18
+ },
6
19
  "files": [
7
20
  ".claude-plugin/icon.png",
8
21
  ".claude-plugin/plugin.json",
@@ -12,14 +25,6 @@
12
25
  "src",
13
26
  "CHANGELOG.md"
14
27
  ],
15
- "scripts": {
16
- "lint": "eslint .",
17
- "test": "vitest",
18
- "prepack": "node scripts/fetch-docs.js && node scripts/sync-skill.js",
19
- "mcpb": "node scripts/fetch-docs.js && node scripts/build-mcpb.js",
20
- "skill": "node scripts/sync-skill.js",
21
- "version": "node scripts/sync-version.js && git add .claude-plugin/plugin.json"
22
- },
23
28
  "keywords": [
24
29
  "nera",
25
30
  "mcp",
@@ -38,26 +43,34 @@
38
43
  "url": "https://github.com/seebaermichi/nera-mcp/issues"
39
44
  },
40
45
  "homepage": "https://github.com/seebaermichi/nera-mcp#readme",
41
- "engines": {
42
- "node": ">=22.12.0"
43
- },
44
46
  "publishConfig": {
45
47
  "access": "public"
46
48
  },
49
+ "engines": {
50
+ "node": ">=22.12.0"
51
+ },
47
52
  "dependencies": {
48
53
  "@modelcontextprotocol/sdk": "^1.32.2",
49
54
  "@nera-static/core": "^4.18.3",
50
- "@nera-static/nera": "^1.27.0",
55
+ "@nera-static/nera": "^1.31.0",
56
+ "@nera-static/plugin-utils": "^1.9.0",
57
+ "express": "^5.3.0",
58
+ "semver": "^7.8.6",
51
59
  "yaml": "^2.9.1",
52
60
  "zod": "^4.6.7"
53
61
  },
54
62
  "devDependencies": {
55
63
  "@anthropic-ai/mcpb": "^2.1.2",
56
- "eslint": "^10.15.0",
64
+ "@nera-static/stan": "^1.1.0",
65
+ "@nera-static/test-utils": "^1.1.0",
66
+ "husky": "^9.1.7",
57
67
  "vitest": "^5.1.1"
58
68
  },
59
- "bin": {
60
- "nera-mcp": "bin/nera-mcp.js"
61
- },
62
- "mcpName": "io.github.seebaermichi/nera-mcp"
69
+ "mcpName": "io.github.seebaermichi/nera-mcp",
70
+ "nera-stan": {
71
+ "variants": {
72
+ ".github/workflows/test.yml": "windows-smoke",
73
+ ".github/workflows/publish.yml": "desktop-release"
74
+ }
75
+ }
63
76
  }
@@ -25,6 +25,9 @@ Eleventy, Hugo, Astro or Jekyll; do not apply their conventions.
25
25
  Start from an official starter when one fits, with `--starter <name>`:
26
26
  - `blank`: a home page, imprint and privacy placeholders, one layout
27
27
  - `blog`: sample posts, tags, archive, prev/next, feed, sitemap
28
+ - `stack`: a blog for developers with highlighted code, series and search
29
+ - `ansitz`: a photo blog with large photographs, series and search
30
+ - `umwege`: a travel blog with trip facts, places, photographs and search
28
31
  - `business`: home, about, services, opening hours, contact form
29
32
  - `portfolio`: project pages with image galleries, about, contact form
30
33
 
@@ -5,11 +5,15 @@ links and a sitemap.
5
5
 
6
6
  ## Fast path
7
7
 
8
- `npx @nera-static/nera new my-blog --starter blog` creates a blog on
9
- `@nera-static/theme-blog`: sample posts, tags, an archive by year,
10
- previous/next, an Atom feed, a sitemap and navigation. The theme's own
11
- templates list the posts; it does not use simple-page-list. Read its
12
- `AGENTS.md`, then replace the sample posts and the placeholder
8
+ `npx @nera-static/nera new my-blog --starter blog` creates a plain blog on
9
+ `@nera-static/theme-blog` 2.x: sample posts with a series, tags, an archive
10
+ by year, previous/next, an Atom feed, a sitemap and navigation. With `--yes`
11
+ or without a terminal it is always this plain blog; on a terminal without
12
+ `--yes` it first asks which blog. `--starter stack` (a blog for developers,
13
+ highlighted code), `--starter ansitz` (a photo blog) and `--starter umwege`
14
+ (a travel blog) pick another one directly, each on its own theme with the
15
+ same post fields. The theme's own templates list the posts; it does not use
16
+ simple-page-list. Read the new site's `AGENTS.md`, then replace the sample posts and the placeholder
13
17
  `origin: https://example.com` in `config/app.yaml` with the live URL; step 9
14
18
  below still applies. The steps below build the blog by hand instead, with
15
19
  different files.
package/src/catalog.js CHANGED
@@ -4,7 +4,7 @@ import { ok, tool, ToolError } from './results.js'
4
4
 
5
5
  /**
6
6
  * The three catalogs, as the tools and resources present them. The registry
7
- * search itself is the CLI's `listCatalog` (ROADMAP principle 4).
7
+ * search itself is the CLI's `listCatalog`: one logic, many front ends.
8
8
  */
9
9
  export const KINDS = {
10
10
  starters: {
@@ -0,0 +1,131 @@
1
+ // The HTTP app of the hosted mode (L7b): one Express app that
2
+ // is both the OAuth 2.1 authorization server and the protected MCP resource.
3
+ //
4
+ // /.well-known/oauth-protected-resource/mcp RFC 9728, names our issuer
5
+ // /.well-known/oauth-authorization-server RFC 8414 (S256 only, DCR)
6
+ // /register /authorize /token /revoke the SDK's `mcpAuthRouter`
7
+ // POST /oauth/consent our consent page's form
8
+ // GET /oauth/github/callback GitHub's redirect back to us
9
+ // /mcp Streamable HTTP, bearer-guarded
10
+ //
11
+ // The issuer is configured, never taken from the request: behind a TLS proxy
12
+ // the request says `http://127.0.0.1:…`, while every URL we publish must be the
13
+ // public `https://` one. `/mcp` is stateless — each POST gets a fresh server
14
+ // and transport, bound to the caller's token through `req.auth`, whose
15
+ // `extra.userId` picks the GitHub sign-in the site tools act as.
16
+ import express from 'express'
17
+ import { requireBearerAuth } from '@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js'
18
+ import { getOAuthProtectedResourceMetadataUrl, mcpAuthRouter } from '@modelcontextprotocol/sdk/server/auth/router.js'
19
+ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'
20
+ import { CONSENT_PATH } from './consent.js'
21
+ import { createHostedServer } from './mcp.js'
22
+ import { createProvider } from './provider.js'
23
+
24
+ /** Where the MCP endpoint lives; the protected resource is `<issuer>/mcp`. */
25
+ export const MCP_PATH = '/mcp'
26
+
27
+ /** GitHub's redirect back to us; the GitHub App's callback URL is `<issuer>` + this. */
28
+ export const GITHUB_CALLBACK_PATH = '/oauth/github/callback'
29
+
30
+ /** The largest JSON-RPC request body `/mcp` accepts. */
31
+ const MCP_BODY_LIMIT = '1mb'
32
+
33
+ /** A JSON-RPC error without a request id, for requests the transport never sees. */
34
+ function jsonRpcError(res, status, code, message) {
35
+ res.status(status).json({ jsonrpc: '2.0', error: { code, message }, id: null })
36
+ }
37
+
38
+ /**
39
+ * Checks the configured issuer: an origin only, since the SDK publishes the
40
+ * endpoints and the authorization-server metadata at the root of it. The SDK
41
+ * itself refuses a non-https issuer other than localhost.
42
+ *
43
+ * @param {string|URL} issuer
44
+ * @returns {URL}
45
+ */
46
+ function issuerUrl(issuer) {
47
+ const url = new URL(issuer)
48
+ if (url.pathname !== '/' || url.search || url.hash) {
49
+ throw new Error(`The issuer must be an origin such as https://mcp.nera-pro.app, without a path, query or fragment (got ${url.href}).`)
50
+ }
51
+ return url
52
+ }
53
+
54
+ /**
55
+ * Builds the hosted app. It does not listen: the bin (or a test) hands it to
56
+ * an HTTP server.
57
+ *
58
+ * @param {object} options
59
+ * @param {string|URL} options.issuer our public origin, e.g. `https://mcp.nera-pro.app`
60
+ * @param {ReturnType<import('./store.js').createStore>} options.store
61
+ * @param {ReturnType<import('./github.js').createGitHubClient>} options.github with `<issuer>/oauth/github/callback` as its redirect URI
62
+ * @param {typeof fetch} [options.fetch] fetches the npm registry catalogs for the tools
63
+ * @param {(token: string) => ReturnType<import('./repo.js').createRepoClient>} [options.createRepo] builds the site tools' repository client for a user's GitHub token
64
+ * @param {() => number} [options.now] the clock in milliseconds
65
+ * @param {(message: string) => void} [options.log] where failures are reported (never with a token in them)
66
+ * @param {boolean|number|string} [options.trustProxy] Express's `trust proxy`, so the rate limits see the client's address behind a proxy
67
+ * @returns {{ app: import('express').Express, provider: ReturnType<typeof createProvider> }}
68
+ */
69
+ export function createHostedApp({
70
+ issuer, store, github, fetch = globalThis.fetch, createRepo, now, log = () => {}, trustProxy = false,
71
+ }) {
72
+ const base = issuerUrl(issuer)
73
+ const resource = new URL(MCP_PATH, base)
74
+ const provider = createProvider({ store, github, resource, now, log })
75
+
76
+ const app = express()
77
+ app.disable('x-powered-by')
78
+ app.set('trust proxy', trustProxy)
79
+
80
+ app.use(mcpAuthRouter({ provider, issuerUrl: base, resourceServerUrl: resource, resourceName: 'Nera' }))
81
+ app.post(CONSENT_PATH, express.urlencoded({ extended: false }), (req, res) => provider.handleConsent(req, res))
82
+ app.get(GITHUB_CALLBACK_PATH, (req, res) => provider.handleGitHubCallback(req, res))
83
+
84
+ // Every method on /mcp passes the guard first; a token is accepted only
85
+ // when it was issued for exactly this resource.
86
+ app.use(MCP_PATH, requireBearerAuth({
87
+ verifier: provider,
88
+ resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(resource),
89
+ expectedResource: resource,
90
+ }))
91
+ app.post(MCP_PATH, express.json({ limit: MCP_BODY_LIMIT }), async (req, res) => {
92
+ const server = createHostedServer({
93
+ fetch,
94
+ userId: req.auth.extra?.userId,
95
+ githubToken: (userId) => provider.githubToken(userId),
96
+ createRepo,
97
+ })
98
+ const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined, enableJsonResponse: true })
99
+ // Both close calls are async; allSettled keeps a failed close from becoming an unhandled rejection.
100
+ res.on('close', () => void Promise.allSettled([transport.close(), server.close()]))
101
+ await server.connect(transport)
102
+ await transport.handleRequest(req, res, req.body)
103
+ })
104
+ // Stateless: there is no session to stream to (GET) or to end (DELETE).
105
+ app.all(MCP_PATH, (req, res) => {
106
+ res.setHeader('Allow', 'POST')
107
+ jsonRpcError(res, 405, -32000, 'Method not allowed: this server is stateless, send every request as a POST.')
108
+ })
109
+
110
+ // Last: a body a parser refused keeps its 4xx; anything else is a 500
111
+ // without a stack trace in the response. `/mcp` answers in JSON-RPC, the
112
+ // browser routes (consent, callback) in plain text.
113
+ app.use((error, req, res, next) => {
114
+ if (res.headersSent) {
115
+ next(error)
116
+ return
117
+ }
118
+ const clientError = error.expose && error.status >= 400 && error.status < 500
119
+ if (!clientError) log(`${req.method} ${req.path} failed: ${error.message}`)
120
+ const status = clientError ? error.status : 500
121
+ const message = clientError ? error.message : 'Internal server error.'
122
+ if (req.path === MCP_PATH) {
123
+ const code = !clientError ? -32603 : error.type === 'entity.parse.failed' ? -32700 : -32600
124
+ jsonRpcError(res, status, code, message)
125
+ return
126
+ }
127
+ res.status(status).type('text/plain').send(message)
128
+ })
129
+
130
+ return { app, provider }
131
+ }