@webjsdev/mcp 0.1.7 → 0.1.9

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 (37) hide show
  1. package/README.md +1 -1
  2. package/package.json +4 -1
  3. package/resources/AGENTS.md +86 -72
  4. package/resources/SKILL.md +226 -0
  5. package/resources/references/auth-and-sessions.md +220 -0
  6. package/resources/references/built-ins.md +200 -0
  7. package/resources/references/client-router-and-streaming.md +204 -0
  8. package/resources/references/components.md +167 -0
  9. package/resources/references/data-and-actions.md +187 -0
  10. package/resources/references/muscle-memory-gotchas.md +170 -0
  11. package/resources/references/optimistic-ui.md +128 -0
  12. package/resources/references/routing-and-pages.md +158 -0
  13. package/resources/references/runtime.md +80 -0
  14. package/resources/references/service-worker.md +78 -0
  15. package/resources/references/styling.md +123 -0
  16. package/resources/references/testing.md +125 -0
  17. package/resources/references/typescript.md +148 -0
  18. package/src/mcp-docs.js +27 -14
  19. package/src/mcp-source.js +1 -1
  20. package/src/mcp.js +9 -47
  21. package/src/routes-report.js +90 -0
  22. package/resources/agent-docs/advanced.md +0 -1334
  23. package/resources/agent-docs/built-ins.md +0 -389
  24. package/resources/agent-docs/components-shadowing.md +0 -87
  25. package/resources/agent-docs/components.md +0 -734
  26. package/resources/agent-docs/configuration.md +0 -284
  27. package/resources/agent-docs/framework-dev.md +0 -73
  28. package/resources/agent-docs/lit-muscle-memory-gotchas.md +0 -470
  29. package/resources/agent-docs/metadata.md +0 -334
  30. package/resources/agent-docs/orm.md +0 -198
  31. package/resources/agent-docs/recipes.md +0 -664
  32. package/resources/agent-docs/runtime.md +0 -65
  33. package/resources/agent-docs/service-worker.md +0 -104
  34. package/resources/agent-docs/styling.md +0 -279
  35. package/resources/agent-docs/testing.md +0 -479
  36. package/resources/agent-docs/types-and-mutations.md +0 -171
  37. package/resources/agent-docs/typescript.md +0 -402
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Shared JSON projector for the app route table (#975).
3
+ *
4
+ * `webjs routes --json` and the `webjs mcp` server's `list_routes` tool BOTH
5
+ * return the identical shape, so the projection lives here once (the same
6
+ * pattern as `check-report.js` for `check --json` / the MCP `check` tool). The
7
+ * input is the raw `RouteTable` from `buildRouteTable(appDir)` (the ONE route
8
+ * walker, reused, never re-implemented); the output is a stable, agent-friendly
9
+ * `{ pages, apis }` shape.
10
+ *
11
+ * This module is a LEAF: it imports only `node:path` and receives the two
12
+ * effectful dependencies it needs (`readFile` to read a `route.{js,ts}` file's
13
+ * source, `extractRouteMethods` to lexically pull its HTTP-verb exports) as
14
+ * injected arguments, the same dependency-injection style the MCP tool runners
15
+ * already use. That keeps it free of any `@webjsdev/mcp` main-entry import (so
16
+ * the CLI can pull just this projector without loading the MCP server) and free
17
+ * of a cycle with `mcp.js`.
18
+ *
19
+ * @module routes-report
20
+ */
21
+
22
+ import { relative } from 'node:path';
23
+
24
+ /**
25
+ * The literal URL path for a page/api directory: `blog/[slug]` -> `/blog/[slug]`,
26
+ * the root `.` -> `/`. Route groups `(group)` and `_private` segments drop, the
27
+ * same normalization `buildRouteTable` uses for matching.
28
+ *
29
+ * @param {string} routeDir POSIX-style, `.` for the app root.
30
+ * @returns {string}
31
+ */
32
+ export function routePathFromDir(routeDir) {
33
+ if (!routeDir || routeDir === '.') return '/';
34
+ const segs = routeDir
35
+ .split('/')
36
+ .filter((s) => !(s.startsWith('(') && s.endsWith(')')) && !s.startsWith('_'));
37
+ return segs.length ? '/' + segs.join('/') : '/';
38
+ }
39
+
40
+ /**
41
+ * @typedef {{ path: string, file: string, dynamic?: boolean, params?: string[] }} PageRouteReport
42
+ * @typedef {{ path: string, file: string, methods: string[] }} ApiRouteReport
43
+ * @typedef {{ pages: PageRouteReport[], apis: ApiRouteReport[] }} RoutesReport
44
+ */
45
+
46
+ /**
47
+ * Project a `RouteTable` into the structured `{ pages, apis }` report shared by
48
+ * `webjs routes --json` and the MCP `list_routes` tool. Pure over its inputs
49
+ * (given the same table + deps it produces the same output); the only I/O is
50
+ * the injected `readFile` reading each `route.{js,ts}` source to extract its
51
+ * methods. A `route.{js,ts}` that cannot be read degrades to an empty method
52
+ * list rather than throwing, so one unreadable file never sinks the whole
53
+ * report.
54
+ *
55
+ * @param {{ pages: any[], apis: any[] }} table the `buildRouteTable(appDir)` result
56
+ * @param {{
57
+ * appDir: string,
58
+ * readFile: (path: string, enc: string) => Promise<string>,
59
+ * extractRouteMethods: (src: string) => string[],
60
+ * }} deps
61
+ * @returns {Promise<RoutesReport>}
62
+ */
63
+ export async function projectRoutes(table, { appDir, readFile, extractRouteMethods }) {
64
+ const pages = table.pages.map((r) => {
65
+ /** @type {PageRouteReport} */
66
+ const out = {
67
+ path: routePathFromDir(r.routeDir),
68
+ file: relative(appDir, r.file),
69
+ };
70
+ if (r.paramNames && r.paramNames.length) {
71
+ out.dynamic = true;
72
+ out.params = r.paramNames;
73
+ }
74
+ return out;
75
+ });
76
+ const apis = await Promise.all(
77
+ table.apis.map(async (r) => {
78
+ let methods = [];
79
+ try {
80
+ methods = extractRouteMethods(await readFile(r.file, 'utf8'));
81
+ } catch {}
82
+ return {
83
+ path: routePathFromDir(r.routeDir),
84
+ file: relative(appDir, r.file),
85
+ methods,
86
+ };
87
+ }),
88
+ );
89
+ return { pages, apis };
90
+ }