@nifrajs/cli 2.14.1 → 3.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.
Files changed (203) hide show
  1. package/README.md +10 -0
  2. package/dist/assure-hydration.d.ts.map +1 -1
  3. package/dist/assure-hydration.js +6 -1
  4. package/dist/assure-hydration.js.map +1 -1
  5. package/dist/assure.d.ts.map +1 -1
  6. package/dist/assure.js +3 -2
  7. package/dist/assure.js.map +1 -1
  8. package/dist/check-diagnostics.d.ts +165 -0
  9. package/dist/check-diagnostics.d.ts.map +1 -0
  10. package/dist/check-diagnostics.js +1009 -0
  11. package/dist/check-diagnostics.js.map +1 -0
  12. package/dist/check-scan.d.ts +245 -0
  13. package/dist/check-scan.d.ts.map +1 -0
  14. package/dist/check-scan.js +1599 -0
  15. package/dist/check-scan.js.map +1 -0
  16. package/dist/check.d.ts +4 -324
  17. package/dist/check.d.ts.map +1 -1
  18. package/dist/check.js +8 -2346
  19. package/dist/check.js.map +1 -1
  20. package/dist/cli.d.ts.map +1 -1
  21. package/dist/cli.js +285 -10
  22. package/dist/cli.js.map +1 -1
  23. package/dist/command-catalog.d.ts +27 -1
  24. package/dist/command-catalog.d.ts.map +1 -1
  25. package/dist/command-catalog.js +142 -2
  26. package/dist/command-catalog.js.map +1 -1
  27. package/dist/doctor.d.ts +42 -0
  28. package/dist/doctor.d.ts.map +1 -1
  29. package/dist/doctor.js +64 -7
  30. package/dist/doctor.js.map +1 -1
  31. package/dist/env-file.d.ts +17 -0
  32. package/dist/env-file.d.ts.map +1 -0
  33. package/dist/env-file.js +113 -0
  34. package/dist/env-file.js.map +1 -0
  35. package/dist/fix-recipes.d.ts.map +1 -1
  36. package/dist/fix-recipes.js +91 -15
  37. package/dist/fix-recipes.js.map +1 -1
  38. package/dist/frontend-guidance.d.ts +57 -0
  39. package/dist/frontend-guidance.d.ts.map +1 -0
  40. package/dist/frontend-guidance.js +195 -0
  41. package/dist/frontend-guidance.js.map +1 -0
  42. package/dist/internal/reserved-segment-codemod.d.ts +36 -0
  43. package/dist/internal/reserved-segment-codemod.d.ts.map +1 -0
  44. package/dist/internal/reserved-segment-codemod.js +134 -0
  45. package/dist/internal/reserved-segment-codemod.js.map +1 -0
  46. package/dist/internal/typescript-import.d.ts +1 -1
  47. package/dist/internal/typescript-import.d.ts.map +1 -1
  48. package/dist/internal/typescript-import.js +62 -11
  49. package/dist/internal/typescript-import.js.map +1 -1
  50. package/dist/introspect.d.ts +26 -1
  51. package/dist/introspect.d.ts.map +1 -1
  52. package/dist/introspect.js +74 -24
  53. package/dist/introspect.js.map +1 -1
  54. package/dist/levels-tool.d.ts.map +1 -1
  55. package/dist/levels-tool.js +6 -0
  56. package/dist/levels-tool.js.map +1 -1
  57. package/dist/load.d.ts.map +1 -1
  58. package/dist/load.js +4 -1
  59. package/dist/load.js.map +1 -1
  60. package/dist/mcp-context.d.ts +48 -0
  61. package/dist/mcp-context.d.ts.map +1 -0
  62. package/dist/mcp-context.js +215 -0
  63. package/dist/mcp-context.js.map +1 -0
  64. package/dist/mcp-docs-tools.d.ts.map +1 -1
  65. package/dist/mcp-docs-tools.js +31 -0
  66. package/dist/mcp-docs-tools.js.map +1 -1
  67. package/dist/mcp-exec.d.ts +74 -0
  68. package/dist/mcp-exec.d.ts.map +1 -0
  69. package/dist/mcp-exec.js +844 -0
  70. package/dist/mcp-exec.js.map +1 -0
  71. package/dist/mcp-http.js +1 -1
  72. package/dist/mcp-http.js.map +1 -1
  73. package/dist/mcp-io.d.ts +26 -0
  74. package/dist/mcp-io.d.ts.map +1 -0
  75. package/dist/mcp-io.js +100 -0
  76. package/dist/mcp-io.js.map +1 -0
  77. package/dist/mcp-reflect.d.ts +16 -0
  78. package/dist/mcp-reflect.d.ts.map +1 -0
  79. package/dist/mcp-reflect.js +101 -0
  80. package/dist/mcp-reflect.js.map +1 -0
  81. package/dist/mcp-root.d.ts +7 -0
  82. package/dist/mcp-root.d.ts.map +1 -1
  83. package/dist/mcp-root.js +51 -3
  84. package/dist/mcp-root.js.map +1 -1
  85. package/dist/mcp.d.ts +10 -84
  86. package/dist/mcp.d.ts.map +1 -1
  87. package/dist/mcp.js +13 -1170
  88. package/dist/mcp.js.map +1 -1
  89. package/dist/openapi-tool.d.ts +5 -10
  90. package/dist/openapi-tool.d.ts.map +1 -1
  91. package/dist/openapi-tool.js +21 -2
  92. package/dist/openapi-tool.js.map +1 -1
  93. package/dist/openapi-types.d.ts +21 -0
  94. package/dist/openapi-types.d.ts.map +1 -0
  95. package/dist/openapi-types.js +214 -0
  96. package/dist/openapi-types.js.map +1 -0
  97. package/dist/port.d.ts.map +1 -1
  98. package/dist/port.js +2 -1
  99. package/dist/port.js.map +1 -1
  100. package/dist/project-facts.d.ts +2 -1
  101. package/dist/project-facts.d.ts.map +1 -1
  102. package/dist/project-facts.js.map +1 -1
  103. package/dist/recipes/3.0.0.d.ts +10 -0
  104. package/dist/recipes/3.0.0.d.ts.map +1 -0
  105. package/dist/recipes/3.0.0.js +23 -0
  106. package/dist/recipes/3.0.0.js.map +1 -0
  107. package/dist/recipes/index.d.ts.map +1 -1
  108. package/dist/recipes/index.js +2 -0
  109. package/dist/recipes/index.js.map +1 -1
  110. package/dist/release-verification.d.ts +4 -1
  111. package/dist/release-verification.d.ts.map +1 -1
  112. package/dist/release-verification.js +6 -123
  113. package/dist/release-verification.js.map +1 -1
  114. package/dist/rules/codes.d.ts +4 -0
  115. package/dist/rules/codes.d.ts.map +1 -1
  116. package/dist/rules/codes.js +4 -0
  117. package/dist/rules/codes.js.map +1 -1
  118. package/dist/rules/islands.d.ts +4 -0
  119. package/dist/rules/islands.d.ts.map +1 -0
  120. package/dist/rules/islands.js +155 -0
  121. package/dist/rules/islands.js.map +1 -0
  122. package/dist/rules/nano.d.ts +6 -0
  123. package/dist/rules/nano.d.ts.map +1 -0
  124. package/dist/rules/nano.js +264 -0
  125. package/dist/rules/nano.js.map +1 -0
  126. package/dist/rules/routes.d.ts.map +1 -1
  127. package/dist/rules/routes.js +17 -30
  128. package/dist/rules/routes.js.map +1 -1
  129. package/dist/rules/security.d.ts.map +1 -1
  130. package/dist/rules/security.js +38 -4
  131. package/dist/rules/security.js.map +1 -1
  132. package/dist/scaffold.d.ts +12 -6
  133. package/dist/scaffold.d.ts.map +1 -1
  134. package/dist/scaffold.js +149 -10
  135. package/dist/scaffold.js.map +1 -1
  136. package/dist/search-terms.d.ts.map +1 -1
  137. package/dist/search-terms.js +5 -3
  138. package/dist/search-terms.js.map +1 -1
  139. package/dist/stylex-migrate.d.ts +38 -0
  140. package/dist/stylex-migrate.d.ts.map +1 -0
  141. package/dist/stylex-migrate.js +1052 -0
  142. package/dist/stylex-migrate.js.map +1 -0
  143. package/dist/sync-manifest.d.ts.map +1 -1
  144. package/dist/sync-manifest.js +2 -1
  145. package/dist/sync-manifest.js.map +1 -1
  146. package/dist/verification-plan.d.ts +24 -0
  147. package/dist/verification-plan.d.ts.map +1 -0
  148. package/dist/verification-plan.js +116 -0
  149. package/dist/verification-plan.js.map +1 -0
  150. package/dist/work-graph.d.ts.map +1 -1
  151. package/dist/work-graph.js +6 -3
  152. package/dist/work-graph.js.map +1 -1
  153. package/dist/workspace-link.d.ts +37 -0
  154. package/dist/workspace-link.d.ts.map +1 -0
  155. package/dist/workspace-link.js +72 -0
  156. package/dist/workspace-link.js.map +1 -0
  157. package/docs/examples.json +37 -1
  158. package/docs/llms-full.txt +1598 -44
  159. package/docs/types.json +5157 -172
  160. package/package.json +9 -9
  161. package/src/assure-hydration.ts +6 -1
  162. package/src/assure.ts +4 -2
  163. package/src/check-diagnostics.ts +1219 -0
  164. package/src/check-scan.ts +1825 -0
  165. package/src/check.ts +47 -2731
  166. package/src/cli.ts +291 -10
  167. package/src/command-catalog.ts +177 -2
  168. package/src/doctor.ts +99 -8
  169. package/src/env-file.ts +121 -0
  170. package/src/fix-recipes.ts +101 -15
  171. package/src/frontend-guidance.ts +259 -0
  172. package/src/internal/reserved-segment-codemod.ts +150 -0
  173. package/src/internal/typescript-import.ts +61 -11
  174. package/src/introspect.ts +82 -21
  175. package/src/levels-tool.ts +6 -0
  176. package/src/load.ts +4 -1
  177. package/src/mcp-context.ts +266 -0
  178. package/src/mcp-docs-tools.ts +37 -0
  179. package/src/mcp-exec.ts +1040 -0
  180. package/src/mcp-http.ts +1 -1
  181. package/src/mcp-io.ts +118 -0
  182. package/src/mcp-reflect.ts +140 -0
  183. package/src/mcp-root.ts +62 -4
  184. package/src/mcp.ts +61 -1436
  185. package/src/openapi-tool.ts +32 -2
  186. package/src/openapi-types.ts +261 -0
  187. package/src/port.ts +2 -1
  188. package/src/project-facts.ts +2 -4
  189. package/src/recipes/3.0.0.ts +24 -0
  190. package/src/recipes/index.ts +2 -0
  191. package/src/release-verification.ts +22 -147
  192. package/src/rules/codes.ts +4 -0
  193. package/src/rules/islands.ts +171 -0
  194. package/src/rules/nano.ts +295 -0
  195. package/src/rules/routes.ts +17 -30
  196. package/src/rules/security.ts +40 -4
  197. package/src/scaffold.ts +169 -9
  198. package/src/search-terms.ts +7 -3
  199. package/src/stylex-migrate.ts +1139 -0
  200. package/src/sync-manifest.ts +2 -1
  201. package/src/verification-plan.ts +242 -0
  202. package/src/work-graph.ts +6 -3
  203. package/src/workspace-link.ts +80 -0
@@ -132,6 +132,12 @@ export async function collectVerificationLevels(
132
132
  if (assurance.ok && (capabilityReport === undefined || capabilityReport.ok)) {
133
133
  const current = await buildNifraManifest({
134
134
  source: config.source,
135
+ // `evidence` is NOT optional detail here - it is what `nifra manifest emit` and the
136
+ // `versioned trust manifest drift` check in `nifra check` both hash. Omitting it made
137
+ // this recompute a manifest nothing else ever emits, so every app that publishes
138
+ // assurance evidence from outside its `.use()` chain (the `assure()` seam) reported a
139
+ // freshly emitted manifest as stale and could never reach L3.
140
+ ...(verification.evidence !== undefined ? { evidence: verification.evidence } : {}),
135
141
  assurance,
136
142
  ...(capabilityReport !== undefined ? { capabilities: capabilityReport } : {}),
137
143
  })
package/src/load.ts CHANGED
@@ -214,7 +214,10 @@ export async function loadApp(
214
214
  // and passes through unchanged.
215
215
  let clientModule: string
216
216
  if (fw.clientModule.startsWith("./") || fw.clientModule.startsWith("../")) {
217
- clientModule = resolve(cwd, fw.clientModule)
217
+ // The value is embedded in generated import source, not passed directly to a filesystem API.
218
+ // Keep it absolute but slash-normalized so the generated module is identical on POSIX and
219
+ // Windows (Bun accepts an absolute drive path with forward slashes).
220
+ clientModule = resolve(cwd, fw.clientModule).replaceAll("\\", "/")
218
221
  } else {
219
222
  // A specifier that is neither `./`-relative, scoped (`@…`), nor absolute is read as a BARE PACKAGE
220
223
  // specifier - resolved against `node_modules`, not `cwd`. If a real local file sits at that path
@@ -0,0 +1,266 @@
1
+ /**
2
+ * Project context and trust-local utilities for the MCP server.
3
+ *
4
+ * Resources, prompts, path scoping, and monorepo namespacing are independent of the JSON-RPC loop and
5
+ * of backend reflection. App loading is injected through the shared cached loader seam.
6
+ */
7
+
8
+ import { realpathSync } from "node:fs"
9
+ import { readFile } from "node:fs/promises"
10
+ import { basename, isAbsolute, relative, resolve, sep } from "node:path"
11
+ import type { LoadedApp } from "./load.ts"
12
+ import { createCachedAppLoader } from "./mcp-exec.ts"
13
+ import type { McpPrompt, McpResource, McpServerFeatures, McpTool } from "./mcp-protocol.ts"
14
+
15
+ function openApiFormat(args: Record<string, unknown>): "json" | "yaml" {
16
+ const format = args.format
17
+ return format === "yaml" ? "yaml" : "json"
18
+ }
19
+
20
+ export async function openApiHandler(
21
+ args: Record<string, unknown>,
22
+ loadAppCached: (outDirName?: string) => Promise<LoadedApp>,
23
+ ): Promise<string> {
24
+ const { renderOpenApiWithTypes } = await import("./openapi-tool.ts")
25
+ const pathPrefix = typeof args.path === "string" ? args.path : undefined
26
+ return renderOpenApiWithTypes(await loadAppCached(), openApiFormat(args), pathPrefix)
27
+ }
28
+
29
+ async function readProjectFile(
30
+ cwd: string,
31
+ relativeFile: string,
32
+ maxChars: number,
33
+ ): Promise<string> {
34
+ const target = resolve(cwd, relativeFile)
35
+ const root = resolve(cwd)
36
+ if (target !== root && !target.startsWith(`${root}${sep}`)) {
37
+ throw new Error(`refusing to read outside project root: ${relativeFile}`)
38
+ }
39
+ try {
40
+ const text = await readFile(target, "utf8")
41
+ return text.length <= maxChars
42
+ ? text
43
+ : `${text.slice(0, maxChars)}\n…(trimmed; read ${relativeFile} directly for the rest)`
44
+ } catch (err) {
45
+ if (err && typeof err === "object" && (err as { code?: string }).code === "ENOENT") {
46
+ return `No ${relativeFile} found in ${basename(cwd)}.`
47
+ }
48
+ throw err
49
+ }
50
+ }
51
+
52
+ function promptText(
53
+ text: string,
54
+ ): readonly [
55
+ { readonly role: "user"; readonly content: { readonly type: "text"; readonly text: string } },
56
+ ] {
57
+ return [{ role: "user", content: { type: "text", text } }]
58
+ }
59
+
60
+ export function projectResources(
61
+ cwd: string,
62
+ loadAppCached: (outDirName?: string) => Promise<LoadedApp> = createCachedAppLoader(cwd),
63
+ ): McpResource[] {
64
+ return [
65
+ {
66
+ uri: "nifra://routes",
67
+ name: "API routes",
68
+ description:
69
+ "Structured API routes with typed-client calls and compact request/response shapes.",
70
+ mimeType: "application/json",
71
+ read: async () => {
72
+ const { routesToJson } = await import("./introspect.ts")
73
+ return { text: JSON.stringify(routesToJson(await loadAppCached()), null, 2) }
74
+ },
75
+ },
76
+ {
77
+ uri: "nifra://openapi",
78
+ name: "OpenAPI 3.1",
79
+ description: "OpenAPI document generated from backend.ts using @nifrajs/schema.",
80
+ mimeType: "application/json",
81
+ read: async () => ({ text: await openApiHandler({ format: "json" }, loadAppCached) }),
82
+ },
83
+ {
84
+ uri: "nifra://package-json",
85
+ name: "package.json",
86
+ description: "Project package metadata and scripts.",
87
+ mimeType: "application/json",
88
+ read: async () => ({ text: await readProjectFile(cwd, "package.json", 40_000) }),
89
+ },
90
+ {
91
+ uri: "nifra://agents-md",
92
+ name: "AGENTS.md",
93
+ description: "Repository-specific agent instructions if the project has them.",
94
+ mimeType: "text/markdown",
95
+ read: async () => ({ text: await readProjectFile(cwd, "AGENTS.md", 40_000) }),
96
+ },
97
+ ]
98
+ }
99
+
100
+ export function projectPrompts(): McpPrompt[] {
101
+ return [
102
+ {
103
+ name: "nifra_new_route",
104
+ description:
105
+ "Implement a new file route with the right routes/ filename, examples, and checks.",
106
+ arguments: [
107
+ { name: "path", description: 'URL path, e.g. "/users/:id".', required: true },
108
+ { name: "goal", description: "What the page should do.", required: false },
109
+ ],
110
+ handler: async (args) =>
111
+ promptText(
112
+ [
113
+ `Create a nifra page route for ${JSON.stringify(args.path ?? "/new-route")}.`,
114
+ args.goal ? `Goal: ${String(args.goal)}` : undefined,
115
+ 'Use `nifra_context` with `{ kind: "pages" }`, then `nifra_scaffold` for the exact file path.',
116
+ "If the stub is not writable for this framework, call `nifra_example` for a verified page/loader example before editing.",
117
+ "Verify with `nifra_render` for the route and finish with `nifra_check`.",
118
+ ]
119
+ .filter(Boolean)
120
+ .join("\n"),
121
+ ),
122
+ },
123
+ {
124
+ name: "nifra_add_endpoint",
125
+ description:
126
+ "Add or update a backend endpoint with schemas, typed-client usage, and verification.",
127
+ arguments: [
128
+ { name: "method", description: "HTTP method.", required: true },
129
+ { name: "path", description: 'API path, e.g. "/users/:id".', required: true },
130
+ { name: "goal", description: "What the endpoint should do.", required: false },
131
+ ],
132
+ handler: async (args) =>
133
+ promptText(
134
+ [
135
+ `Add a nifra backend endpoint: ${String(args.method ?? "GET").toUpperCase()} ${String(args.path ?? "/api")}.`,
136
+ args.goal ? `Goal: ${String(args.goal)}` : undefined,
137
+ "Read `nifra://routes` or call `nifra_routes` first so the new route fits the existing API shape.",
138
+ "Use route schemas for untrusted body/query input and declare `response` when the frontend consumes the shape.",
139
+ "Verify behavior with `nifra_run`, then run `nifra_check` and `nifra_test` for the touched area.",
140
+ ]
141
+ .filter(Boolean)
142
+ .join("\n"),
143
+ ),
144
+ },
145
+ {
146
+ name: "nifra_debug_drift",
147
+ description:
148
+ "Debug frontend/backend contract drift using the typed client and checker output.",
149
+ arguments: [
150
+ { name: "symptom", description: "The error or behavior to investigate.", required: false },
151
+ ],
152
+ handler: async (args) =>
153
+ promptText(
154
+ [
155
+ "Debug nifra contract drift.",
156
+ args.symptom ? `Symptom: ${String(args.symptom)}` : undefined,
157
+ "Start with `nifra_check`; use each diagnostic as the source of truth.",
158
+ "Read `nifra://routes` for the exact typed-client calls and compact body/query/response shapes.",
159
+ "Prefer `client<typeof app>` over hand-rolled internal `fetch`. Verify fixed endpoints with `nifra_run`.",
160
+ ]
161
+ .filter(Boolean)
162
+ .join("\n"),
163
+ ),
164
+ },
165
+ ]
166
+ }
167
+
168
+ export function projectFeatures(
169
+ cwd: string,
170
+ loadAppCached: (outDirName?: string) => Promise<LoadedApp> = createCachedAppLoader(cwd),
171
+ ): McpServerFeatures {
172
+ return { resources: projectResources(cwd, loadAppCached), prompts: projectPrompts() }
173
+ }
174
+
175
+ /**
176
+ * Resolve an optional `dir` tool argument - a subdirectory of the project root the caller wants to scope a
177
+ * check/test to (e.g. `nifra check` on `app/` when the MCP server's root is a monorepo). Returns the
178
+ * absolute target, or `null` if `dir` escapes the root (a path-traversal guard: no `..` out, no absolute
179
+ * path elsewhere). `undefined`/empty → the root itself.
180
+ */
181
+ export function resolveProjectDir(root: string, dir: string | undefined): string | null {
182
+ if (dir === undefined || dir === "") return root
183
+ const target = resolve(root, dir)
184
+ let canonicalRoot: string
185
+ try {
186
+ canonicalRoot = realpathSync(root)
187
+ } catch {
188
+ const lexical = relative(root, target)
189
+ return lexical === "" || (!lexical.startsWith("..") && !isAbsolute(lexical)) ? target : null
190
+ }
191
+ let probe = target
192
+ const missing: string[] = []
193
+ while (true) {
194
+ try {
195
+ const canonicalProbe = realpathSync(probe)
196
+ const rel = relative(canonicalRoot, canonicalProbe)
197
+ if (rel.startsWith("..") || isAbsolute(rel)) return null
198
+ return missing.length === 0 ? canonicalProbe : resolve(canonicalProbe, ...missing.reverse())
199
+ } catch {
200
+ const parent = resolve(probe, "..")
201
+ if (parent === probe) return null
202
+ // `basename`, not a slice past `parent`: when `parent` is the filesystem root its trailing
203
+ // separator is part of it, so `parent.length + 1` eats the first character of the segment and
204
+ // the path gets rebuilt wrong.
205
+ missing.push(basename(probe))
206
+ probe = parent
207
+ }
208
+ }
209
+ }
210
+
211
+ /** Consistent error string for a `dir` that escapes the project root. */
212
+ export function dirError(dir: string | undefined): string {
213
+ return JSON.stringify(
214
+ { ok: false, error: `dir must be a subdirectory of the project root - "${dir}" escapes it.` },
215
+ null,
216
+ 2,
217
+ )
218
+ }
219
+
220
+ /** Build the project-scoped tools for `cwd`. */
221
+ export interface CommandMcpToolOptions {
222
+ readonly cwd: string
223
+ readonly loadAppCached?: () => Promise<LoadedApp>
224
+ }
225
+
226
+ /** Adapt one executable catalog spec to its MCP descriptor and project-scoped handler. */
227
+ export function namespaceForApp(
228
+ name: string,
229
+ tools: McpTool[],
230
+ features: McpServerFeatures,
231
+ ): { tools: McpTool[]; features: McpServerFeatures } {
232
+ const prefix = `nifra_${name}_`
233
+ const namespacedTools = tools.map((t) => ({
234
+ ...t,
235
+ name: t.name.startsWith("nifra_") ? t.name.replace(/^nifra_/, prefix) : `${name}_${t.name}`,
236
+ }))
237
+ const namespacedResources = (features.resources ?? []).map((r) => ({
238
+ ...r,
239
+ uri: r.uri.replace(/^nifra:\/\//, `nifra://${name}/`),
240
+ }))
241
+ const namespacedPrompts = (features.prompts ?? []).map((p) => ({
242
+ ...p,
243
+ name: p.name.replace(/^nifra_/, prefix),
244
+ }))
245
+ return {
246
+ tools: namespacedTools,
247
+ features: { resources: namespacedResources, prompts: namespacedPrompts },
248
+ }
249
+ }
250
+
251
+ /**
252
+ * Merge the backend-derived resources/prompts into `base` - and keep a project that cannot be loaded
253
+ * from deciding whether the server starts at all.
254
+ *
255
+ * Resources and prompts are OPTIONAL capabilities extracted from the app's backend, so this load is a
256
+ * best-effort enrichment. It was awaited unguarded, which made it a hard boot requirement: `loadApp`
257
+ * needs a web config (`adapter` + `clientModule`) and a `routes/` directory, and a backend-only
258
+ * project - the shape `create-nifra`'s DEFAULT template produces - has neither. On those projects the
259
+ * throw escaped before the JSON-RPC loop began, so the server wrote nothing and exited. `nifra
260
+ * init-agents` would happily register an `.mcp.json` pointing at a server that could never start, and
261
+ * every tool went with it, including the twelve that never touch the app (docs, examples, types,
262
+ * check, doctor, levels, test).
263
+ *
264
+ * Degrading costs only the backend resources/prompts. Tools that genuinely need the app still fail,
265
+ * but per call, with their own message - which is a diagnosis instead of a silence.
266
+ */
@@ -9,6 +9,7 @@
9
9
 
10
10
  import { renderDocsResult } from "./docs-search.ts"
11
11
  import { type Example, renderExamplesResult } from "./examples.ts"
12
+ import { renderFrontendResult } from "./frontend-guidance.ts"
12
13
  import { renderLearnResult } from "./learn.ts"
13
14
  import type { McpTool } from "./mcp-protocol.ts"
14
15
  import { renderTypesResult, type TypeEntry } from "./types-search.ts"
@@ -147,5 +148,41 @@ export function docsTools(
147
148
  },
148
149
  handler: async (args) => renderLearnResult((args as { step?: number }).step),
149
150
  },
151
+ {
152
+ name: "nifra_frontend",
153
+ annotations: {
154
+ title: "Frontend footgun guidance",
155
+ readOnlyHint: true,
156
+ openWorldHint: false,
157
+ },
158
+ description:
159
+ 'Diagnose a CLIENT-SIDE nifra problem by symptom, across every adapter (React/Preact/Solid/Vue/Svelte/vanilla). Returns the cause, the concrete fix, and how to verify it. Covers the nifra SEAM (a server-only import leaking into a client component, a hydration mismatch, a duplicated framework runtime, loader-data typing) - where it points at the nifra_* tool that fixes and checks it - and the per-framework reactivity-loss idioms (Vue ref, Solid props, Svelte runes, React effect deps), where it points at that framework\'s own ESLint plugin. Call with no args for the index; pass `symptom` (e.g. "hydration mismatch", "value stopped updating") and/or `adapter` to filter. Use this when a rendered page misbehaves and nifra_check is green (check owns the static seam; this owns the rest).',
160
+ inputSchema: {
161
+ type: "object",
162
+ properties: {
163
+ symptom: {
164
+ type: "string",
165
+ maxLength: 256,
166
+ description: "What you observe (omit for the index).",
167
+ },
168
+ adapter: {
169
+ type: "string",
170
+ enum: ["react", "preact", "solid", "vue", "svelte", "vanilla"],
171
+ description:
172
+ "Filter to one adapter's entries (plus the adapter-independent seam entries).",
173
+ },
174
+ limit: { type: "number", description: "Max entries to return (default 3, max 5)." },
175
+ },
176
+ additionalProperties: false,
177
+ },
178
+ handler: async (args) => {
179
+ const { symptom, adapter, limit } = args as {
180
+ symptom?: string
181
+ adapter?: string
182
+ limit?: number
183
+ }
184
+ return renderFrontendResult({ symptom, adapter, limit: clamp(limit, 1, 5, 3) })
185
+ },
186
+ },
150
187
  ]
151
188
  }