@nysds/mcp-server 1.20.1 → 1.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * New York State Design System v1.20.1
2
+ * New York State Design System v1.21.1
3
3
  * Description: A design system for New York State's digital products.
4
4
  * Repository: https://github.com/its-hcd/nysds
5
5
  * License: MIT
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Framework snippet generation
3
+ *
4
+ * Turns a component's canonical HTML examples into React and Angular
5
+ * snippets using `@nysds/codegen`'s `transformExample` — the same
6
+ * transformer the docs site and Storybook autodocs use, so an AI assistant
7
+ * asking the MCP server sees exactly the same code a developer sees on
8
+ * designsystem.ny.gov.
9
+ */
10
+ import { type CEMExample, type CEMFormControl } from "./cem-parser.js";
11
+ export type FrameworkFilter = "html" | "react" | "angular";
12
+ export interface FrameworkSnippet {
13
+ code: string;
14
+ imports: string[];
15
+ warnings: string[];
16
+ unsupported: boolean;
17
+ }
18
+ export interface ExampleWithSnippets {
19
+ title: string;
20
+ html: string;
21
+ react: FrameworkSnippet;
22
+ angular: FrameworkSnippet;
23
+ }
24
+ /**
25
+ * Builds React and Angular snippets for every HTML example on a component.
26
+ *
27
+ * When `framework` names one target explicitly, that framework's snippet
28
+ * uses its most idiomatic forms binding for a form-control component —
29
+ * React's controlled pattern (`value` + `onNys*`), Angular's
30
+ * `formControlName` (Reactive Forms). The unrequested framework, and every
31
+ * snippet when `framework` is `"html"` (the default), stays a plain
32
+ * attribute-for-attribute conversion so the default response isn't
33
+ * surprising.
34
+ */
35
+ export declare function buildExampleSnippets(examples: CEMExample[] | undefined, framework: FrameworkFilter, formControl: CEMFormControl | undefined): ExampleWithSnippets[];
36
+ //# sourceMappingURL=framework-snippets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"framework-snippets.d.ts","sourceRoot":"","sources":["../../src/lib/framework-snippets.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH,OAAO,EAAU,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE/E,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;AAE3D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,gBAAgB,CAAC;IACxB,OAAO,EAAE,gBAAgB,CAAC;CAC3B;AAgBD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,UAAU,EAAE,GAAG,SAAS,EAClC,SAAS,EAAE,eAAe,EAC1B,WAAW,EAAE,cAAc,GAAG,SAAS,GACtC,mBAAmB,EAAE,CA+BvB"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Framework snippet generation
3
+ *
4
+ * Turns a component's canonical HTML examples into React and Angular
5
+ * snippets using `@nysds/codegen`'s `transformExample` — the same
6
+ * transformer the docs site and Storybook autodocs use, so an AI assistant
7
+ * asking the MCP server sees exactly the same code a developer sees on
8
+ * designsystem.ny.gov.
9
+ */
10
+ import { transformExample, } from "@nysds/codegen";
11
+ import { getCEM } from "./cem-parser.js";
12
+ function toSnippet(result) {
13
+ return {
14
+ code: result.code,
15
+ imports: result.imports,
16
+ warnings: result.warnings,
17
+ unsupported: result.unsupported,
18
+ };
19
+ }
20
+ /**
21
+ * Builds React and Angular snippets for every HTML example on a component.
22
+ *
23
+ * When `framework` names one target explicitly, that framework's snippet
24
+ * uses its most idiomatic forms binding for a form-control component —
25
+ * React's controlled pattern (`value` + `onNys*`), Angular's
26
+ * `formControlName` (Reactive Forms). The unrequested framework, and every
27
+ * snippet when `framework` is `"html"` (the default), stays a plain
28
+ * attribute-for-attribute conversion so the default response isn't
29
+ * surprising.
30
+ */
31
+ export function buildExampleSnippets(examples, framework, formControl) {
32
+ if (!examples || examples.length === 0)
33
+ return [];
34
+ const manifest = getCEM();
35
+ const reactFormsMode = framework === "react" && formControl ? "template" : "none";
36
+ const angularFormsMode = framework === "angular" && formControl ? "reactive" : "none";
37
+ return examples
38
+ .filter((example) => !example.lang || example.lang === "html")
39
+ .map((example) => ({
40
+ title: example.title,
41
+ html: example.code,
42
+ react: toSnippet(transformExample({
43
+ html: example.code,
44
+ framework: "react",
45
+ manifest,
46
+ formsMode: reactFormsMode,
47
+ })),
48
+ angular: toSnippet(transformExample({
49
+ html: example.code,
50
+ framework: "angular",
51
+ manifest,
52
+ formsMode: angularFormsMode,
53
+ })),
54
+ }));
55
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Framework usage notes
3
+ *
4
+ * Short, framework-specific guidance attached to `get_component` responses
5
+ * when the caller asks for `framework: "react"` or `"angular"` — the import
6
+ * line, the event-prop naming rule, and (when the component is a form
7
+ * control) how it binds into that framework's forms. Naming follows the
8
+ * rules in `.claude/plans/framework-support/README.md` section 4.1, reused
9
+ * here via `@nysds/codegen` rather than re-derived.
10
+ */
11
+ import type { CEMFormControl } from "./cem-parser.js";
12
+ export interface FrameworkUsageNotes {
13
+ package: string;
14
+ import: string;
15
+ events: string;
16
+ forms?: string;
17
+ }
18
+ export declare function buildReactUsageNotes(tagName: string, className: string, formControl: CEMFormControl | undefined): FrameworkUsageNotes;
19
+ export declare function buildAngularUsageNotes(tagName: string, className: string, formControl: CEMFormControl | undefined): FrameworkUsageNotes;
20
+ //# sourceMappingURL=framework-usage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"framework-usage.d.ts","sourceRoot":"","sources":["../../src/lib/framework-usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAQD,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,cAAc,GAAG,SAAS,GACtC,mBAAmB,CAqBrB;AAED,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,cAAc,GAAG,SAAS,GACtC,mBAAmB,CAmBrB"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Framework usage notes
3
+ *
4
+ * Short, framework-specific guidance attached to `get_component` responses
5
+ * when the caller asks for `framework: "react"` or `"angular"` — the import
6
+ * line, the event-prop naming rule, and (when the component is a form
7
+ * control) how it binds into that framework's forms. Naming follows the
8
+ * rules in `.claude/plans/framework-support/README.md` section 4.1, reused
9
+ * here via `@nysds/codegen` rather than re-derived.
10
+ */
11
+ import { eventToAngularOutput, eventToReactProp, tagToSubpath, } from "@nysds/codegen";
12
+ const FORM_CONTROL_LABEL = {
13
+ value: "value",
14
+ checked: "checked state",
15
+ files: "selected files",
16
+ };
17
+ export function buildReactUsageNotes(tagName, className, formControl) {
18
+ const subpath = tagToSubpath(tagName);
19
+ const changeProp = formControl
20
+ ? eventToReactProp(formControl.changeEvent)
21
+ : undefined;
22
+ const inputProp = formControl?.inputEvent !== undefined
23
+ ? eventToReactProp(formControl.inputEvent)
24
+ : undefined;
25
+ return {
26
+ package: "@nysds/react",
27
+ import: `import { ${className} } from "@nysds/react/${subpath}";`,
28
+ events: "Events map to onNys* props (nys-change -> onNysChange). The handler receives the typed CustomEvent, so e.detail autocompletes.",
29
+ forms: formControl
30
+ ? `Form control (${formControl.kind}). For a controlled component, bind ${formControl.kind} and update state from ${changeProp}${inputProp ? ` (or ${inputProp} for every keystroke)` : ""}; re-rendering with the same ${FORM_CONTROL_LABEL[formControl.kind]} snaps the element back to your state. See get_guide({ topic: "installation", framework: "react" }) for React Hook Form and uncontrolled-form patterns.`
31
+ : undefined,
32
+ };
33
+ }
34
+ export function buildAngularUsageNotes(tagName, className, formControl) {
35
+ const subpath = tagToSubpath(tagName);
36
+ const angularClass = `${className}Component`;
37
+ const changeOutput = formControl
38
+ ? eventToAngularOutput(formControl.changeEvent)
39
+ : undefined;
40
+ return {
41
+ package: "@nysds/angular",
42
+ import: `import { ${angularClass} } from "@nysds/angular/${subpath}";`,
43
+ events: `Events map to camelCase outputs (nys-change -> (nysChange)); event.detail is typed.${changeOutput
44
+ ? ` This component's change output is (${changeOutput}).`
45
+ : ""}`,
46
+ forms: formControl
47
+ ? 'Implements ControlValueAccessor: works with [(ngModel)], formControlName (Reactive Forms), and Signal Forms [formField] with no CUSTOM_ELEMENTS_SCHEMA. Add the nysControlErrors directive to let Angular own validation display instead of the component\'s own errorMessage/showError. See get_guide({ topic: "installation", framework: "angular" }).'
48
+ : undefined,
49
+ };
50
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Framework package index
3
+ *
4
+ * Reads `data/frameworks.json`, written by `scripts/sync-guides.mjs` from
5
+ * `packages/react/package.json` and `packages/angular/package.json`. Gives
6
+ * tools and resources the published package name and version without
7
+ * hand-maintaining either.
8
+ */
9
+ export interface FrameworkPackageInfo {
10
+ packageName: string;
11
+ version: string;
12
+ }
13
+ export interface FrameworksIndex {
14
+ react: FrameworkPackageInfo;
15
+ angular: FrameworkPackageInfo;
16
+ }
17
+ export declare function getFrameworksIndex(): FrameworksIndex;
18
+ //# sourceMappingURL=frameworks-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frameworks-data.d.ts","sourceRoot":"","sources":["../../src/lib/frameworks-data.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,oBAAoB,CAAC;IAC5B,OAAO,EAAE,oBAAoB,CAAC;CAC/B;AAiBD,wBAAgB,kBAAkB,IAAI,eAAe,CAcpD"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Framework package index
3
+ *
4
+ * Reads `data/frameworks.json`, written by `scripts/sync-guides.mjs` from
5
+ * `packages/react/package.json` and `packages/angular/package.json`. Gives
6
+ * tools and resources the published package name and version without
7
+ * hand-maintaining either.
8
+ */
9
+ import { readFileSync, existsSync } from "node:fs";
10
+ import { resolve, dirname } from "node:path";
11
+ import { fileURLToPath } from "node:url";
12
+ const __dirname = dirname(fileURLToPath(import.meta.url));
13
+ let cached = null;
14
+ function getFrameworksDataPath() {
15
+ const candidates = [
16
+ resolve(__dirname, "../../data/frameworks.json"),
17
+ resolve(process.cwd(), "data/frameworks.json"),
18
+ ];
19
+ for (const path of candidates) {
20
+ if (existsSync(path))
21
+ return path;
22
+ }
23
+ throw new Error(`data/frameworks.json not found. Searched paths:\n${candidates.join("\n")}`);
24
+ }
25
+ export function getFrameworksIndex() {
26
+ if (cached)
27
+ return cached;
28
+ try {
29
+ cached = JSON.parse(readFileSync(getFrameworksDataPath(), "utf-8"));
30
+ }
31
+ catch (error) {
32
+ console.error("Warning: Could not load data/frameworks.json:", error);
33
+ cached = {
34
+ react: { packageName: "@nysds/react", version: "unknown" },
35
+ angular: { packageName: "@nysds/angular", version: "unknown" },
36
+ };
37
+ }
38
+ return cached;
39
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Framework Resources
3
+ *
4
+ * MCP resources for NYSDS framework packages (@nysds/react, @nysds/angular).
5
+ *
6
+ * Resources:
7
+ * - nysds://frameworks - Index of framework packages with version and guide URI
8
+ * - nysds://frameworks/react - @nysds/react guide (synced from its README)
9
+ * - nysds://frameworks/angular - @nysds/angular guide (synced from its README)
10
+ */
11
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
12
+ export declare function registerFrameworkResources(server: McpServer): void;
13
+ //# sourceMappingURL=frameworks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frameworks.d.ts","sourceRoot":"","sources":["../../src/resources/frameworks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAezE,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA8ElE"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Framework Resources
3
+ *
4
+ * MCP resources for NYSDS framework packages (@nysds/react, @nysds/angular).
5
+ *
6
+ * Resources:
7
+ * - nysds://frameworks - Index of framework packages with version and guide URI
8
+ * - nysds://frameworks/react - @nysds/react guide (synced from its README)
9
+ * - nysds://frameworks/angular - @nysds/angular guide (synced from its README)
10
+ */
11
+ import { readFileSync } from "node:fs";
12
+ import { join, dirname } from "node:path";
13
+ import { fileURLToPath } from "node:url";
14
+ import { getFrameworksIndex } from "../lib/frameworks-data.js";
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = dirname(__filename);
17
+ const GUIDES_DIR = join(__dirname, "../../data/guides/frameworks");
18
+ function loadFrameworkGuide(framework) {
19
+ try {
20
+ return readFileSync(join(GUIDES_DIR, `${framework}.md`), "utf-8");
21
+ }
22
+ catch {
23
+ return `Framework guide not found: ${framework}. Run "npm run sync:guides -w @nysds/mcp-server".`;
24
+ }
25
+ }
26
+ export function registerFrameworkResources(server) {
27
+ // nysds://frameworks - Index of framework packages
28
+ server.resource("frameworks", "nysds://frameworks", {
29
+ description: "Index of NYSDS framework packages (@nysds/react, @nysds/angular) with their published version and guide resource URI",
30
+ mimeType: "application/json",
31
+ }, async () => {
32
+ const index = getFrameworksIndex();
33
+ const list = [
34
+ {
35
+ id: "react",
36
+ packageName: index.react.packageName,
37
+ version: index.react.version,
38
+ guideUri: "nysds://frameworks/react",
39
+ },
40
+ {
41
+ id: "angular",
42
+ packageName: index.angular.packageName,
43
+ version: index.angular.version,
44
+ guideUri: "nysds://frameworks/angular",
45
+ },
46
+ ];
47
+ return {
48
+ contents: [
49
+ {
50
+ uri: "nysds://frameworks",
51
+ mimeType: "application/json",
52
+ text: JSON.stringify(list, null, 2),
53
+ },
54
+ ],
55
+ };
56
+ });
57
+ // nysds://frameworks/react - @nysds/react guide
58
+ server.resource("frameworks-react", "nysds://frameworks/react", {
59
+ description: "@nysds/react install, usage, forms, SSR, and troubleshooting guide",
60
+ mimeType: "text/markdown",
61
+ }, async () => ({
62
+ contents: [
63
+ {
64
+ uri: "nysds://frameworks/react",
65
+ mimeType: "text/markdown",
66
+ text: loadFrameworkGuide("react"),
67
+ },
68
+ ],
69
+ }));
70
+ // nysds://frameworks/angular - @nysds/angular guide
71
+ server.resource("frameworks-angular", "nysds://frameworks/angular", {
72
+ description: "@nysds/angular install, usage, forms, SSR, and troubleshooting guide",
73
+ mimeType: "text/markdown",
74
+ }, async () => ({
75
+ contents: [
76
+ {
77
+ uri: "nysds://frameworks/angular",
78
+ mimeType: "text/markdown",
79
+ text: loadFrameworkGuide("angular"),
80
+ },
81
+ ],
82
+ }));
83
+ }
@@ -2,7 +2,55 @@
2
2
  * Utility Tools
3
3
  *
4
4
  * MCP tools for NYSDS utility classes.
5
+ *
6
+ * The class lists this tool returns are RENDERED from the scale constants
7
+ * below. Those constants mirror the Sass sources that actually generate the
8
+ * stylesheet:
9
+ *
10
+ * - packages/styles/src/utilities/_config.scss ($spacing, $opacity-values,
11
+ * $zindex-values, $display-values,
12
+ * $breakpoints, $flex-columns)
13
+ * - packages/styles/src/utilities/_layout-grid.scss ($responsive-gap-suffixes)
14
+ * - packages/styles/src/core/typography.scss ($body-sizes, $ui-sizes,
15
+ * $ui-underline-styles, $display-sizes)
16
+ *
17
+ * Do not hand-write a class name into the markdown. Add it to a scale and let
18
+ * the renderer emit it, so a name can never appear here without a scale entry
19
+ * behind it.
20
+ *
21
+ * `npm run verify:utility-docs` compiles the stylesheet and asserts that every
22
+ * class this tool names exists in it. Run it after touching any scale.
5
23
  */
6
24
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
25
+ declare const UTILITY_DOCS: {
26
+ grid: string;
27
+ flex: string;
28
+ spacing: string;
29
+ display: string;
30
+ opacity: string;
31
+ zindex: string;
32
+ typography: string;
33
+ responsive: string;
34
+ componentSpacing: string;
35
+ };
36
+ /**
37
+ * Classes the reference deliberately names in order to say they do NOT exist.
38
+ *
39
+ * These are the names people reach for out of habit from other frameworks.
40
+ * Saying so explicitly is more useful than silence, but it means the docs
41
+ * mention class names the stylesheet does not define, which would otherwise
42
+ * trip the verifier.
43
+ *
44
+ * `verify-utility-docs.mjs` asserts each of these is genuinely absent, so if
45
+ * NYSDS ever adds one, the stale warning fails the check instead of quietly
46
+ * misinforming people.
47
+ */
48
+ declare const KNOWN_ABSENT: readonly string[];
49
+ /**
50
+ * Exported so `src/scripts/verify-utility-docs.mjs` can assert that every class
51
+ * named in this reference exists in the compiled stylesheet — and that every
52
+ * class named in KNOWN_ABSENT still does not.
53
+ */
54
+ export { UTILITY_DOCS, KNOWN_ABSENT };
7
55
  export declare function registerUtilityTools(server: McpServer): void;
8
56
  //# sourceMappingURL=utility-tools.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utility-tools.d.ts","sourceRoot":"","sources":["../../src/tools/utility-tools.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAmPzE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA8D5D"}
1
+ {"version":3,"file":"utility-tools.d.ts","sourceRoot":"","sources":["../../src/tools/utility-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAiLzE,QAAA,MAAM,YAAY;;;;;;;;;;CAyOjB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,YAAY,EAAE,SAAS,MAAM,EAUlC,CAAC;AAEF;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;AAEtC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA8D5D"}