@mandujs/mcp 0.13.0 → 0.16.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 (136) hide show
  1. package/README.md +6 -7
  2. package/package.json +3 -2
  3. package/src/adapters/index.ts +20 -20
  4. package/src/adapters/monitor-adapter.ts +100 -100
  5. package/src/adapters/tool-adapter.ts +88 -88
  6. package/src/executor/error-handler.ts +250 -250
  7. package/src/executor/index.ts +22 -22
  8. package/src/executor/tool-executor.ts +148 -148
  9. package/src/hooks/config-watcher.ts +174 -174
  10. package/src/hooks/index.ts +23 -23
  11. package/src/hooks/mcp-hooks.ts +227 -227
  12. package/src/logging/index.ts +15 -15
  13. package/src/logging/mcp-transport.ts +134 -134
  14. package/src/registry/index.ts +13 -13
  15. package/src/registry/mcp-tool-registry.ts +298 -298
  16. package/src/resources/skills/guides.ts +1136 -1136
  17. package/src/resources/skills/index.ts +12 -12
  18. package/src/resources/skills/loader.ts +218 -218
  19. package/src/resources/skills/mandu-composition/SKILL.md +91 -91
  20. package/src/resources/skills/mandu-composition/metadata.json +13 -13
  21. package/src/resources/skills/mandu-composition/rules/_sections.md +26 -26
  22. package/src/resources/skills/mandu-composition/rules/_template.md +77 -77
  23. package/src/resources/skills/mandu-composition/rules/comp-arch-avoid-boolean-props.md +146 -146
  24. package/src/resources/skills/mandu-composition/rules/comp-arch-compound-components.md +164 -164
  25. package/src/resources/skills/mandu-composition/rules/comp-island-event.md +161 -161
  26. package/src/resources/skills/mandu-composition/rules/comp-island-slot-split.md +167 -167
  27. package/src/resources/skills/mandu-composition/rules/comp-pattern-children.md +149 -149
  28. package/src/resources/skills/mandu-composition/rules/comp-state-context-interface.md +148 -148
  29. package/src/resources/skills/mandu-composition/rules/comp-state-lift-state.md +150 -150
  30. package/src/resources/skills/mandu-deployment/SKILL.md +92 -92
  31. package/src/resources/skills/mandu-deployment/_sections.md +41 -41
  32. package/src/resources/skills/mandu-deployment/_template.md +38 -38
  33. package/src/resources/skills/mandu-deployment/metadata.json +13 -13
  34. package/src/resources/skills/mandu-deployment/rules/deploy-build-bun.md +109 -109
  35. package/src/resources/skills/mandu-deployment/rules/deploy-build-output.md +115 -115
  36. package/src/resources/skills/mandu-deployment/rules/deploy-cicd-github.md +219 -219
  37. package/src/resources/skills/mandu-deployment/rules/deploy-docker-bun.md +150 -150
  38. package/src/resources/skills/mandu-deployment/rules/deploy-docker-compose.md +223 -223
  39. package/src/resources/skills/mandu-deployment/rules/deploy-platform-fly.md +152 -152
  40. package/src/resources/skills/mandu-deployment/rules/deploy-platform-render.md +179 -179
  41. package/src/resources/skills/mandu-deployment/rules/deploy-platform-supabase.md +323 -323
  42. package/src/resources/skills/mandu-deployment/rules/deploy-platform-vercel.md +140 -140
  43. package/src/resources/skills/mandu-fs-routes/SKILL.md +82 -82
  44. package/src/resources/skills/mandu-fs-routes/metadata.json +12 -12
  45. package/src/resources/skills/mandu-fs-routes/rules/_sections.md +36 -36
  46. package/src/resources/skills/mandu-fs-routes/rules/_template.md +69 -69
  47. package/src/resources/skills/mandu-fs-routes/rules/routes-api-methods.md +65 -65
  48. package/src/resources/skills/mandu-fs-routes/rules/routes-dynamic-param.md +93 -93
  49. package/src/resources/skills/mandu-fs-routes/rules/routes-naming-page.md +55 -55
  50. package/src/resources/skills/mandu-guard/SKILL.md +129 -129
  51. package/src/resources/skills/mandu-guard/metadata.json +12 -12
  52. package/src/resources/skills/mandu-guard/rules/_sections.md +36 -36
  53. package/src/resources/skills/mandu-guard/rules/_template.md +82 -82
  54. package/src/resources/skills/mandu-guard/rules/guard-config-rules.md +100 -100
  55. package/src/resources/skills/mandu-guard/rules/guard-layer-direction.md +76 -76
  56. package/src/resources/skills/mandu-guard/rules/guard-preset-mandu.md +81 -81
  57. package/src/resources/skills/mandu-guard/rules/guard-validate-import.md +80 -80
  58. package/src/resources/skills/mandu-hydration/SKILL.md +91 -91
  59. package/src/resources/skills/mandu-hydration/metadata.json +12 -12
  60. package/src/resources/skills/mandu-hydration/rules/_sections.md +31 -31
  61. package/src/resources/skills/mandu-hydration/rules/_template.md +72 -72
  62. package/src/resources/skills/mandu-hydration/rules/hydration-data-event.md +109 -109
  63. package/src/resources/skills/mandu-hydration/rules/hydration-directive-use-client.md +55 -55
  64. package/src/resources/skills/mandu-hydration/rules/hydration-island-setup.md +113 -113
  65. package/src/resources/skills/mandu-hydration/rules/hydration-priority-visible.md +68 -68
  66. package/src/resources/skills/mandu-performance/SKILL.md +85 -85
  67. package/src/resources/skills/mandu-performance/metadata.json +14 -14
  68. package/src/resources/skills/mandu-performance/rules/_sections.md +31 -31
  69. package/src/resources/skills/mandu-performance/rules/_template.md +64 -64
  70. package/src/resources/skills/mandu-performance/rules/perf-async-defer-await.md +103 -103
  71. package/src/resources/skills/mandu-performance/rules/perf-async-parallel.md +95 -95
  72. package/src/resources/skills/mandu-performance/rules/perf-bun-file.md +124 -124
  73. package/src/resources/skills/mandu-performance/rules/perf-bun-serve.md +125 -125
  74. package/src/resources/skills/mandu-performance/rules/perf-bundle-imports.md +80 -80
  75. package/src/resources/skills/mandu-performance/rules/perf-bundle-island-lazy.md +145 -145
  76. package/src/resources/skills/mandu-performance/rules/perf-cache-react.md +98 -98
  77. package/src/resources/skills/mandu-performance/rules/perf-render-transitions.md +154 -154
  78. package/src/resources/skills/mandu-security/SKILL.md +87 -87
  79. package/src/resources/skills/mandu-security/metadata.json +13 -13
  80. package/src/resources/skills/mandu-security/rules/_sections.md +31 -31
  81. package/src/resources/skills/mandu-security/rules/_template.md +74 -74
  82. package/src/resources/skills/mandu-security/rules/sec-auth-guard.md +127 -127
  83. package/src/resources/skills/mandu-security/rules/sec-env-management.md +133 -133
  84. package/src/resources/skills/mandu-security/rules/sec-input-validate.md +148 -148
  85. package/src/resources/skills/mandu-security/rules/sec-protect-csrf.md +146 -146
  86. package/src/resources/skills/mandu-security/rules/sec-protect-headers.md +138 -138
  87. package/src/resources/skills/mandu-slot/SKILL.md +85 -85
  88. package/src/resources/skills/mandu-slot/metadata.json +12 -12
  89. package/src/resources/skills/mandu-slot/rules/_sections.md +36 -36
  90. package/src/resources/skills/mandu-slot/rules/_template.md +63 -63
  91. package/src/resources/skills/mandu-slot/rules/slot-basic-structure.md +38 -38
  92. package/src/resources/skills/mandu-slot/rules/slot-ctx-response.md +56 -56
  93. package/src/resources/skills/mandu-slot/rules/slot-guard-auth.md +59 -59
  94. package/src/resources/skills/mandu-slot/rules/slot-http-methods.md +64 -64
  95. package/src/resources/skills/mandu-styling/SKILL.md +154 -154
  96. package/src/resources/skills/mandu-styling/_sections.md +43 -43
  97. package/src/resources/skills/mandu-styling/_template.md +32 -32
  98. package/src/resources/skills/mandu-styling/metadata.json +15 -15
  99. package/src/resources/skills/mandu-styling/rules/style-component-compound.md +235 -235
  100. package/src/resources/skills/mandu-styling/rules/style-component-slots.md +255 -255
  101. package/src/resources/skills/mandu-styling/rules/style-component-tokens.md +205 -205
  102. package/src/resources/skills/mandu-styling/rules/style-island-animations.md +272 -272
  103. package/src/resources/skills/mandu-styling/rules/style-island-scoping.md +167 -167
  104. package/src/resources/skills/mandu-styling/rules/style-island-variants.md +221 -221
  105. package/src/resources/skills/mandu-styling/rules/style-perf-critical.md +209 -209
  106. package/src/resources/skills/mandu-styling/rules/style-perf-purge.md +192 -192
  107. package/src/resources/skills/mandu-styling/rules/style-setup-modules.md +162 -162
  108. package/src/resources/skills/mandu-styling/rules/style-setup-panda.md +164 -164
  109. package/src/resources/skills/mandu-styling/rules/style-setup-tailwind.md +170 -170
  110. package/src/resources/skills/mandu-styling/rules/style-tailwind-v4-gotchas.md +179 -179
  111. package/src/resources/skills/mandu-styling/rules/style-theme-darkmode.md +229 -229
  112. package/src/resources/skills/mandu-testing/SKILL.md +99 -99
  113. package/src/resources/skills/mandu-testing/metadata.json +13 -13
  114. package/src/resources/skills/mandu-testing/rules/_sections.md +26 -26
  115. package/src/resources/skills/mandu-testing/rules/_template.md +65 -65
  116. package/src/resources/skills/mandu-testing/rules/test-component-island.md +195 -195
  117. package/src/resources/skills/mandu-testing/rules/test-e2e-playwright.md +196 -196
  118. package/src/resources/skills/mandu-testing/rules/test-mock-fetch.md +219 -219
  119. package/src/resources/skills/mandu-testing/rules/test-slot-unit.md +192 -192
  120. package/src/resources/skills/mandu-ui/SKILL.md +117 -117
  121. package/src/resources/skills/mandu-ui/_sections.md +23 -23
  122. package/src/resources/skills/mandu-ui/_template.md +32 -32
  123. package/src/resources/skills/mandu-ui/metadata.json +13 -13
  124. package/src/resources/skills/mandu-ui/rules/ui-accessibility-aria.md +232 -232
  125. package/src/resources/skills/mandu-ui/rules/ui-accessibility-focus.md +238 -238
  126. package/src/resources/skills/mandu-ui/rules/ui-composition-patterns.md +259 -259
  127. package/src/resources/skills/mandu-ui/rules/ui-island-integration.md +258 -258
  128. package/src/resources/skills/mandu-ui/rules/ui-radix-patterns.md +213 -213
  129. package/src/resources/skills/mandu-ui/rules/ui-shadcn-setup.md +209 -209
  130. package/src/resources/skills/recipes.ts +932 -932
  131. package/src/tools/ate.ts +129 -0
  132. package/src/tools/index.ts +4 -1
  133. package/src/tools/project.ts +334 -334
  134. package/src/tools/runtime.ts +497 -497
  135. package/src/tools/seo.ts +417 -417
  136. package/src/utils/withWarnings.ts +83 -83
package/src/tools/seo.ts CHANGED
@@ -1,417 +1,417 @@
1
- import type { Tool } from "@modelcontextprotocol/sdk/types.js";
2
- import {
3
- renderMetadata,
4
- createDefaultMetadata,
5
- resolveMetadata,
6
- renderSitemap,
7
- renderRobots,
8
- createDefaultRobots,
9
- createArticleJsonLd,
10
- createBreadcrumbJsonLd,
11
- createFAQJsonLd,
12
- createProductJsonLd,
13
- createWebSiteJsonLd,
14
- createOrganizationJsonLd,
15
- createLocalBusinessJsonLd,
16
- createVideoJsonLd,
17
- createEventJsonLd,
18
- type Metadata,
19
- type Sitemap,
20
- type RobotsFile,
21
- type JsonLd,
22
- } from "@mandujs/core";
23
- import { getProjectPaths, readJsonFile, writeJsonFile } from "../utils/project.js";
24
- import * as fs from "fs";
25
- import * as path from "path";
26
-
27
- export const seoToolDefinitions: Tool[] = [
28
- {
29
- name: "mandu_preview_seo",
30
- description: "Preview rendered SEO HTML for given metadata. Useful for testing metadata before applying.",
31
- inputSchema: {
32
- type: "object",
33
- properties: {
34
- metadata: {
35
- type: "object",
36
- description: "Metadata object to render (title, description, openGraph, twitter, etc.)",
37
- },
38
- },
39
- required: ["metadata"],
40
- },
41
- },
42
- {
43
- name: "mandu_generate_sitemap_preview",
44
- description: "Generate sitemap.xml preview from entries",
45
- inputSchema: {
46
- type: "object",
47
- properties: {
48
- entries: {
49
- type: "array",
50
- description: "Array of sitemap entries with url, lastModified, changeFrequency, priority",
51
- items: {
52
- type: "object",
53
- properties: {
54
- url: { type: "string", description: "Page URL" },
55
- lastModified: { type: "string", description: "Last modified date (ISO string)" },
56
- changeFrequency: {
57
- type: "string",
58
- enum: ["always", "hourly", "daily", "weekly", "monthly", "yearly", "never"],
59
- },
60
- priority: { type: "number", description: "Priority 0.0 to 1.0" },
61
- images: {
62
- type: "array",
63
- items: { type: "string" },
64
- description: "Image URLs for this page",
65
- },
66
- },
67
- required: ["url"],
68
- },
69
- },
70
- },
71
- required: ["entries"],
72
- },
73
- },
74
- {
75
- name: "mandu_generate_robots_preview",
76
- description: "Generate robots.txt preview from configuration",
77
- inputSchema: {
78
- type: "object",
79
- properties: {
80
- rules: {
81
- type: "object",
82
- description: "Robots rules (userAgent, allow, disallow, crawlDelay)",
83
- },
84
- sitemap: {
85
- type: "string",
86
- description: "Sitemap URL",
87
- },
88
- },
89
- required: [],
90
- },
91
- },
92
- {
93
- name: "mandu_create_jsonld",
94
- description: "Create JSON-LD structured data for SEO. Supports Article, WebSite, Organization, Breadcrumb, FAQ, Product, LocalBusiness, Video, Event types.",
95
- inputSchema: {
96
- type: "object",
97
- properties: {
98
- type: {
99
- type: "string",
100
- enum: ["Article", "WebSite", "Organization", "Breadcrumb", "FAQ", "Product", "LocalBusiness", "Video", "Event"],
101
- description: "Type of JSON-LD to create",
102
- },
103
- data: {
104
- type: "object",
105
- description: "Data for the JSON-LD (varies by type)",
106
- },
107
- },
108
- required: ["type", "data"],
109
- },
110
- },
111
- {
112
- name: "mandu_write_seo_file",
113
- description: "Write SEO configuration file (sitemap.ts or robots.ts) to app directory",
114
- inputSchema: {
115
- type: "object",
116
- properties: {
117
- fileType: {
118
- type: "string",
119
- enum: ["sitemap", "robots"],
120
- description: "Type of SEO file to create",
121
- },
122
- config: {
123
- type: "object",
124
- description: "Configuration object for the file",
125
- },
126
- },
127
- required: ["fileType"],
128
- },
129
- },
130
- {
131
- name: "mandu_seo_analyze",
132
- description: "Analyze SEO metadata for common issues and provide recommendations",
133
- inputSchema: {
134
- type: "object",
135
- properties: {
136
- metadata: {
137
- type: "object",
138
- description: "Metadata object to analyze",
139
- },
140
- url: {
141
- type: "string",
142
- description: "Page URL for context",
143
- },
144
- },
145
- required: ["metadata"],
146
- },
147
- },
148
- ];
149
-
150
- export function seoTools(projectRoot: string) {
151
- const paths = getProjectPaths(projectRoot);
152
-
153
- return {
154
- mandu_preview_seo: async (args: Record<string, unknown>) => {
155
- const { metadata } = args as { metadata: Metadata };
156
-
157
- try {
158
- // Create resolved metadata from input
159
- const resolved = await resolveMetadata([metadata]);
160
- const html = renderMetadata(resolved);
161
-
162
- return {
163
- success: true,
164
- html,
165
- resolved: {
166
- title: resolved.title?.absolute,
167
- description: resolved.description,
168
- hasOpenGraph: !!resolved.openGraph,
169
- hasTwitter: !!resolved.twitter,
170
- hasJsonLd: !!resolved.jsonLd && resolved.jsonLd.length > 0,
171
- },
172
- };
173
- } catch (error) {
174
- return {
175
- success: false,
176
- error: error instanceof Error ? error.message : String(error),
177
- };
178
- }
179
- },
180
-
181
- mandu_generate_sitemap_preview: async (args: Record<string, unknown>) => {
182
- const { entries } = args as { entries: Sitemap };
183
-
184
- try {
185
- // Convert date strings to Date objects
186
- const processedEntries = entries.map((entry) => ({
187
- ...entry,
188
- lastModified: entry.lastModified
189
- ? new Date(entry.lastModified as string)
190
- : undefined,
191
- }));
192
-
193
- const xml = renderSitemap(processedEntries);
194
-
195
- return {
196
- success: true,
197
- xml,
198
- entryCount: entries.length,
199
- };
200
- } catch (error) {
201
- return {
202
- success: false,
203
- error: error instanceof Error ? error.message : String(error),
204
- };
205
- }
206
- },
207
-
208
- mandu_generate_robots_preview: async (args: Record<string, unknown>) => {
209
- const { rules, sitemap } = args as {
210
- rules?: RobotsFile["rules"];
211
- sitemap?: string;
212
- };
213
-
214
- try {
215
- const robotsConfig: RobotsFile = rules
216
- ? { rules, sitemap }
217
- : createDefaultRobots(sitemap || "");
218
-
219
- const txt = renderRobots(robotsConfig);
220
-
221
- return {
222
- success: true,
223
- txt,
224
- };
225
- } catch (error) {
226
- return {
227
- success: false,
228
- error: error instanceof Error ? error.message : String(error),
229
- };
230
- }
231
- },
232
-
233
- mandu_create_jsonld: async (args: Record<string, unknown>) => {
234
- const { type, data } = args as { type: string; data: Record<string, unknown> };
235
-
236
- try {
237
- let jsonLd: JsonLd;
238
-
239
- switch (type) {
240
- case "Article":
241
- jsonLd = createArticleJsonLd(data as Parameters<typeof createArticleJsonLd>[0]);
242
- break;
243
- case "WebSite":
244
- jsonLd = createWebSiteJsonLd(data as Parameters<typeof createWebSiteJsonLd>[0]);
245
- break;
246
- case "Organization":
247
- jsonLd = createOrganizationJsonLd(data as Parameters<typeof createOrganizationJsonLd>[0]);
248
- break;
249
- case "Breadcrumb":
250
- jsonLd = createBreadcrumbJsonLd(data as Array<{ name: string; url: string }>);
251
- break;
252
- case "FAQ":
253
- jsonLd = createFAQJsonLd(data as Array<{ question: string; answer: string }>);
254
- break;
255
- case "Product":
256
- jsonLd = createProductJsonLd(data as Parameters<typeof createProductJsonLd>[0]);
257
- break;
258
- case "LocalBusiness":
259
- jsonLd = createLocalBusinessJsonLd(data as Parameters<typeof createLocalBusinessJsonLd>[0]);
260
- break;
261
- case "Video":
262
- jsonLd = createVideoJsonLd(data as Parameters<typeof createVideoJsonLd>[0]);
263
- break;
264
- case "Event":
265
- jsonLd = createEventJsonLd(data as Parameters<typeof createEventJsonLd>[0]);
266
- break;
267
- default:
268
- return {
269
- success: false,
270
- error: `Unknown JSON-LD type: ${type}`,
271
- };
272
- }
273
-
274
- return {
275
- success: true,
276
- jsonLd,
277
- script: `<script type="application/ld+json">${JSON.stringify(jsonLd, null, 2)}</script>`,
278
- };
279
- } catch (error) {
280
- return {
281
- success: false,
282
- error: error instanceof Error ? error.message : String(error),
283
- };
284
- }
285
- },
286
-
287
- mandu_write_seo_file: async (args: Record<string, unknown>) => {
288
- const { fileType, config } = args as {
289
- fileType: "sitemap" | "robots";
290
- config?: Record<string, unknown>;
291
- };
292
-
293
- try {
294
- const appDir = path.join(projectRoot, "app");
295
-
296
- // Ensure app directory exists
297
- if (!fs.existsSync(appDir)) {
298
- fs.mkdirSync(appDir, { recursive: true });
299
- }
300
-
301
- let filePath: string;
302
- let content: string;
303
-
304
- if (fileType === "sitemap") {
305
- filePath = path.join(appDir, "sitemap.ts");
306
- content = `import type { Sitemap } from '@mandujs/core'
307
-
308
- export default function sitemap(): Sitemap {
309
- return [
310
- {
311
- url: 'https://example.com',
312
- lastModified: new Date(),
313
- changeFrequency: 'daily',
314
- priority: 1.0,
315
- },
316
- // Add more entries here
317
- ]
318
- }
319
- `;
320
- } else {
321
- filePath = path.join(appDir, "robots.ts");
322
- content = `import type { RobotsFile } from '@mandujs/core'
323
-
324
- export default function robots(): RobotsFile {
325
- return {
326
- rules: {
327
- userAgent: '*',
328
- allow: '/',
329
- disallow: ['/admin', '/private'],
330
- },
331
- sitemap: 'https://example.com/sitemap.xml',
332
- }
333
- }
334
- `;
335
- }
336
-
337
- fs.writeFileSync(filePath, content, "utf-8");
338
-
339
- return {
340
- success: true,
341
- filePath,
342
- message: `Created ${fileType}.ts at ${filePath}`,
343
- };
344
- } catch (error) {
345
- return {
346
- success: false,
347
- error: error instanceof Error ? error.message : String(error),
348
- };
349
- }
350
- },
351
-
352
- mandu_seo_analyze: async (args: Record<string, unknown>) => {
353
- const { metadata, url } = args as { metadata: Metadata; url?: string };
354
-
355
- const issues: Array<{ severity: "error" | "warning" | "info"; message: string }> = [];
356
- const recommendations: string[] = [];
357
-
358
- // Title checks
359
- if (!metadata.title) {
360
- issues.push({ severity: "error", message: "Missing title" });
361
- } else if (typeof metadata.title === "string") {
362
- if (metadata.title.length < 10) {
363
- issues.push({ severity: "warning", message: "Title is too short (< 10 chars)" });
364
- } else if (metadata.title.length > 60) {
365
- issues.push({ severity: "warning", message: "Title is too long (> 60 chars)" });
366
- }
367
- }
368
-
369
- // Description checks
370
- if (!metadata.description) {
371
- issues.push({ severity: "error", message: "Missing description" });
372
- } else if (metadata.description.length < 50) {
373
- issues.push({ severity: "warning", message: "Description is too short (< 50 chars)" });
374
- } else if (metadata.description.length > 160) {
375
- issues.push({ severity: "warning", message: "Description is too long (> 160 chars)" });
376
- }
377
-
378
- // Open Graph checks
379
- if (!metadata.openGraph) {
380
- issues.push({ severity: "warning", message: "Missing Open Graph metadata" });
381
- recommendations.push("Add openGraph with title, description, and images for better social sharing");
382
- } else {
383
- if (!metadata.openGraph.images) {
384
- issues.push({ severity: "warning", message: "Missing Open Graph image" });
385
- }
386
- }
387
-
388
- // Twitter checks
389
- if (!metadata.twitter) {
390
- issues.push({ severity: "info", message: "Missing Twitter Card metadata" });
391
- recommendations.push("Add twitter card metadata for Twitter sharing");
392
- }
393
-
394
- // JSON-LD checks
395
- if (!metadata.jsonLd) {
396
- recommendations.push("Add JSON-LD structured data for rich search results");
397
- }
398
-
399
- // Viewport check
400
- if (!metadata.viewport) {
401
- recommendations.push("Add viewport meta for mobile optimization");
402
- }
403
-
404
- // Calculate score
405
- const errorCount = issues.filter((i) => i.severity === "error").length;
406
- const warningCount = issues.filter((i) => i.severity === "warning").length;
407
- const score = Math.max(0, 100 - errorCount * 20 - warningCount * 10);
408
-
409
- return {
410
- score,
411
- issues,
412
- recommendations,
413
- summary: `SEO Score: ${score}/100 (${errorCount} errors, ${warningCount} warnings)`,
414
- };
415
- },
416
- };
417
- }
1
+ import type { Tool } from "@modelcontextprotocol/sdk/types.js";
2
+ import {
3
+ renderMetadata,
4
+ createDefaultMetadata,
5
+ resolveMetadata,
6
+ renderSitemap,
7
+ renderRobots,
8
+ createDefaultRobots,
9
+ createArticleJsonLd,
10
+ createBreadcrumbJsonLd,
11
+ createFAQJsonLd,
12
+ createProductJsonLd,
13
+ createWebSiteJsonLd,
14
+ createOrganizationJsonLd,
15
+ createLocalBusinessJsonLd,
16
+ createVideoJsonLd,
17
+ createEventJsonLd,
18
+ type Metadata,
19
+ type Sitemap,
20
+ type RobotsFile,
21
+ type JsonLd,
22
+ } from "@mandujs/core";
23
+ import { getProjectPaths, readJsonFile, writeJsonFile } from "../utils/project.js";
24
+ import * as fs from "fs";
25
+ import * as path from "path";
26
+
27
+ export const seoToolDefinitions: Tool[] = [
28
+ {
29
+ name: "mandu_preview_seo",
30
+ description: "Preview rendered SEO HTML for given metadata. Useful for testing metadata before applying.",
31
+ inputSchema: {
32
+ type: "object",
33
+ properties: {
34
+ metadata: {
35
+ type: "object",
36
+ description: "Metadata object to render (title, description, openGraph, twitter, etc.)",
37
+ },
38
+ },
39
+ required: ["metadata"],
40
+ },
41
+ },
42
+ {
43
+ name: "mandu_generate_sitemap_preview",
44
+ description: "Generate sitemap.xml preview from entries",
45
+ inputSchema: {
46
+ type: "object",
47
+ properties: {
48
+ entries: {
49
+ type: "array",
50
+ description: "Array of sitemap entries with url, lastModified, changeFrequency, priority",
51
+ items: {
52
+ type: "object",
53
+ properties: {
54
+ url: { type: "string", description: "Page URL" },
55
+ lastModified: { type: "string", description: "Last modified date (ISO string)" },
56
+ changeFrequency: {
57
+ type: "string",
58
+ enum: ["always", "hourly", "daily", "weekly", "monthly", "yearly", "never"],
59
+ },
60
+ priority: { type: "number", description: "Priority 0.0 to 1.0" },
61
+ images: {
62
+ type: "array",
63
+ items: { type: "string" },
64
+ description: "Image URLs for this page",
65
+ },
66
+ },
67
+ required: ["url"],
68
+ },
69
+ },
70
+ },
71
+ required: ["entries"],
72
+ },
73
+ },
74
+ {
75
+ name: "mandu_generate_robots_preview",
76
+ description: "Generate robots.txt preview from configuration",
77
+ inputSchema: {
78
+ type: "object",
79
+ properties: {
80
+ rules: {
81
+ type: "object",
82
+ description: "Robots rules (userAgent, allow, disallow, crawlDelay)",
83
+ },
84
+ sitemap: {
85
+ type: "string",
86
+ description: "Sitemap URL",
87
+ },
88
+ },
89
+ required: [],
90
+ },
91
+ },
92
+ {
93
+ name: "mandu_create_jsonld",
94
+ description: "Create JSON-LD structured data for SEO. Supports Article, WebSite, Organization, Breadcrumb, FAQ, Product, LocalBusiness, Video, Event types.",
95
+ inputSchema: {
96
+ type: "object",
97
+ properties: {
98
+ type: {
99
+ type: "string",
100
+ enum: ["Article", "WebSite", "Organization", "Breadcrumb", "FAQ", "Product", "LocalBusiness", "Video", "Event"],
101
+ description: "Type of JSON-LD to create",
102
+ },
103
+ data: {
104
+ type: "object",
105
+ description: "Data for the JSON-LD (varies by type)",
106
+ },
107
+ },
108
+ required: ["type", "data"],
109
+ },
110
+ },
111
+ {
112
+ name: "mandu_write_seo_file",
113
+ description: "Write SEO configuration file (sitemap.ts or robots.ts) to app directory",
114
+ inputSchema: {
115
+ type: "object",
116
+ properties: {
117
+ fileType: {
118
+ type: "string",
119
+ enum: ["sitemap", "robots"],
120
+ description: "Type of SEO file to create",
121
+ },
122
+ config: {
123
+ type: "object",
124
+ description: "Configuration object for the file",
125
+ },
126
+ },
127
+ required: ["fileType"],
128
+ },
129
+ },
130
+ {
131
+ name: "mandu_seo_analyze",
132
+ description: "Analyze SEO metadata for common issues and provide recommendations",
133
+ inputSchema: {
134
+ type: "object",
135
+ properties: {
136
+ metadata: {
137
+ type: "object",
138
+ description: "Metadata object to analyze",
139
+ },
140
+ url: {
141
+ type: "string",
142
+ description: "Page URL for context",
143
+ },
144
+ },
145
+ required: ["metadata"],
146
+ },
147
+ },
148
+ ];
149
+
150
+ export function seoTools(projectRoot: string) {
151
+ const paths = getProjectPaths(projectRoot);
152
+
153
+ return {
154
+ mandu_preview_seo: async (args: Record<string, unknown>) => {
155
+ const { metadata } = args as { metadata: Metadata };
156
+
157
+ try {
158
+ // Create resolved metadata from input
159
+ const resolved = await resolveMetadata([metadata]);
160
+ const html = renderMetadata(resolved);
161
+
162
+ return {
163
+ success: true,
164
+ html,
165
+ resolved: {
166
+ title: resolved.title?.absolute,
167
+ description: resolved.description,
168
+ hasOpenGraph: !!resolved.openGraph,
169
+ hasTwitter: !!resolved.twitter,
170
+ hasJsonLd: !!resolved.jsonLd && resolved.jsonLd.length > 0,
171
+ },
172
+ };
173
+ } catch (error) {
174
+ return {
175
+ success: false,
176
+ error: error instanceof Error ? error.message : String(error),
177
+ };
178
+ }
179
+ },
180
+
181
+ mandu_generate_sitemap_preview: async (args: Record<string, unknown>) => {
182
+ const { entries } = args as { entries: Sitemap };
183
+
184
+ try {
185
+ // Convert date strings to Date objects
186
+ const processedEntries = entries.map((entry) => ({
187
+ ...entry,
188
+ lastModified: entry.lastModified
189
+ ? new Date(entry.lastModified as string)
190
+ : undefined,
191
+ }));
192
+
193
+ const xml = renderSitemap(processedEntries);
194
+
195
+ return {
196
+ success: true,
197
+ xml,
198
+ entryCount: entries.length,
199
+ };
200
+ } catch (error) {
201
+ return {
202
+ success: false,
203
+ error: error instanceof Error ? error.message : String(error),
204
+ };
205
+ }
206
+ },
207
+
208
+ mandu_generate_robots_preview: async (args: Record<string, unknown>) => {
209
+ const { rules, sitemap } = args as {
210
+ rules?: RobotsFile["rules"];
211
+ sitemap?: string;
212
+ };
213
+
214
+ try {
215
+ const robotsConfig: RobotsFile = rules
216
+ ? { rules, sitemap }
217
+ : createDefaultRobots(sitemap || "");
218
+
219
+ const txt = renderRobots(robotsConfig);
220
+
221
+ return {
222
+ success: true,
223
+ txt,
224
+ };
225
+ } catch (error) {
226
+ return {
227
+ success: false,
228
+ error: error instanceof Error ? error.message : String(error),
229
+ };
230
+ }
231
+ },
232
+
233
+ mandu_create_jsonld: async (args: Record<string, unknown>) => {
234
+ const { type, data } = args as { type: string; data: Record<string, unknown> };
235
+
236
+ try {
237
+ let jsonLd: JsonLd;
238
+
239
+ switch (type) {
240
+ case "Article":
241
+ jsonLd = createArticleJsonLd(data as Parameters<typeof createArticleJsonLd>[0]);
242
+ break;
243
+ case "WebSite":
244
+ jsonLd = createWebSiteJsonLd(data as Parameters<typeof createWebSiteJsonLd>[0]);
245
+ break;
246
+ case "Organization":
247
+ jsonLd = createOrganizationJsonLd(data as Parameters<typeof createOrganizationJsonLd>[0]);
248
+ break;
249
+ case "Breadcrumb":
250
+ jsonLd = createBreadcrumbJsonLd(data as Array<{ name: string; url: string }>);
251
+ break;
252
+ case "FAQ":
253
+ jsonLd = createFAQJsonLd(data as Array<{ question: string; answer: string }>);
254
+ break;
255
+ case "Product":
256
+ jsonLd = createProductJsonLd(data as Parameters<typeof createProductJsonLd>[0]);
257
+ break;
258
+ case "LocalBusiness":
259
+ jsonLd = createLocalBusinessJsonLd(data as Parameters<typeof createLocalBusinessJsonLd>[0]);
260
+ break;
261
+ case "Video":
262
+ jsonLd = createVideoJsonLd(data as Parameters<typeof createVideoJsonLd>[0]);
263
+ break;
264
+ case "Event":
265
+ jsonLd = createEventJsonLd(data as Parameters<typeof createEventJsonLd>[0]);
266
+ break;
267
+ default:
268
+ return {
269
+ success: false,
270
+ error: `Unknown JSON-LD type: ${type}`,
271
+ };
272
+ }
273
+
274
+ return {
275
+ success: true,
276
+ jsonLd,
277
+ script: `<script type="application/ld+json">${JSON.stringify(jsonLd, null, 2)}</script>`,
278
+ };
279
+ } catch (error) {
280
+ return {
281
+ success: false,
282
+ error: error instanceof Error ? error.message : String(error),
283
+ };
284
+ }
285
+ },
286
+
287
+ mandu_write_seo_file: async (args: Record<string, unknown>) => {
288
+ const { fileType, config } = args as {
289
+ fileType: "sitemap" | "robots";
290
+ config?: Record<string, unknown>;
291
+ };
292
+
293
+ try {
294
+ const appDir = path.join(projectRoot, "app");
295
+
296
+ // Ensure app directory exists
297
+ if (!fs.existsSync(appDir)) {
298
+ fs.mkdirSync(appDir, { recursive: true });
299
+ }
300
+
301
+ let filePath: string;
302
+ let content: string;
303
+
304
+ if (fileType === "sitemap") {
305
+ filePath = path.join(appDir, "sitemap.ts");
306
+ content = `import type { Sitemap } from '@mandujs/core'
307
+
308
+ export default function sitemap(): Sitemap {
309
+ return [
310
+ {
311
+ url: 'https://example.com',
312
+ lastModified: new Date(),
313
+ changeFrequency: 'daily',
314
+ priority: 1.0,
315
+ },
316
+ // Add more entries here
317
+ ]
318
+ }
319
+ `;
320
+ } else {
321
+ filePath = path.join(appDir, "robots.ts");
322
+ content = `import type { RobotsFile } from '@mandujs/core'
323
+
324
+ export default function robots(): RobotsFile {
325
+ return {
326
+ rules: {
327
+ userAgent: '*',
328
+ allow: '/',
329
+ disallow: ['/admin', '/private'],
330
+ },
331
+ sitemap: 'https://example.com/sitemap.xml',
332
+ }
333
+ }
334
+ `;
335
+ }
336
+
337
+ fs.writeFileSync(filePath, content, "utf-8");
338
+
339
+ return {
340
+ success: true,
341
+ filePath,
342
+ message: `Created ${fileType}.ts at ${filePath}`,
343
+ };
344
+ } catch (error) {
345
+ return {
346
+ success: false,
347
+ error: error instanceof Error ? error.message : String(error),
348
+ };
349
+ }
350
+ },
351
+
352
+ mandu_seo_analyze: async (args: Record<string, unknown>) => {
353
+ const { metadata, url } = args as { metadata: Metadata; url?: string };
354
+
355
+ const issues: Array<{ severity: "error" | "warning" | "info"; message: string }> = [];
356
+ const recommendations: string[] = [];
357
+
358
+ // Title checks
359
+ if (!metadata.title) {
360
+ issues.push({ severity: "error", message: "Missing title" });
361
+ } else if (typeof metadata.title === "string") {
362
+ if (metadata.title.length < 10) {
363
+ issues.push({ severity: "warning", message: "Title is too short (< 10 chars)" });
364
+ } else if (metadata.title.length > 60) {
365
+ issues.push({ severity: "warning", message: "Title is too long (> 60 chars)" });
366
+ }
367
+ }
368
+
369
+ // Description checks
370
+ if (!metadata.description) {
371
+ issues.push({ severity: "error", message: "Missing description" });
372
+ } else if (metadata.description.length < 50) {
373
+ issues.push({ severity: "warning", message: "Description is too short (< 50 chars)" });
374
+ } else if (metadata.description.length > 160) {
375
+ issues.push({ severity: "warning", message: "Description is too long (> 160 chars)" });
376
+ }
377
+
378
+ // Open Graph checks
379
+ if (!metadata.openGraph) {
380
+ issues.push({ severity: "warning", message: "Missing Open Graph metadata" });
381
+ recommendations.push("Add openGraph with title, description, and images for better social sharing");
382
+ } else {
383
+ if (!metadata.openGraph.images) {
384
+ issues.push({ severity: "warning", message: "Missing Open Graph image" });
385
+ }
386
+ }
387
+
388
+ // Twitter checks
389
+ if (!metadata.twitter) {
390
+ issues.push({ severity: "info", message: "Missing Twitter Card metadata" });
391
+ recommendations.push("Add twitter card metadata for Twitter sharing");
392
+ }
393
+
394
+ // JSON-LD checks
395
+ if (!metadata.jsonLd) {
396
+ recommendations.push("Add JSON-LD structured data for rich search results");
397
+ }
398
+
399
+ // Viewport check
400
+ if (!metadata.viewport) {
401
+ recommendations.push("Add viewport meta for mobile optimization");
402
+ }
403
+
404
+ // Calculate score
405
+ const errorCount = issues.filter((i) => i.severity === "error").length;
406
+ const warningCount = issues.filter((i) => i.severity === "warning").length;
407
+ const score = Math.max(0, 100 - errorCount * 20 - warningCount * 10);
408
+
409
+ return {
410
+ score,
411
+ issues,
412
+ recommendations,
413
+ summary: `SEO Score: ${score}/100 (${errorCount} errors, ${warningCount} warnings)`,
414
+ };
415
+ },
416
+ };
417
+ }