@storybook/mcp 0.0.3 → 0.0.4
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.
- package/dist/index.js +69 -2
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as v from "valibot";
|
|
|
5
5
|
|
|
6
6
|
//#region package.json
|
|
7
7
|
var name = "@storybook/mcp";
|
|
8
|
-
var version = "0.0.
|
|
8
|
+
var version = "0.0.4";
|
|
9
9
|
var description = "MCP server that serves knowledge about your components based on your Storybook stories and documentation";
|
|
10
10
|
|
|
11
11
|
//#endregion
|
|
@@ -26,7 +26,7 @@ const ComponentManifest = v.object({
|
|
|
26
26
|
id: v.string(),
|
|
27
27
|
summary: v.exactOptional(v.string()),
|
|
28
28
|
examples: v.exactOptional(v.array(Example)),
|
|
29
|
-
|
|
29
|
+
reactDocgen: v.exactOptional(v.custom(() => true))
|
|
30
30
|
});
|
|
31
31
|
const ComponentManifestMap = v.object({
|
|
32
32
|
v: v.number(),
|
|
@@ -125,6 +125,54 @@ function dedent(templ, ...values) {
|
|
|
125
125
|
return string;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/utils/parse-react-docgen.ts
|
|
130
|
+
function serializeTsType(tsType) {
|
|
131
|
+
if (!tsType) return void 0;
|
|
132
|
+
if ("raw" in tsType && typeof tsType.raw === "string" && tsType.raw.trim().length > 0) return tsType.raw;
|
|
133
|
+
if (!tsType.name) return void 0;
|
|
134
|
+
if ("elements" in tsType) {
|
|
135
|
+
const serializeElements = () => (tsType.elements ?? []).map((el) => serializeTsType(el) ?? "unknown");
|
|
136
|
+
switch (tsType.name) {
|
|
137
|
+
case "union": return serializeElements().join(" | ");
|
|
138
|
+
case "intersection": return serializeElements().join(" & ");
|
|
139
|
+
case "Array": return `${serializeTsType((tsType.elements ?? [])[0]) ?? "unknown"}[]`;
|
|
140
|
+
case "tuple": return `[${serializeElements().join(", ")}]`;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if ("value" in tsType && tsType.name === "literal") return tsType.value;
|
|
144
|
+
if ("signature" in tsType && tsType.name === "signature") {
|
|
145
|
+
if (tsType.type === "function") {
|
|
146
|
+
const args = (tsType.signature?.arguments ?? []).map((a) => {
|
|
147
|
+
const argType = serializeTsType(a.type) ?? "any";
|
|
148
|
+
return `${a.name}: ${argType}`;
|
|
149
|
+
});
|
|
150
|
+
const ret = serializeTsType(tsType.signature?.return) ?? "void";
|
|
151
|
+
return `(${args.join(", ")}) => ${ret}`;
|
|
152
|
+
}
|
|
153
|
+
if (tsType.type === "object") return `{ ${(tsType.signature?.properties ?? []).map((p) => {
|
|
154
|
+
const req = Boolean(p.value?.required);
|
|
155
|
+
const propType = serializeTsType(p.value) ?? "any";
|
|
156
|
+
return `${p.key}${req ? "" : "?"}: ${propType}`;
|
|
157
|
+
}).join("; ")} }`;
|
|
158
|
+
return "unknown";
|
|
159
|
+
}
|
|
160
|
+
if ("elements" in tsType) {
|
|
161
|
+
const inner = (tsType.elements ?? []).map((el) => serializeTsType(el) ?? "unknown");
|
|
162
|
+
if (inner.length > 0) return `${tsType.name}<${inner.join(", ")}>`;
|
|
163
|
+
}
|
|
164
|
+
return tsType.name;
|
|
165
|
+
}
|
|
166
|
+
const parseReactDocgen = (reactDocgen) => {
|
|
167
|
+
const props = reactDocgen?.props ?? {};
|
|
168
|
+
return { props: Object.fromEntries(Object.entries(props).map(([propName, prop]) => [propName, {
|
|
169
|
+
description: prop.description,
|
|
170
|
+
type: serializeTsType(prop.tsType ?? prop.type),
|
|
171
|
+
defaultValue: prop.defaultValue?.value,
|
|
172
|
+
required: prop.required
|
|
173
|
+
}])) };
|
|
174
|
+
};
|
|
175
|
+
|
|
128
176
|
//#endregion
|
|
129
177
|
//#region src/utils/format-manifest.ts
|
|
130
178
|
function formatComponentManifest(componentManifest) {
|
|
@@ -150,6 +198,25 @@ function formatComponentManifest(componentManifest) {
|
|
|
150
198
|
</example>`);
|
|
151
199
|
parts.push(exampleParts.join("\n"));
|
|
152
200
|
}
|
|
201
|
+
if (componentManifest.reactDocgen) {
|
|
202
|
+
const parsedDocgen = parseReactDocgen(componentManifest.reactDocgen);
|
|
203
|
+
const propEntries = Object.entries(parsedDocgen.props);
|
|
204
|
+
if (propEntries.length > 0) {
|
|
205
|
+
parts.push("<props>");
|
|
206
|
+
for (const [propName, propInfo] of propEntries) {
|
|
207
|
+
parts.push(dedent`<prop>
|
|
208
|
+
<prop_name>${propName}</prop_name>`);
|
|
209
|
+
if (propInfo.description !== void 0) parts.push(dedent`<prop_description>
|
|
210
|
+
${propInfo.description}
|
|
211
|
+
</prop_description>`);
|
|
212
|
+
if (propInfo.type !== void 0) parts.push(dedent`<prop_type>${propInfo.type}</prop_type>`);
|
|
213
|
+
if (propInfo.required !== void 0) parts.push(dedent`<prop_required>${propInfo.required}</prop_required>`);
|
|
214
|
+
if (propInfo.defaultValue !== void 0) parts.push(dedent`<prop_default>${propInfo.defaultValue}</prop_default>`);
|
|
215
|
+
parts.push("</prop>");
|
|
216
|
+
}
|
|
217
|
+
parts.push("</props>");
|
|
218
|
+
}
|
|
219
|
+
}
|
|
153
220
|
parts.push("</component>");
|
|
154
221
|
return parts.join("\n");
|
|
155
222
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "MCP server that serves knowledge about your components based on your Storybook stories and documentation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@tsconfig/node24": "^24.0.1",
|
|
37
37
|
"@types/node": "20.19.0",
|
|
38
38
|
"@vitest/coverage-v8": "3.2.4",
|
|
39
|
+
"react-docgen": "^8.0.2",
|
|
39
40
|
"srvx": "^0.8.16",
|
|
40
41
|
"tsdown": "^0.15.9",
|
|
41
42
|
"typescript": "^5.9.3",
|