@wordpress/design-system-mcp 0.15.0 → 0.17.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 (46) hide show
  1. package/README.md +15 -6
  2. package/build-module/data.mjs +81 -50
  3. package/build-module/data.mjs.map +1 -7
  4. package/build-module/find-each.mjs +25 -0
  5. package/build-module/find-each.mjs.map +1 -0
  6. package/build-module/format.mjs +65 -53
  7. package/build-module/format.mjs.map +1 -7
  8. package/build-module/index.mjs +25 -23
  9. package/build-module/index.mjs.map +1 -7
  10. package/build-module/parse-components.mjs +135 -82
  11. package/build-module/parse-components.mjs.map +1 -7
  12. package/build-module/parse-patterns.mjs +44 -0
  13. package/build-module/parse-patterns.mjs.map +1 -0
  14. package/build-module/tools/get-component-details.mjs +32 -66
  15. package/build-module/tools/get-component-details.mjs.map +1 -7
  16. package/build-module/tools/get-components.mjs +20 -26
  17. package/build-module/tools/get-components.mjs.map +1 -7
  18. package/build-module/tools/get-design-tokens.mjs +19 -26
  19. package/build-module/tools/get-design-tokens.mjs.map +1 -7
  20. package/build-module/tools/get-pattern-details.mjs +38 -0
  21. package/build-module/tools/get-pattern-details.mjs.map +1 -0
  22. package/build-module/tools/get-patterns.mjs +23 -0
  23. package/build-module/tools/get-patterns.mjs.map +1 -0
  24. package/build-module/tools/index.mjs +18 -10
  25. package/build-module/tools/index.mjs.map +1 -7
  26. package/build-module/types.mjs +0 -1
  27. package/build-types/data.d.ts +14 -1
  28. package/build-types/data.d.ts.map +1 -1
  29. package/build-types/find-each.d.ts +13 -0
  30. package/build-types/find-each.d.ts.map +1 -0
  31. package/build-types/format.d.ts +8 -1
  32. package/build-types/format.d.ts.map +1 -1
  33. package/build-types/index.d.ts +1 -0
  34. package/build-types/index.d.ts.map +1 -1
  35. package/build-types/parse-patterns.d.ts +10 -0
  36. package/build-types/parse-patterns.d.ts.map +1 -0
  37. package/build-types/tools/get-component-details.d.ts.map +1 -1
  38. package/build-types/tools/get-pattern-details.d.ts +26 -0
  39. package/build-types/tools/get-pattern-details.d.ts.map +1 -0
  40. package/build-types/tools/get-patterns.d.ts +8 -0
  41. package/build-types/tools/get-patterns.d.ts.map +1 -0
  42. package/build-types/tools/index.d.ts.map +1 -1
  43. package/build-types/types.d.ts +11 -0
  44. package/build-types/types.d.ts.map +1 -1
  45. package/package.json +3 -3
  46. package/build-module/types.mjs.map +0 -7
@@ -1,96 +1,149 @@
1
1
  // packages/design-system-mcp/src/parse-components.ts
2
- var EXPORT_ALIASES = {
3
- "@wordpress/components:ConfirmDialog": "__experimentalConfirmDialog",
4
- "@wordpress/components:InputControl": "__experimentalInputControl",
5
- "@wordpress/components:ItemGroup": "__experimentalItemGroup",
6
- "@wordpress/components:ToggleGroupControl": "__experimentalToggleGroupControl",
7
- "@wordpress/components:TreeGrid": "__experimentalTreeGrid",
8
- "@wordpress/components:Truncate": "__experimentalTruncate"
2
+ /**
3
+ * Mapping of canonical name to actual exported identifier, keyed by
4
+ * `package:name`. A package's actual exported identifier may be different from
5
+ * the canonical name in the internal implementation that's known to Storybook.
6
+ *
7
+ * Ideally we could derive this from the package's source code, but MCP
8
+ * consumers aren't guaranteed to have these packages installed. Since this
9
+ * is a legacy convention, we expect this list will only ever shrink over time
10
+ * and can eventually be removed.
11
+ */
12
+ const EXPORT_ALIASES = {
13
+ "@wordpress/components:ConfirmDialog": "__experimentalConfirmDialog",
14
+ "@wordpress/components:InputControl": "__experimentalInputControl",
15
+ "@wordpress/components:ItemGroup": "__experimentalItemGroup",
16
+ "@wordpress/components:ToggleGroupControl": "__experimentalToggleGroupControl",
17
+ "@wordpress/components:TreeGrid": "__experimentalTreeGrid",
18
+ "@wordpress/components:Truncate": "__experimentalTruncate"
9
19
  };
20
+ /**
21
+ * Build the import statement a consumer should use to bring a component into
22
+ * scope under its canonical name. For aliased components, emit an `as` rename
23
+ * so that subsequent code samples (which reference the canonical name) resolve
24
+ * against the actual export.
25
+ *
26
+ * @param name - The canonical component name.
27
+ * @param packageName - The npm package name.
28
+ * @return The import statement as a single-line string.
29
+ */
10
30
  function buildImportStatement(name, packageName) {
11
- const exported = EXPORT_ALIASES[`${packageName}:${name}`];
12
- return exported ? `import { ${exported} as ${name} } from '${packageName}';` : `import { ${name} } from '${packageName}';`;
31
+ const exported = EXPORT_ALIASES[`${packageName}:${name}`];
32
+ return exported ? `import { ${exported} as ${name} } from '${packageName}';` : `import { ${name} } from '${packageName}';`;
13
33
  }
34
+ /**
35
+ * Derive the npm package name from the story file path.
36
+ *
37
+ * Manifest paths look like `../packages/<dir>/src/.../index.story.tsx`. We
38
+ * extract `<dir>` and prepend the `@wordpress/` npm namespace. Curation of
39
+ * which components appear in the manifest is handled upstream via Storybook
40
+ * tags, so this only needs to recognize package-shaped paths.
41
+ *
42
+ * @param storyPath - The story file path from the manifest.
43
+ * @return The npm package name, or null for paths outside `packages/*`.
44
+ */
14
45
  function packageNameFromPath(storyPath) {
15
- const match = storyPath.match(/\.\.\/packages\/([^/]+)\//);
16
- return match ? `@wordpress/${match[1]}` : null;
46
+ const match = storyPath.match(/\.\.\/packages\/([^/]+)\//);
47
+ return match ? `@wordpress/${match[1]}` : null;
17
48
  }
49
+ /**
50
+ * For components exported as a namespace (e.g. `AlertDialog`, with members
51
+ * `AlertDialog.Root`, `AlertDialog.Trigger`, etc.), the manifest lists the
52
+ * primary entry under a dotted name like `AlertDialog.Root`. The canonical
53
+ * name we expose is the top-level identifier a consumer actually imports,
54
+ * which is the portion before the first dot. For simple components (e.g.
55
+ * `Button`), this is a no-op.
56
+ *
57
+ * @param name - The component name from the manifest.
58
+ * @return The top-level importable identifier.
59
+ */
18
60
  function canonicalComponentName(name) {
19
- return name.split(".", 1)[0];
61
+ return name.split(".", 1)[0];
20
62
  }
63
+ /**
64
+ * Parse props from a component's `reactComponentMeta` data, filtering out
65
+ * deprecated and ignored props.
66
+ *
67
+ * @param rawProps - The component meta props record.
68
+ * @return Parsed props with deprecated entries removed.
69
+ */
21
70
  function parseProps(rawProps) {
22
- return Object.entries(rawProps).filter(([, propInfo]) => {
23
- const description = (propInfo.description || "").toLowerCase();
24
- return !description.includes("@deprecated") && !description.includes("@ignore");
25
- }).map(([propName, propInfo]) => ({
26
- name: propName,
27
- // Prefer `raw` when present, as it carries the source-authored type
28
- // expression a consumer could use directly. Primitives emit only
29
- // `name`, so fall back if `raw` is not present.
30
- type: propInfo.type?.raw || propInfo.type?.name || "unknown",
31
- required: propInfo.required || false,
32
- description: propInfo.description || "",
33
- defaultValue: propInfo.defaultValue?.value ?? null
34
- }));
71
+ return Object.entries(rawProps).filter(([, propInfo]) => {
72
+ const description = (propInfo.description || "").toLowerCase();
73
+ return !description.includes("@deprecated") && !description.includes("@ignore");
74
+ }).map(([propName, propInfo]) => ({
75
+ name: propName,
76
+ type: propInfo.type?.raw || propInfo.type?.name || "unknown",
77
+ required: propInfo.required || false,
78
+ description: propInfo.description || "",
79
+ defaultValue: propInfo.defaultValue?.value ?? null
80
+ }));
35
81
  }
82
+ /**
83
+ * Parse manifest components into a flat list sorted alphabetically by name.
84
+ * When a component is defined across multiple story files (e.g. a companion
85
+ * file documenting a specific aspect), it is collapsed to a single entry keyed
86
+ * by its canonical name and package.
87
+ *
88
+ * @param components - The manifest components record.
89
+ * @return Flat list of components derived from the manifest.
90
+ */
36
91
  function parseComponents(components) {
37
- const byKey = /* @__PURE__ */ new Map();
38
- for (const component of Object.values(components)) {
39
- const packageName = packageNameFromPath(component.path);
40
- if (!packageName) {
41
- continue;
42
- }
43
- const name = canonicalComponentName(component.name);
44
- const key = `${packageName}:${name}`;
45
- const existing = byKey.get(key);
46
- const description = component.description || "";
47
- if (!existing) {
48
- byKey.set(key, { name, description, packageName });
49
- } else {
50
- existing.description ||= description;
51
- }
52
- }
53
- return Array.from(byKey.values()).sort(
54
- (a, b) => a.name.localeCompare(b.name)
55
- );
92
+ const byKey = /* @__PURE__ */ new Map();
93
+ for (const component of Object.values(components)) {
94
+ const packageName = packageNameFromPath(component.path);
95
+ if (!packageName) continue;
96
+ const name = canonicalComponentName(component.name);
97
+ const key = `${packageName}:${name}`;
98
+ const existing = byKey.get(key);
99
+ const description = component.description || "";
100
+ if (!existing) byKey.set(key, {
101
+ name,
102
+ description,
103
+ packageName
104
+ });
105
+ else existing.description ||= description;
106
+ }
107
+ return Array.from(byKey.values()).sort((a, b) => a.name.localeCompare(b.name));
56
108
  }
109
+ /**
110
+ * Find a single component by name (case-insensitive) and return its full
111
+ * detail including props and stories. When a component is spread across
112
+ * multiple story files, stories from every contributing file are collected
113
+ * in manifest order. Descriptions and props are also authored on the component
114
+ * itself, so in principle they should be identical across story files; in
115
+ * practice one file may omit them, so we prefer any non-empty value found.
116
+ *
117
+ * @param components - The manifest components record.
118
+ * @param name - The component name to look up.
119
+ * @return The component detail, or null if not found.
120
+ */
57
121
  function parseComponentDetail(components, name) {
58
- let detail = null;
59
- for (const component of Object.values(components)) {
60
- const canonicalName = canonicalComponentName(component.name);
61
- if (canonicalName.toLowerCase() !== name.toLowerCase()) {
62
- continue;
63
- }
64
- const pkg = packageNameFromPath(component.path);
65
- if (!pkg) {
66
- continue;
67
- }
68
- const description = component.description || "";
69
- const props = parseProps(component.reactComponentMeta?.props || {});
70
- const stories = component.stories || [];
71
- if (!detail) {
72
- detail = {
73
- name: canonicalName,
74
- description,
75
- packageName: pkg,
76
- importStatement: buildImportStatement(canonicalName, pkg),
77
- props,
78
- stories: [...stories]
79
- };
80
- } else if (detail.packageName === pkg) {
81
- detail.description ||= description;
82
- if (detail.props.length === 0) {
83
- detail.props = props;
84
- }
85
- detail.stories.push(...stories);
86
- }
87
- }
88
- return detail;
122
+ let detail = null;
123
+ for (const component of Object.values(components)) {
124
+ const canonicalName = canonicalComponentName(component.name);
125
+ if (canonicalName.toLowerCase() !== name.toLowerCase()) continue;
126
+ const pkg = packageNameFromPath(component.path);
127
+ if (!pkg) continue;
128
+ const description = component.description || "";
129
+ const props = parseProps(component.reactComponentMeta?.props || {});
130
+ const stories = component.stories || [];
131
+ if (!detail) detail = {
132
+ name: canonicalName,
133
+ description,
134
+ packageName: pkg,
135
+ importStatement: buildImportStatement(canonicalName, pkg),
136
+ props,
137
+ stories: [...stories]
138
+ };
139
+ else if (detail.packageName === pkg) {
140
+ detail.description ||= description;
141
+ if (detail.props.length === 0) detail.props = props;
142
+ detail.stories.push(...stories);
143
+ }
144
+ }
145
+ return detail;
89
146
  }
90
- export {
91
- packageNameFromPath,
92
- parseComponentDetail,
93
- parseComponents,
94
- parseProps
95
- };
96
- //# sourceMappingURL=parse-components.mjs.map
147
+ export { packageNameFromPath, parseComponentDetail, parseComponents, parseProps };
148
+
149
+ //# sourceMappingURL=parse-components.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/parse-components.ts"],
4
- "sourcesContent": ["import type {\n\tComponent,\n\tComponentDetail,\n\tComponentProp,\n\tManifestComponent,\n} from './types.ts';\n\n/**\n * Mapping of canonical name to actual exported identifier, keyed by\n * `package:name`. A package's actual exported identifier may be different from\n * the canonical name in the internal implementation that's known to Storybook.\n *\n * Ideally we could derive this from the package's source code, but MCP\n * consumers aren't guaranteed to have these packages installed. Since this\n * is a legacy convention, we expect this list will only ever shrink over time\n * and can eventually be removed.\n */\nconst EXPORT_ALIASES: Record< string, string > = {\n\t'@wordpress/components:ConfirmDialog': '__experimentalConfirmDialog',\n\t'@wordpress/components:InputControl': '__experimentalInputControl',\n\t'@wordpress/components:ItemGroup': '__experimentalItemGroup',\n\t'@wordpress/components:ToggleGroupControl':\n\t\t'__experimentalToggleGroupControl',\n\t'@wordpress/components:TreeGrid': '__experimentalTreeGrid',\n\t'@wordpress/components:Truncate': '__experimentalTruncate',\n};\n\n/**\n * Build the import statement a consumer should use to bring a component into\n * scope under its canonical name. For aliased components, emit an `as` rename\n * so that subsequent code samples (which reference the canonical name) resolve\n * against the actual export.\n *\n * @param name - The canonical component name.\n * @param packageName - The npm package name.\n * @return The import statement as a single-line string.\n */\nfunction buildImportStatement( name: string, packageName: string ): string {\n\tconst exported = EXPORT_ALIASES[ `${ packageName }:${ name }` ];\n\treturn exported\n\t\t? `import { ${ exported } as ${ name } } from '${ packageName }';`\n\t\t: `import { ${ name } } from '${ packageName }';`;\n}\n\n/**\n * Derive the npm package name from the story file path.\n *\n * Manifest paths look like `../packages/<dir>/src/.../index.story.tsx`. We\n * extract `<dir>` and prepend the `@wordpress/` npm namespace. Curation of\n * which components appear in the manifest is handled upstream via Storybook\n * tags, so this only needs to recognize package-shaped paths.\n *\n * @param storyPath - The story file path from the manifest.\n * @return The npm package name, or null for paths outside `packages/*`.\n */\nexport function packageNameFromPath( storyPath: string ): string | null {\n\tconst match = storyPath.match( /\\.\\.\\/packages\\/([^/]+)\\// );\n\treturn match ? `@wordpress/${ match[ 1 ] }` : null;\n}\n\n/**\n * For components exported as a namespace (e.g. `AlertDialog`, with members\n * `AlertDialog.Root`, `AlertDialog.Trigger`, etc.), the manifest lists the\n * primary entry under a dotted name like `AlertDialog.Root`. The canonical\n * name we expose is the top-level identifier a consumer actually imports,\n * which is the portion before the first dot. For simple components (e.g.\n * `Button`), this is a no-op.\n *\n * @param name - The component name from the manifest.\n * @return The top-level importable identifier.\n */\nfunction canonicalComponentName( name: string ): string {\n\treturn name.split( '.', 1 )[ 0 ];\n}\n\n/**\n * Parse props from a component's `reactComponentMeta` data, filtering out\n * deprecated and ignored props.\n *\n * @param rawProps - The component meta props record.\n * @return Parsed props with deprecated entries removed.\n */\nexport function parseProps(\n\trawProps: Record<\n\t\tstring,\n\t\t{\n\t\t\trequired?: boolean;\n\t\t\ttype?: { name: string; raw?: string };\n\t\t\tdescription?: string;\n\t\t\tdefaultValue?: { value: string } | null;\n\t\t}\n\t>\n): ComponentProp[] {\n\treturn Object.entries( rawProps )\n\t\t.filter( ( [ , propInfo ] ) => {\n\t\t\tconst description = ( propInfo.description || '' ).toLowerCase();\n\t\t\treturn (\n\t\t\t\t! description.includes( '@deprecated' ) &&\n\t\t\t\t! description.includes( '@ignore' )\n\t\t\t);\n\t\t} )\n\t\t.map( ( [ propName, propInfo ] ) => ( {\n\t\t\tname: propName,\n\t\t\t// Prefer `raw` when present, as it carries the source-authored type\n\t\t\t// expression a consumer could use directly. Primitives emit only\n\t\t\t// `name`, so fall back if `raw` is not present.\n\t\t\ttype: propInfo.type?.raw || propInfo.type?.name || 'unknown',\n\t\t\trequired: propInfo.required || false,\n\t\t\tdescription: propInfo.description || '',\n\t\t\tdefaultValue: propInfo.defaultValue?.value ?? null,\n\t\t} ) );\n}\n\n/**\n * Parse manifest components into a flat list sorted alphabetically by name.\n * When a component is defined across multiple story files (e.g. a companion\n * file documenting a specific aspect), it is collapsed to a single entry keyed\n * by its canonical name and package.\n *\n * @param components - The manifest components record.\n * @return Flat list of components derived from the manifest.\n */\nexport function parseComponents(\n\tcomponents: Record< string, ManifestComponent >\n): Component[] {\n\tconst byKey = new Map< string, Component >();\n\n\tfor ( const component of Object.values( components ) ) {\n\t\tconst packageName = packageNameFromPath( component.path );\n\t\tif ( ! packageName ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst name = canonicalComponentName( component.name );\n\t\tconst key = `${ packageName }:${ name }`;\n\t\tconst existing = byKey.get( key );\n\t\tconst description = component.description || '';\n\n\t\tif ( ! existing ) {\n\t\t\tbyKey.set( key, { name, description, packageName } );\n\t\t} else {\n\t\t\t// Prefer a non-empty description from a later entry over an\n\t\t\t// empty one from the first.\n\t\t\texisting.description ||= description;\n\t\t}\n\t}\n\n\treturn Array.from( byKey.values() ).sort( ( a, b ) =>\n\t\ta.name.localeCompare( b.name )\n\t);\n}\n\n/**\n * Find a single component by name (case-insensitive) and return its full\n * detail including props and stories. When a component is spread across\n * multiple story files, stories from every contributing file are collected\n * in manifest order. Descriptions and props are also authored on the component\n * itself, so in principle they should be identical across story files; in\n * practice one file may omit them, so we prefer any non-empty value found.\n *\n * @param components - The manifest components record.\n * @param name - The component name to look up.\n * @return The component detail, or null if not found.\n */\nexport function parseComponentDetail(\n\tcomponents: Record< string, ManifestComponent >,\n\tname: string\n): ComponentDetail | null {\n\tlet detail: ComponentDetail | null = null;\n\n\tfor ( const component of Object.values( components ) ) {\n\t\tconst canonicalName = canonicalComponentName( component.name );\n\t\tif ( canonicalName.toLowerCase() !== name.toLowerCase() ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst pkg = packageNameFromPath( component.path );\n\t\tif ( ! pkg ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst description = component.description || '';\n\t\tconst props = parseProps( component.reactComponentMeta?.props || {} );\n\t\tconst stories = component.stories || [];\n\n\t\tif ( ! detail ) {\n\t\t\tdetail = {\n\t\t\t\tname: canonicalName,\n\t\t\t\tdescription,\n\t\t\t\tpackageName: pkg,\n\t\t\t\timportStatement: buildImportStatement( canonicalName, pkg ),\n\t\t\t\tprops,\n\t\t\t\tstories: [ ...stories ],\n\t\t\t};\n\t\t} else if ( detail.packageName === pkg ) {\n\t\t\tdetail.description ||= description;\n\t\t\tif ( detail.props.length === 0 ) {\n\t\t\t\tdetail.props = props;\n\t\t\t}\n\t\t\tdetail.stories.push( ...stories );\n\t\t}\n\t}\n\n\treturn detail;\n}\n"],
5
- "mappings": ";AAiBA,IAAM,iBAA2C;AAAA,EAChD,uCAAuC;AAAA,EACvC,sCAAsC;AAAA,EACtC,mCAAmC;AAAA,EACnC,4CACC;AAAA,EACD,kCAAkC;AAAA,EAClC,kCAAkC;AACnC;AAYA,SAAS,qBAAsB,MAAc,aAA8B;AAC1E,QAAM,WAAW,eAAgB,GAAI,WAAY,IAAK,IAAK,EAAG;AAC9D,SAAO,WACJ,YAAa,QAAS,OAAQ,IAAK,YAAa,WAAY,OAC5D,YAAa,IAAK,YAAa,WAAY;AAC/C;AAaO,SAAS,oBAAqB,WAAmC;AACvE,QAAM,QAAQ,UAAU,MAAO,2BAA4B;AAC3D,SAAO,QAAQ,cAAe,MAAO,CAAE,CAAE,KAAK;AAC/C;AAaA,SAAS,uBAAwB,MAAuB;AACvD,SAAO,KAAK,MAAO,KAAK,CAAE,EAAG,CAAE;AAChC;AASO,SAAS,WACf,UASkB;AAClB,SAAO,OAAO,QAAS,QAAS,EAC9B,OAAQ,CAAE,CAAE,EAAE,QAAS,MAAO;AAC9B,UAAM,eAAgB,SAAS,eAAe,IAAK,YAAY;AAC/D,WACC,CAAE,YAAY,SAAU,aAAc,KACtC,CAAE,YAAY,SAAU,SAAU;AAAA,EAEpC,CAAE,EACD,IAAK,CAAE,CAAE,UAAU,QAAS,OAAS;AAAA,IACrC,MAAM;AAAA;AAAA;AAAA;AAAA,IAIN,MAAM,SAAS,MAAM,OAAO,SAAS,MAAM,QAAQ;AAAA,IACnD,UAAU,SAAS,YAAY;AAAA,IAC/B,aAAa,SAAS,eAAe;AAAA,IACrC,cAAc,SAAS,cAAc,SAAS;AAAA,EAC/C,EAAI;AACN;AAWO,SAAS,gBACf,YACc;AACd,QAAM,QAAQ,oBAAI,IAAyB;AAE3C,aAAY,aAAa,OAAO,OAAQ,UAAW,GAAI;AACtD,UAAM,cAAc,oBAAqB,UAAU,IAAK;AACxD,QAAK,CAAE,aAAc;AACpB;AAAA,IACD;AAEA,UAAM,OAAO,uBAAwB,UAAU,IAAK;AACpD,UAAM,MAAM,GAAI,WAAY,IAAK,IAAK;AACtC,UAAM,WAAW,MAAM,IAAK,GAAI;AAChC,UAAM,cAAc,UAAU,eAAe;AAE7C,QAAK,CAAE,UAAW;AACjB,YAAM,IAAK,KAAK,EAAE,MAAM,aAAa,YAAY,CAAE;AAAA,IACpD,OAAO;AAGN,eAAS,gBAAgB;AAAA,IAC1B;AAAA,EACD;AAEA,SAAO,MAAM,KAAM,MAAM,OAAO,CAAE,EAAE;AAAA,IAAM,CAAE,GAAG,MAC9C,EAAE,KAAK,cAAe,EAAE,IAAK;AAAA,EAC9B;AACD;AAcO,SAAS,qBACf,YACA,MACyB;AACzB,MAAI,SAAiC;AAErC,aAAY,aAAa,OAAO,OAAQ,UAAW,GAAI;AACtD,UAAM,gBAAgB,uBAAwB,UAAU,IAAK;AAC7D,QAAK,cAAc,YAAY,MAAM,KAAK,YAAY,GAAI;AACzD;AAAA,IACD;AAEA,UAAM,MAAM,oBAAqB,UAAU,IAAK;AAChD,QAAK,CAAE,KAAM;AACZ;AAAA,IACD;AAEA,UAAM,cAAc,UAAU,eAAe;AAC7C,UAAM,QAAQ,WAAY,UAAU,oBAAoB,SAAS,CAAC,CAAE;AACpE,UAAM,UAAU,UAAU,WAAW,CAAC;AAEtC,QAAK,CAAE,QAAS;AACf,eAAS;AAAA,QACR,MAAM;AAAA,QACN;AAAA,QACA,aAAa;AAAA,QACb,iBAAiB,qBAAsB,eAAe,GAAI;AAAA,QAC1D;AAAA,QACA,SAAS,CAAE,GAAG,OAAQ;AAAA,MACvB;AAAA,IACD,WAAY,OAAO,gBAAgB,KAAM;AACxC,aAAO,gBAAgB;AACvB,UAAK,OAAO,MAAM,WAAW,GAAI;AAChC,eAAO,QAAQ;AAAA,MAChB;AACA,aAAO,QAAQ,KAAM,GAAG,OAAQ;AAAA,IACjC;AAAA,EACD;AAEA,SAAO;AACR;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"parse-components.mjs","names":[],"sources":["../src/parse-components.ts"],"sourcesContent":["import type {\n\tComponent,\n\tComponentDetail,\n\tComponentProp,\n\tManifestComponent,\n} from './types.ts';\n\n/**\n * Mapping of canonical name to actual exported identifier, keyed by\n * `package:name`. A package's actual exported identifier may be different from\n * the canonical name in the internal implementation that's known to Storybook.\n *\n * Ideally we could derive this from the package's source code, but MCP\n * consumers aren't guaranteed to have these packages installed. Since this\n * is a legacy convention, we expect this list will only ever shrink over time\n * and can eventually be removed.\n */\nconst EXPORT_ALIASES: Record< string, string > = {\n\t'@wordpress/components:ConfirmDialog': '__experimentalConfirmDialog',\n\t'@wordpress/components:InputControl': '__experimentalInputControl',\n\t'@wordpress/components:ItemGroup': '__experimentalItemGroup',\n\t'@wordpress/components:ToggleGroupControl':\n\t\t'__experimentalToggleGroupControl',\n\t'@wordpress/components:TreeGrid': '__experimentalTreeGrid',\n\t'@wordpress/components:Truncate': '__experimentalTruncate',\n};\n\n/**\n * Build the import statement a consumer should use to bring a component into\n * scope under its canonical name. For aliased components, emit an `as` rename\n * so that subsequent code samples (which reference the canonical name) resolve\n * against the actual export.\n *\n * @param name - The canonical component name.\n * @param packageName - The npm package name.\n * @return The import statement as a single-line string.\n */\nfunction buildImportStatement( name: string, packageName: string ): string {\n\tconst exported = EXPORT_ALIASES[ `${ packageName }:${ name }` ];\n\treturn exported\n\t\t? `import { ${ exported } as ${ name } } from '${ packageName }';`\n\t\t: `import { ${ name } } from '${ packageName }';`;\n}\n\n/**\n * Derive the npm package name from the story file path.\n *\n * Manifest paths look like `../packages/<dir>/src/.../index.story.tsx`. We\n * extract `<dir>` and prepend the `@wordpress/` npm namespace. Curation of\n * which components appear in the manifest is handled upstream via Storybook\n * tags, so this only needs to recognize package-shaped paths.\n *\n * @param storyPath - The story file path from the manifest.\n * @return The npm package name, or null for paths outside `packages/*`.\n */\nexport function packageNameFromPath( storyPath: string ): string | null {\n\tconst match = storyPath.match( /\\.\\.\\/packages\\/([^/]+)\\// );\n\treturn match ? `@wordpress/${ match[ 1 ] }` : null;\n}\n\n/**\n * For components exported as a namespace (e.g. `AlertDialog`, with members\n * `AlertDialog.Root`, `AlertDialog.Trigger`, etc.), the manifest lists the\n * primary entry under a dotted name like `AlertDialog.Root`. The canonical\n * name we expose is the top-level identifier a consumer actually imports,\n * which is the portion before the first dot. For simple components (e.g.\n * `Button`), this is a no-op.\n *\n * @param name - The component name from the manifest.\n * @return The top-level importable identifier.\n */\nfunction canonicalComponentName( name: string ): string {\n\treturn name.split( '.', 1 )[ 0 ];\n}\n\n/**\n * Parse props from a component's `reactComponentMeta` data, filtering out\n * deprecated and ignored props.\n *\n * @param rawProps - The component meta props record.\n * @return Parsed props with deprecated entries removed.\n */\nexport function parseProps(\n\trawProps: Record<\n\t\tstring,\n\t\t{\n\t\t\trequired?: boolean;\n\t\t\ttype?: { name: string; raw?: string };\n\t\t\tdescription?: string;\n\t\t\tdefaultValue?: { value: string } | null;\n\t\t}\n\t>\n): ComponentProp[] {\n\treturn Object.entries( rawProps )\n\t\t.filter( ( [ , propInfo ] ) => {\n\t\t\tconst description = ( propInfo.description || '' ).toLowerCase();\n\t\t\treturn (\n\t\t\t\t! description.includes( '@deprecated' ) &&\n\t\t\t\t! description.includes( '@ignore' )\n\t\t\t);\n\t\t} )\n\t\t.map( ( [ propName, propInfo ] ) => ( {\n\t\t\tname: propName,\n\t\t\t// Prefer `raw` when present, as it carries the source-authored type\n\t\t\t// expression a consumer could use directly. Primitives emit only\n\t\t\t// `name`, so fall back if `raw` is not present.\n\t\t\ttype: propInfo.type?.raw || propInfo.type?.name || 'unknown',\n\t\t\trequired: propInfo.required || false,\n\t\t\tdescription: propInfo.description || '',\n\t\t\tdefaultValue: propInfo.defaultValue?.value ?? null,\n\t\t} ) );\n}\n\n/**\n * Parse manifest components into a flat list sorted alphabetically by name.\n * When a component is defined across multiple story files (e.g. a companion\n * file documenting a specific aspect), it is collapsed to a single entry keyed\n * by its canonical name and package.\n *\n * @param components - The manifest components record.\n * @return Flat list of components derived from the manifest.\n */\nexport function parseComponents(\n\tcomponents: Record< string, ManifestComponent >\n): Component[] {\n\tconst byKey = new Map< string, Component >();\n\n\tfor ( const component of Object.values( components ) ) {\n\t\tconst packageName = packageNameFromPath( component.path );\n\t\tif ( ! packageName ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst name = canonicalComponentName( component.name );\n\t\tconst key = `${ packageName }:${ name }`;\n\t\tconst existing = byKey.get( key );\n\t\tconst description = component.description || '';\n\n\t\tif ( ! existing ) {\n\t\t\tbyKey.set( key, { name, description, packageName } );\n\t\t} else {\n\t\t\t// Prefer a non-empty description from a later entry over an\n\t\t\t// empty one from the first.\n\t\t\texisting.description ||= description;\n\t\t}\n\t}\n\n\treturn Array.from( byKey.values() ).sort( ( a, b ) =>\n\t\ta.name.localeCompare( b.name )\n\t);\n}\n\n/**\n * Find a single component by name (case-insensitive) and return its full\n * detail including props and stories. When a component is spread across\n * multiple story files, stories from every contributing file are collected\n * in manifest order. Descriptions and props are also authored on the component\n * itself, so in principle they should be identical across story files; in\n * practice one file may omit them, so we prefer any non-empty value found.\n *\n * @param components - The manifest components record.\n * @param name - The component name to look up.\n * @return The component detail, or null if not found.\n */\nexport function parseComponentDetail(\n\tcomponents: Record< string, ManifestComponent >,\n\tname: string\n): ComponentDetail | null {\n\tlet detail: ComponentDetail | null = null;\n\n\tfor ( const component of Object.values( components ) ) {\n\t\tconst canonicalName = canonicalComponentName( component.name );\n\t\tif ( canonicalName.toLowerCase() !== name.toLowerCase() ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst pkg = packageNameFromPath( component.path );\n\t\tif ( ! pkg ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst description = component.description || '';\n\t\tconst props = parseProps( component.reactComponentMeta?.props || {} );\n\t\tconst stories = component.stories || [];\n\n\t\tif ( ! detail ) {\n\t\t\tdetail = {\n\t\t\t\tname: canonicalName,\n\t\t\t\tdescription,\n\t\t\t\tpackageName: pkg,\n\t\t\t\timportStatement: buildImportStatement( canonicalName, pkg ),\n\t\t\t\tprops,\n\t\t\t\tstories: [ ...stories ],\n\t\t\t};\n\t\t} else if ( detail.packageName === pkg ) {\n\t\t\tdetail.description ||= description;\n\t\t\tif ( detail.props.length === 0 ) {\n\t\t\t\tdetail.props = props;\n\t\t\t}\n\t\t\tdetail.stories.push( ...stories );\n\t\t}\n\t}\n\n\treturn detail;\n}\n"],"mappings":";;;;;;;;;;;AAiBA,MAAM,iBAA2C;CAChD,uCAAuC;CACvC,sCAAsC;CACtC,mCAAmC;CACnC,4CACC;CACD,kCAAkC;CAClC,kCAAkC;AACnC;;;;;;;;;;;AAYA,SAAS,qBAAsB,MAAc,aAA8B;CAC1E,MAAM,WAAW,eAAgB,GAAI,YAAa,GAAI;CACtD,OAAO,WACJ,YAAa,SAAU,MAAO,KAAM,WAAY,YAAa,MAC7D,YAAa,KAAM,WAAY,YAAa;AAChD;;;;;;;;;;;;AAaA,SAAgB,oBAAqB,WAAmC;CACvE,MAAM,QAAQ,UAAU,MAAO,2BAA4B;CAC3D,OAAO,QAAQ,cAAe,MAAO,OAAS;AAC/C;;;;;;;;;;;;AAaA,SAAS,uBAAwB,MAAuB;CACvD,OAAO,KAAK,MAAO,KAAK,CAAE,CAAC,CAAE;AAC9B;;;;;;;;AASA,SAAgB,WACf,UASkB;CAClB,OAAO,OAAO,QAAS,QAAS,CAAC,CAC/B,QAAU,GAAI,cAAgB;EAC9B,MAAM,eAAgB,SAAS,eAAe,GAAA,CAAK,YAAY;EAC/D,OACC,CAAE,YAAY,SAAU,aAAc,KACtC,CAAE,YAAY,SAAU,SAAU;CAEpC,CAAE,CAAC,CACF,KAAO,CAAE,UAAU,eAAkB;EACrC,MAAM;EAIN,MAAM,SAAS,MAAM,OAAO,SAAS,MAAM,QAAQ;EACnD,UAAU,SAAS,YAAY;EAC/B,aAAa,SAAS,eAAe;EACrC,cAAc,SAAS,cAAc,SAAS;CAC/C,EAAI;AACN;;;;;;;;;;AAWA,SAAgB,gBACf,YACc;CACd,MAAM,wBAAQ,IAAI,IAAyB;CAE3C,KAAM,MAAM,aAAa,OAAO,OAAQ,UAAW,GAAI;EACtD,MAAM,cAAc,oBAAqB,UAAU,IAAK;EACxD,IAAK,CAAE,aACN;EAGD,MAAM,OAAO,uBAAwB,UAAU,IAAK;EACpD,MAAM,MAAM,GAAI,YAAa,GAAI;EACjC,MAAM,WAAW,MAAM,IAAK,GAAI;EAChC,MAAM,cAAc,UAAU,eAAe;EAE7C,IAAK,CAAE,UACN,MAAM,IAAK,KAAK;GAAE;GAAM;GAAa;EAAY,CAAE;OAInD,SAAS,gBAAgB;CAE3B;CAEA,OAAO,MAAM,KAAM,MAAM,OAAO,CAAE,CAAC,CAAC,MAAQ,GAAG,MAC9C,EAAE,KAAK,cAAe,EAAE,IAAK,CAC9B;AACD;;;;;;;;;;;;;AAcA,SAAgB,qBACf,YACA,MACyB;CACzB,IAAI,SAAiC;CAErC,KAAM,MAAM,aAAa,OAAO,OAAQ,UAAW,GAAI;EACtD,MAAM,gBAAgB,uBAAwB,UAAU,IAAK;EAC7D,IAAK,cAAc,YAAY,MAAM,KAAK,YAAY,GACrD;EAGD,MAAM,MAAM,oBAAqB,UAAU,IAAK;EAChD,IAAK,CAAE,KACN;EAGD,MAAM,cAAc,UAAU,eAAe;EAC7C,MAAM,QAAQ,WAAY,UAAU,oBAAoB,SAAS,CAAC,CAAE;EACpE,MAAM,UAAU,UAAU,WAAW,CAAC;EAEtC,IAAK,CAAE,QACN,SAAS;GACR,MAAM;GACN;GACA,aAAa;GACb,iBAAiB,qBAAsB,eAAe,GAAI;GAC1D;GACA,SAAS,CAAE,GAAG,OAAQ;EACvB;OACM,IAAK,OAAO,gBAAgB,KAAM;GACxC,OAAO,gBAAgB;GACvB,IAAK,OAAO,MAAM,WAAW,GAC5B,OAAO,QAAQ;GAEhB,OAAO,QAAQ,KAAM,GAAG,OAAQ;EACjC;CACD;CAEA,OAAO;AACR"}
@@ -0,0 +1,44 @@
1
+ // packages/design-system-mcp/src/parse-patterns.ts
2
+ /**
3
+ * Storybook docs ID prefix shared by every document under the "Design System/
4
+ * Patterns" title, e.g. `design-system-patterns-destructive-actions--docs`.
5
+ */
6
+ const PATTERN_ID_PREFIX = "design-system-patterns-";
7
+ /**
8
+ * Parse a docs manifest entry into a pattern. The title is the last segment of
9
+ * the Storybook title, as shown in the sidebar, and the description is the
10
+ * document's lead paragraph (see the "Manifests" section of
11
+ * `storybook/README.md`).
12
+ *
13
+ * @param doc - The docs manifest entry.
14
+ * @return The pattern, or null if the entry is not a pattern or has no heading.
15
+ */
16
+ function parsePattern(doc) {
17
+ const [componentId] = doc.id.split("--");
18
+ const source = doc.content ?? "";
19
+ const start = source.search(/^# /m);
20
+ if (!componentId.startsWith(PATTERN_ID_PREFIX) || start === -1) return null;
21
+ const slug = componentId.slice(23);
22
+ const content = source.slice(start).trim();
23
+ const title = doc.title?.split("/").pop() ?? slug;
24
+ const [, description = ""] = content.split(/\n{2,}/);
25
+ return {
26
+ slug,
27
+ title,
28
+ description: description.replace(/\s*\n\s*/g, " "),
29
+ content
30
+ };
31
+ }
32
+ /**
33
+ * Parse the design system patterns from the entries of a Storybook docs
34
+ * manifest.
35
+ *
36
+ * @param docs - The manifest entries, keyed by docs ID.
37
+ * @return The patterns.
38
+ */
39
+ function parsePatterns(docs) {
40
+ return Object.values(docs).map(parsePattern).filter((pattern) => !!pattern);
41
+ }
42
+ export { parsePatterns };
43
+
44
+ //# sourceMappingURL=parse-patterns.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-patterns.mjs","names":[],"sources":["../src/parse-patterns.ts"],"sourcesContent":["import type { ManifestDoc, Pattern } from './types.ts';\n\n/**\n * Storybook docs ID prefix shared by every document under the \"Design System/\n * Patterns\" title, e.g. `design-system-patterns-destructive-actions--docs`.\n */\nconst PATTERN_ID_PREFIX = 'design-system-patterns-';\n\n/**\n * Parse a docs manifest entry into a pattern. The title is the last segment of\n * the Storybook title, as shown in the sidebar, and the description is the\n * document's lead paragraph (see the \"Manifests\" section of\n * `storybook/README.md`).\n *\n * @param doc - The docs manifest entry.\n * @return The pattern, or null if the entry is not a pattern or has no heading.\n */\nfunction parsePattern( doc: ManifestDoc ): Pattern | null {\n\tconst [ componentId ] = doc.id.split( '--' );\n\tconst source = doc.content ?? '';\n\t// The document starts at its heading. Anything before it, such as imports\n\t// and the `<Meta />` block, only sets up the Storybook page.\n\tconst start = source.search( /^# /m );\n\tif ( ! componentId.startsWith( PATTERN_ID_PREFIX ) || start === -1 ) {\n\t\treturn null;\n\t}\n\n\tconst slug = componentId.slice( PATTERN_ID_PREFIX.length );\n\tconst content = source.slice( start ).trim();\n\tconst title = doc.title?.split( '/' ).pop() ?? slug;\n\tconst [ , description = '' ] = content.split( /\\n{2,}/ );\n\n\treturn {\n\t\tslug,\n\t\ttitle,\n\t\tdescription: description.replace( /\\s*\\n\\s*/g, ' ' ),\n\t\tcontent,\n\t};\n}\n\n/**\n * Parse the design system patterns from the entries of a Storybook docs\n * manifest.\n *\n * @param docs - The manifest entries, keyed by docs ID.\n * @return The patterns.\n */\nexport function parsePatterns(\n\tdocs: Record< string, ManifestDoc >\n): Pattern[] {\n\treturn Object.values( docs )\n\t\t.map( parsePattern )\n\t\t.filter( ( pattern ): pattern is Pattern => !! pattern );\n}\n"],"mappings":";;;;;AAMA,MAAM,oBAAoB;;;;;;;;;;AAW1B,SAAS,aAAc,KAAmC;CACzD,MAAM,CAAE,eAAgB,IAAI,GAAG,MAAO,IAAK;CAC3C,MAAM,SAAS,IAAI,WAAW;CAG9B,MAAM,QAAQ,OAAO,OAAQ,MAAO;CACpC,IAAK,CAAE,YAAY,WAAY,iBAAkB,KAAK,UAAU,IAC/D,OAAO;CAGR,MAAM,OAAO,YAAY,MAAO,EAAyB;CACzD,MAAM,UAAU,OAAO,MAAO,KAAM,CAAC,CAAC,KAAK;CAC3C,MAAM,QAAQ,IAAI,OAAO,MAAO,GAAI,CAAC,CAAC,IAAI,KAAK;CAC/C,MAAM,GAAI,cAAc,MAAO,QAAQ,MAAO,QAAS;CAEvD,OAAO;EACN;EACA;EACA,aAAa,YAAY,QAAS,aAAa,GAAI;EACnD;CACD;AACD;;;;;;;;AASA,SAAgB,cACf,MACY;CACZ,OAAO,OAAO,OAAQ,IAAK,CAAC,CAC1B,IAAK,YAAa,CAAC,CACnB,QAAU,YAAiC,CAAC,CAAE,OAAQ;AACzD"}
@@ -1,73 +1,39 @@
1
- // packages/design-system-mcp/src/tools/get-component-details.ts
2
1
  import { z } from "zod";
3
2
  import { getComponentDetail } from "../data.mjs";
4
3
  import { formatComponentDetail } from "../format.mjs";
5
- var inputSchema = z.object({
6
- name: z.union([
7
- z.string().min(1),
8
- z.array(z.string().min(1)).min(1).max(10)
9
- ]).describe(
10
- 'A component name, or an array of component names to fetch in a single call (e.g. "Button" or ["Button", "Tabs"]).'
11
- )
12
- });
4
+ import { findEach } from "../find-each.mjs";
5
+ // packages/design-system-mcp/src/tools/get-component-details.ts
6
+ const inputSchema = z.object({ name: z.union([z.string().min(1), z.array(z.string().min(1)).min(1).max(10)]).describe("A component name, or an array of component names to fetch in a single call (e.g. \"Button\" or [\"Button\", \"Tabs\"]).") });
13
7
  async function handler({ name }) {
14
- const names = Array.isArray(name) ? name : [name];
15
- const sections = [];
16
- const missing = [];
17
- for (const componentName of names) {
18
- const detail = await getComponentDetail(componentName);
19
- if (detail) {
20
- sections.push(formatComponentDetail(detail));
21
- } else {
22
- missing.push(componentName);
23
- }
24
- }
25
- if (sections.length === 0) {
26
- const list = missing.map((n) => `"${n}"`).join(", ");
27
- return {
28
- content: [
29
- {
30
- type: "text",
31
- text: `No components were found for: ${list}.`
32
- }
33
- ],
34
- isError: true
35
- };
36
- }
37
- let text = sections.join("\n\n---\n\n");
38
- if (missing.length > 0) {
39
- const list = missing.map((n) => `"${n}"`).join(", ");
40
- text += `
41
-
42
- ---
43
-
44
- _No components were found for: ${list}._`;
45
- }
46
- return {
47
- content: [
48
- {
49
- type: "text",
50
- text
51
- }
52
- ]
53
- };
8
+ const { found, missing } = await findEach(name, getComponentDetail);
9
+ const list = missing.map((key) => `"${key}"`).join(", ");
10
+ if (found.length === 0) return {
11
+ content: [{
12
+ type: "text",
13
+ text: `No components were found for: ${list}.`
14
+ }],
15
+ isError: true
16
+ };
17
+ let text = found.map(formatComponentDetail).join("\n\n---\n\n");
18
+ if (missing.length > 0) text += `\n\n---\n\n_No components were found for: ${list}._`;
19
+ return { content: [{
20
+ type: "text",
21
+ text
22
+ }] };
54
23
  }
24
+ /**
25
+ * Register the get_component_details tool.
26
+ *
27
+ * @param server - The MCP server instance.
28
+ */
55
29
  function register(server) {
56
- server.registerTool(
57
- "get_component_details",
58
- {
59
- title: "Get Component Details",
60
- description: "Get detailed documentation for one or more WordPress Design System components including props, usage examples, and import statements. Pass multiple names to fetch several components in a single call instead of making repeated calls.",
61
- inputSchema,
62
- annotations: {
63
- readOnlyHint: true
64
- }
65
- },
66
- handler
67
- );
30
+ server.registerTool("get_component_details", {
31
+ title: "Get Component Details",
32
+ description: "Get detailed documentation for one or more WordPress Design System components including props, usage examples, and import statements. Pass multiple names to fetch several components in a single call instead of making repeated calls.",
33
+ inputSchema,
34
+ annotations: { readOnlyHint: true }
35
+ }, handler);
68
36
  }
69
- export {
70
- handler,
71
- register
72
- };
73
- //# sourceMappingURL=get-component-details.mjs.map
37
+ export { handler, register };
38
+
39
+ //# sourceMappingURL=get-component-details.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/tools/get-component-details.ts"],
4
- "sourcesContent": ["import type { McpServer } from '@modelcontextprotocol/server';\nimport { z } from 'zod';\nimport { getComponentDetail } from '../data.ts';\nimport { formatComponentDetail } from '../format.ts';\n\nconst inputSchema = z.object( {\n\tname: z\n\t\t.union( [\n\t\t\tz.string().min( 1 ),\n\t\t\tz.array( z.string().min( 1 ) ).min( 1 ).max( 10 ),\n\t\t] )\n\t\t.describe(\n\t\t\t'A component name, or an array of component names to fetch in a single call (e.g. \"Button\" or [\"Button\", \"Tabs\"]).'\n\t\t),\n} );\n\nexport async function handler( { name }: z.infer< typeof inputSchema > ) {\n\tconst names = Array.isArray( name ) ? name : [ name ];\n\tconst sections: string[] = [];\n\tconst missing: string[] = [];\n\n\tfor ( const componentName of names ) {\n\t\tconst detail = await getComponentDetail( componentName );\n\t\tif ( detail ) {\n\t\t\tsections.push( formatComponentDetail( detail ) );\n\t\t} else {\n\t\t\tmissing.push( componentName );\n\t\t}\n\t}\n\n\tif ( sections.length === 0 ) {\n\t\tconst list = missing.map( ( n ) => `\"${ n }\"` ).join( ', ' );\n\t\treturn {\n\t\t\tcontent: [\n\t\t\t\t{\n\t\t\t\t\ttype: 'text' as const,\n\t\t\t\t\ttext: `No components were found for: ${ list }.`,\n\t\t\t\t},\n\t\t\t],\n\t\t\tisError: true,\n\t\t};\n\t}\n\n\tlet text = sections.join( '\\n\\n---\\n\\n' );\n\tif ( missing.length > 0 ) {\n\t\tconst list = missing.map( ( n ) => `\"${ n }\"` ).join( ', ' );\n\t\ttext += `\\n\\n---\\n\\n_No components were found for: ${ list }._`;\n\t}\n\n\treturn {\n\t\tcontent: [\n\t\t\t{\n\t\t\t\ttype: 'text' as const,\n\t\t\t\ttext,\n\t\t\t},\n\t\t],\n\t};\n}\n\n/**\n * Register the get_component_details tool.\n *\n * @param server - The MCP server instance.\n */\nexport function register( server: McpServer ): void {\n\tserver.registerTool(\n\t\t'get_component_details',\n\t\t{\n\t\t\ttitle: 'Get Component Details',\n\t\t\tdescription:\n\t\t\t\t'Get detailed documentation for one or more WordPress Design System components including props, usage examples, and import statements. Pass multiple names to fetch several components in a single call instead of making repeated calls.',\n\t\t\tinputSchema,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: true,\n\t\t\t},\n\t\t},\n\t\thandler\n\t);\n}\n"],
5
- "mappings": ";AACA,SAAS,SAAS;AAClB,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AAEtC,IAAM,cAAc,EAAE,OAAQ;AAAA,EAC7B,MAAM,EACJ,MAAO;AAAA,IACP,EAAE,OAAO,EAAE,IAAK,CAAE;AAAA,IAClB,EAAE,MAAO,EAAE,OAAO,EAAE,IAAK,CAAE,CAAE,EAAE,IAAK,CAAE,EAAE,IAAK,EAAG;AAAA,EACjD,CAAE,EACD;AAAA,IACA;AAAA,EACD;AACF,CAAE;AAEF,eAAsB,QAAS,EAAE,KAAK,GAAmC;AACxE,QAAM,QAAQ,MAAM,QAAS,IAAK,IAAI,OAAO,CAAE,IAAK;AACpD,QAAM,WAAqB,CAAC;AAC5B,QAAM,UAAoB,CAAC;AAE3B,aAAY,iBAAiB,OAAQ;AACpC,UAAM,SAAS,MAAM,mBAAoB,aAAc;AACvD,QAAK,QAAS;AACb,eAAS,KAAM,sBAAuB,MAAO,CAAE;AAAA,IAChD,OAAO;AACN,cAAQ,KAAM,aAAc;AAAA,IAC7B;AAAA,EACD;AAEA,MAAK,SAAS,WAAW,GAAI;AAC5B,UAAM,OAAO,QAAQ,IAAK,CAAE,MAAO,IAAK,CAAE,GAAI,EAAE,KAAM,IAAK;AAC3D,WAAO;AAAA,MACN,SAAS;AAAA,QACR;AAAA,UACC,MAAM;AAAA,UACN,MAAM,iCAAkC,IAAK;AAAA,QAC9C;AAAA,MACD;AAAA,MACA,SAAS;AAAA,IACV;AAAA,EACD;AAEA,MAAI,OAAO,SAAS,KAAM,aAAc;AACxC,MAAK,QAAQ,SAAS,GAAI;AACzB,UAAM,OAAO,QAAQ,IAAK,CAAE,MAAO,IAAK,CAAE,GAAI,EAAE,KAAM,IAAK;AAC3D,YAAQ;AAAA;AAAA;AAAA;AAAA,iCAA8C,IAAK;AAAA,EAC5D;AAEA,SAAO;AAAA,IACN,SAAS;AAAA,MACR;AAAA,QACC,MAAM;AAAA,QACN;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;AAOO,SAAS,SAAU,QAA0B;AACnD,SAAO;AAAA,IACN;AAAA,IACA;AAAA,MACC,OAAO;AAAA,MACP,aACC;AAAA,MACD;AAAA,MACA,aAAa;AAAA,QACZ,cAAc;AAAA,MACf;AAAA,IACD;AAAA,IACA;AAAA,EACD;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"get-component-details.mjs","names":[],"sources":["../../src/tools/get-component-details.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/server';\nimport { z } from 'zod';\nimport { getComponentDetail } from '../data.ts';\nimport { formatComponentDetail } from '../format.ts';\nimport { findEach } from '../find-each.ts';\n\nconst inputSchema = z.object( {\n\tname: z\n\t\t.union( [\n\t\t\tz.string().min( 1 ),\n\t\t\tz.array( z.string().min( 1 ) ).min( 1 ).max( 10 ),\n\t\t] )\n\t\t.describe(\n\t\t\t'A component name, or an array of component names to fetch in a single call (e.g. \"Button\" or [\"Button\", \"Tabs\"]).'\n\t\t),\n} );\n\nexport async function handler( { name }: z.infer< typeof inputSchema > ) {\n\tconst { found, missing } = await findEach( name, getComponentDetail );\n\tconst list = missing.map( ( key ) => `\"${ key }\"` ).join( ', ' );\n\n\tif ( found.length === 0 ) {\n\t\treturn {\n\t\t\tcontent: [\n\t\t\t\t{\n\t\t\t\t\ttype: 'text' as const,\n\t\t\t\t\ttext: `No components were found for: ${ list }.`,\n\t\t\t\t},\n\t\t\t],\n\t\t\tisError: true,\n\t\t};\n\t}\n\n\tlet text = found.map( formatComponentDetail ).join( '\\n\\n---\\n\\n' );\n\tif ( missing.length > 0 ) {\n\t\ttext += `\\n\\n---\\n\\n_No components were found for: ${ list }._`;\n\t}\n\n\treturn {\n\t\tcontent: [\n\t\t\t{\n\t\t\t\ttype: 'text' as const,\n\t\t\t\ttext,\n\t\t\t},\n\t\t],\n\t};\n}\n\n/**\n * Register the get_component_details tool.\n *\n * @param server - The MCP server instance.\n */\nexport function register( server: McpServer ): void {\n\tserver.registerTool(\n\t\t'get_component_details',\n\t\t{\n\t\t\ttitle: 'Get Component Details',\n\t\t\tdescription:\n\t\t\t\t'Get detailed documentation for one or more WordPress Design System components including props, usage examples, and import statements. Pass multiple names to fetch several components in a single call instead of making repeated calls.',\n\t\t\tinputSchema,\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: true,\n\t\t\t},\n\t\t},\n\t\thandler\n\t);\n}\n"],"mappings":";;;;;AAMA,MAAM,cAAc,EAAE,OAAQ,EAC7B,MAAM,EACJ,MAAO,CACP,EAAE,OAAO,CAAC,CAAC,IAAK,CAAE,GAClB,EAAE,MAAO,EAAE,OAAO,CAAC,CAAC,IAAK,CAAE,CAAE,CAAC,CAAC,IAAK,CAAE,CAAC,CAAC,IAAK,EAAG,CACjD,CAAE,CAAC,CACF,SACA,yHACD,EACF,CAAE;AAEF,eAAsB,QAAS,EAAE,QAAwC;CACxE,MAAM,EAAE,OAAO,YAAY,MAAM,SAAU,MAAM,kBAAmB;CACpE,MAAM,OAAO,QAAQ,KAAO,QAAS,IAAK,IAAK,EAAG,CAAC,CAAC,KAAM,IAAK;CAE/D,IAAK,MAAM,WAAW,GACrB,OAAO;EACN,SAAS,CACR;GACC,MAAM;GACN,MAAM,iCAAkC,KAAM;EAC/C,CACD;EACA,SAAS;CACV;CAGD,IAAI,OAAO,MAAM,IAAK,qBAAsB,CAAC,CAAC,KAAM,aAAc;CAClE,IAAK,QAAQ,SAAS,GACrB,QAAQ,6CAA8C,KAAM;CAG7D,OAAO,EACN,SAAS,CACR;EACC,MAAM;EACN;CACD,CACD,EACD;AACD;;;;;;AAOA,SAAgB,SAAU,QAA0B;CACnD,OAAO,aACN,yBACA;EACC,OAAO;EACP,aACC;EACD;EACA,aAAa,EACZ,cAAc,KACf;CACD,GACA,OACD;AACD"}
@@ -1,30 +1,24 @@
1
- // packages/design-system-mcp/src/tools/get-components.ts
2
1
  import { getComponents } from "../data.mjs";
3
2
  import { formatComponents } from "../format.mjs";
3
+ // packages/design-system-mcp/src/tools/get-components.ts
4
+ /**
5
+ * Register the get_components tool.
6
+ *
7
+ * @param server - The MCP server instance.
8
+ */
4
9
  function register(server) {
5
- server.registerTool(
6
- "get_components",
7
- {
8
- title: "Get Components",
9
- description: "Get a list of all available WordPress Design System components with their package names and descriptions.",
10
- annotations: {
11
- readOnlyHint: true
12
- }
13
- },
14
- async () => {
15
- const components = await getComponents();
16
- return {
17
- content: [
18
- {
19
- type: "text",
20
- text: formatComponents(components)
21
- }
22
- ]
23
- };
24
- }
25
- );
10
+ server.registerTool("get_components", {
11
+ title: "Get Components",
12
+ description: "Get a list of all available WordPress Design System components with their package names and descriptions.",
13
+ annotations: { readOnlyHint: true }
14
+ }, async () => {
15
+ const components = await getComponents();
16
+ return { content: [{
17
+ type: "text",
18
+ text: formatComponents(components)
19
+ }] };
20
+ });
26
21
  }
27
- export {
28
- register
29
- };
30
- //# sourceMappingURL=get-components.mjs.map
22
+ export { register };
23
+
24
+ //# sourceMappingURL=get-components.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/tools/get-components.ts"],
4
- "sourcesContent": ["import type { McpServer } from '@modelcontextprotocol/server';\nimport { getComponents } from '../data.ts';\nimport { formatComponents } from '../format.ts';\n\n/**\n * Register the get_components tool.\n *\n * @param server - The MCP server instance.\n */\nexport function register( server: McpServer ): void {\n\tserver.registerTool(\n\t\t'get_components',\n\t\t{\n\t\t\ttitle: 'Get Components',\n\t\t\tdescription:\n\t\t\t\t'Get a list of all available WordPress Design System components with their package names and descriptions.',\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: true,\n\t\t\t},\n\t\t},\n\t\tasync () => {\n\t\t\tconst components = await getComponents();\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\ttext: formatComponents( components ),\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t}\n\t);\n}\n"],
5
- "mappings": ";AACA,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AAO1B,SAAS,SAAU,QAA0B;AACnD,SAAO;AAAA,IACN;AAAA,IACA;AAAA,MACC,OAAO;AAAA,MACP,aACC;AAAA,MACD,aAAa;AAAA,QACZ,cAAc;AAAA,MACf;AAAA,IACD;AAAA,IACA,YAAY;AACX,YAAM,aAAa,MAAM,cAAc;AACvC,aAAO;AAAA,QACN,SAAS;AAAA,UACR;AAAA,YACC,MAAM;AAAA,YACN,MAAM,iBAAkB,UAAW;AAAA,UACpC;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"get-components.mjs","names":[],"sources":["../../src/tools/get-components.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/server';\nimport { getComponents } from '../data.ts';\nimport { formatComponents } from '../format.ts';\n\n/**\n * Register the get_components tool.\n *\n * @param server - The MCP server instance.\n */\nexport function register( server: McpServer ): void {\n\tserver.registerTool(\n\t\t'get_components',\n\t\t{\n\t\t\ttitle: 'Get Components',\n\t\t\tdescription:\n\t\t\t\t'Get a list of all available WordPress Design System components with their package names and descriptions.',\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: true,\n\t\t\t},\n\t\t},\n\t\tasync () => {\n\t\t\tconst components = await getComponents();\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\ttext: formatComponents( components ),\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t}\n\t);\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,SAAU,QAA0B;CACnD,OAAO,aACN,kBACA;EACC,OAAO;EACP,aACC;EACD,aAAa,EACZ,cAAc,KACf;CACD,GACA,YAAY;EACX,MAAM,aAAa,MAAM,cAAc;EACvC,OAAO,EACN,SAAS,CACR;GACC,MAAM;GACN,MAAM,iBAAkB,UAAW;EACpC,CACD,EACD;CACD,CACD;AACD"}
@@ -1,29 +1,22 @@
1
- // packages/design-system-mcp/src/tools/get-design-tokens.ts
2
1
  import { getDesignTokens } from "../data.mjs";
2
+ // packages/design-system-mcp/src/tools/get-design-tokens.ts
3
+ /**
4
+ * Register the get_design_tokens tool.
5
+ *
6
+ * @param server - The MCP server instance.
7
+ */
3
8
  function register(server) {
4
- server.registerTool(
5
- "get_design_tokens",
6
- {
7
- title: "Get Design Tokens",
8
- description: "Get the WordPress Design System design tokens reference (colors, spacing, typography, motion, etc.).",
9
- annotations: {
10
- readOnlyHint: true
11
- }
12
- },
13
- async () => {
14
- const tokens = await getDesignTokens();
15
- return {
16
- content: [
17
- {
18
- type: "text",
19
- text: tokens.content
20
- }
21
- ]
22
- };
23
- }
24
- );
9
+ server.registerTool("get_design_tokens", {
10
+ title: "Get Design Tokens",
11
+ description: "Get the WordPress Design System design tokens reference (colors, spacing, typography, motion, etc.).",
12
+ annotations: { readOnlyHint: true }
13
+ }, async () => {
14
+ return { content: [{
15
+ type: "text",
16
+ text: (await getDesignTokens()).content
17
+ }] };
18
+ });
25
19
  }
26
- export {
27
- register
28
- };
29
- //# sourceMappingURL=get-design-tokens.mjs.map
20
+ export { register };
21
+
22
+ //# sourceMappingURL=get-design-tokens.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/tools/get-design-tokens.ts"],
4
- "sourcesContent": ["import type { McpServer } from '@modelcontextprotocol/server';\nimport { getDesignTokens } from '../data.ts';\n\n/**\n * Register the get_design_tokens tool.\n *\n * @param server - The MCP server instance.\n */\nexport function register( server: McpServer ): void {\n\tserver.registerTool(\n\t\t'get_design_tokens',\n\t\t{\n\t\t\ttitle: 'Get Design Tokens',\n\t\t\tdescription:\n\t\t\t\t'Get the WordPress Design System design tokens reference (colors, spacing, typography, motion, etc.).',\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: true,\n\t\t\t},\n\t\t},\n\t\tasync () => {\n\t\t\tconst tokens = await getDesignTokens();\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\ttext: tokens.content,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t}\n\t);\n}\n"],
5
- "mappings": ";AACA,SAAS,uBAAuB;AAOzB,SAAS,SAAU,QAA0B;AACnD,SAAO;AAAA,IACN;AAAA,IACA;AAAA,MACC,OAAO;AAAA,MACP,aACC;AAAA,MACD,aAAa;AAAA,QACZ,cAAc;AAAA,MACf;AAAA,IACD;AAAA,IACA,YAAY;AACX,YAAM,SAAS,MAAM,gBAAgB;AACrC,aAAO;AAAA,QACN,SAAS;AAAA,UACR;AAAA,YACC,MAAM;AAAA,YACN,MAAM,OAAO;AAAA,UACd;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"get-design-tokens.mjs","names":[],"sources":["../../src/tools/get-design-tokens.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/server';\nimport { getDesignTokens } from '../data.ts';\n\n/**\n * Register the get_design_tokens tool.\n *\n * @param server - The MCP server instance.\n */\nexport function register( server: McpServer ): void {\n\tserver.registerTool(\n\t\t'get_design_tokens',\n\t\t{\n\t\t\ttitle: 'Get Design Tokens',\n\t\t\tdescription:\n\t\t\t\t'Get the WordPress Design System design tokens reference (colors, spacing, typography, motion, etc.).',\n\t\t\tannotations: {\n\t\t\t\treadOnlyHint: true,\n\t\t\t},\n\t\t},\n\t\tasync () => {\n\t\t\tconst tokens = await getDesignTokens();\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\ttext: tokens.content,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t}\n\t);\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,SAAU,QAA0B;CACnD,OAAO,aACN,qBACA;EACC,OAAO;EACP,aACC;EACD,aAAa,EACZ,cAAc,KACf;CACD,GACA,YAAY;EAEX,OAAO,EACN,SAAS,CACR;GACC,MAAM;GACN,OAAM,MALY,gBAAgB,EAAA,CAKrB;EACd,CACD,EACD;CACD,CACD;AACD"}
@@ -0,0 +1,38 @@
1
+ import { z } from "zod";
2
+ import { getPatternDetail } from "../data.mjs";
3
+ import { findEach } from "../find-each.mjs";
4
+ // packages/design-system-mcp/src/tools/get-pattern-details.ts
5
+ const inputSchema = z.object({ slug: z.union([z.string().min(1), z.array(z.string().min(1)).min(1).max(10)]).describe("A pattern slug, or an array of pattern slugs to fetch in a single call (e.g. \"destructive-actions\" or [\"destructive-actions\", \"error-messages\"]).") });
6
+ async function handler({ slug }) {
7
+ const { found, missing } = await findEach(slug, getPatternDetail);
8
+ const list = missing.map((key) => `"${key}"`).join(", ");
9
+ if (found.length === 0) return {
10
+ content: [{
11
+ type: "text",
12
+ text: `No patterns were found for: ${list}. Call get_patterns for the available slugs.`
13
+ }],
14
+ isError: true
15
+ };
16
+ let text = found.map((pattern) => pattern.content).join("\n\n---\n\n");
17
+ if (missing.length > 0) text += `\n\n---\n\n_No patterns were found for: ${list}._`;
18
+ return { content: [{
19
+ type: "text",
20
+ text
21
+ }] };
22
+ }
23
+ /**
24
+ * Register the get_pattern_details tool.
25
+ *
26
+ * @param server - The MCP server instance.
27
+ */
28
+ function register(server) {
29
+ server.registerTool("get_pattern_details", {
30
+ title: "Get Pattern Details",
31
+ description: "Get the full guidance for one or more WordPress Design System patterns. A pattern explains which components to choose for a kind of interaction and how to configure them. Use the slugs listed by get_patterns. Pass multiple slugs to fetch several patterns in a single call instead of making repeated calls.",
32
+ inputSchema,
33
+ annotations: { readOnlyHint: true }
34
+ }, handler);
35
+ }
36
+ export { handler, register };
37
+
38
+ //# sourceMappingURL=get-pattern-details.mjs.map