@storybook/mcp 0.4.0 → 0.4.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.
- package/dist/index.d.ts +8 -22
- package/dist/index.js +10 -10
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { McpServer } from "tmcp";
|
|
2
2
|
import * as v from "valibot";
|
|
3
|
-
import { Documentation } from "react-docgen";
|
|
4
|
-
import { ComponentDoc } from "react-docgen-typescript";
|
|
5
3
|
|
|
6
4
|
//#region src/types.d.ts
|
|
7
5
|
/**
|
|
8
6
|
* Represents a single Storybook source (local or remote).
|
|
9
7
|
*/
|
|
10
8
|
type Source = {
|
|
11
|
-
/** Unique identifier for this source (e.g., 'local', 'tetra') */
|
|
12
|
-
|
|
13
|
-
/** Human-readable title (e.g., 'Local', 'Tetra Design System') */
|
|
14
|
-
title: string;
|
|
15
|
-
/** Remote URL, undefined for local source */
|
|
9
|
+
/** Unique identifier for this source (e.g., 'local', 'tetra') */id: string; /** Human-readable title (e.g., 'Local', 'Tetra Design System') */
|
|
10
|
+
title: string; /** Remote URL, undefined for local source */
|
|
16
11
|
url?: string;
|
|
17
12
|
};
|
|
18
13
|
/**
|
|
@@ -21,8 +16,7 @@ type Source = {
|
|
|
21
16
|
type SourceManifests = {
|
|
22
17
|
source: Source;
|
|
23
18
|
componentManifest: ComponentManifestMap;
|
|
24
|
-
docsManifest?: DocsManifestMap;
|
|
25
|
-
/** Error message if fetching this source failed */
|
|
19
|
+
docsManifest?: DocsManifestMap; /** Error message if fetching this source failed */
|
|
26
20
|
error?: string;
|
|
27
21
|
};
|
|
28
22
|
/**
|
|
@@ -56,8 +50,7 @@ type StorybookContext = {
|
|
|
56
50
|
onListAllDocumentation?: (params: {
|
|
57
51
|
context: StorybookContext;
|
|
58
52
|
manifests: AllManifests;
|
|
59
|
-
resultText: string;
|
|
60
|
-
/** Present in multi-source mode — all source manifests including errors */
|
|
53
|
+
resultText: string; /** Present in multi-source mode — all source manifests including errors */
|
|
61
54
|
sources?: SourceManifests[];
|
|
62
55
|
}) => void | Promise<void>;
|
|
63
56
|
/**
|
|
@@ -95,13 +88,6 @@ declare const Doc: v.ObjectSchema<{
|
|
|
95
88
|
}, undefined>, undefined>;
|
|
96
89
|
}, undefined>;
|
|
97
90
|
type Doc = v.InferOutput<typeof Doc>;
|
|
98
|
-
/**
|
|
99
|
-
* Component documentation from react-docgen-typescript, extended with export name.
|
|
100
|
-
* Matches the shape produced by Storybook's manifest generator.
|
|
101
|
-
*/
|
|
102
|
-
type ComponentDocWithExportName = ComponentDoc & {
|
|
103
|
-
exportName: string;
|
|
104
|
-
};
|
|
105
91
|
declare const ComponentManifest: v.ObjectSchema<{
|
|
106
92
|
readonly id: v.StringSchema<undefined>;
|
|
107
93
|
readonly path: v.StringSchema<undefined>;
|
|
@@ -119,8 +105,8 @@ declare const ComponentManifest: v.ObjectSchema<{
|
|
|
119
105
|
readonly message: v.StringSchema<undefined>;
|
|
120
106
|
}, undefined>, undefined>;
|
|
121
107
|
}, undefined>, undefined>, undefined>;
|
|
122
|
-
readonly reactDocgen: v.OptionalSchema<v.
|
|
123
|
-
readonly reactDocgenTypescript: v.OptionalSchema<v.
|
|
108
|
+
readonly reactDocgen: v.OptionalSchema<v.AnySchema, undefined>;
|
|
109
|
+
readonly reactDocgenTypescript: v.OptionalSchema<v.AnySchema, undefined>;
|
|
124
110
|
readonly docs: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
125
111
|
readonly id: v.StringSchema<undefined>;
|
|
126
112
|
readonly name: v.StringSchema<undefined>;
|
|
@@ -161,8 +147,8 @@ declare const ComponentManifestMap: v.ObjectSchema<{
|
|
|
161
147
|
readonly message: v.StringSchema<undefined>;
|
|
162
148
|
}, undefined>, undefined>;
|
|
163
149
|
}, undefined>, undefined>, undefined>;
|
|
164
|
-
readonly reactDocgen: v.OptionalSchema<v.
|
|
165
|
-
readonly reactDocgenTypescript: v.OptionalSchema<v.
|
|
150
|
+
readonly reactDocgen: v.OptionalSchema<v.AnySchema, undefined>;
|
|
151
|
+
readonly reactDocgenTypescript: v.OptionalSchema<v.AnySchema, undefined>;
|
|
166
152
|
readonly docs: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.ObjectSchema<{
|
|
167
153
|
readonly id: v.StringSchema<undefined>;
|
|
168
154
|
readonly name: v.StringSchema<undefined>;
|
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.4.
|
|
8
|
+
var version = "0.4.1";
|
|
9
9
|
var description = "MCP server that serves knowledge about your components based on your Storybook stories and documentation";
|
|
10
10
|
|
|
11
11
|
//#endregion
|
|
@@ -47,8 +47,8 @@ const ComponentManifest = v.object({
|
|
|
47
47
|
summary: v.optional(v.string()),
|
|
48
48
|
import: v.optional(v.string()),
|
|
49
49
|
stories: v.optional(v.array(Story)),
|
|
50
|
-
reactDocgen: v.optional(v.
|
|
51
|
-
reactDocgenTypescript: v.optional(v.
|
|
50
|
+
reactDocgen: v.optional(v.any()),
|
|
51
|
+
reactDocgenTypescript: v.optional(v.any()),
|
|
52
52
|
docs: v.optional(v.record(v.string(), Doc))
|
|
53
53
|
});
|
|
54
54
|
const ComponentManifestMap = v.object({
|
|
@@ -107,11 +107,11 @@ const errorToMCPContent = (error) => {
|
|
|
107
107
|
/**
|
|
108
108
|
* Parses a JSON string and validates it against a Valibot schema
|
|
109
109
|
*/
|
|
110
|
-
function parseManifest({ jsonString, schema, name
|
|
110
|
+
function parseManifest({ jsonString, schema, name, url }) {
|
|
111
111
|
try {
|
|
112
112
|
return v.parse(v.pipe(v.string(), v.parseJson(), schema), jsonString);
|
|
113
113
|
} catch (error) {
|
|
114
|
-
throw new ManifestGetError(`Failed to parse ${name
|
|
114
|
+
throw new ManifestGetError(`Failed to parse ${name} manifest:
|
|
115
115
|
${error instanceof v.ValiError ? error.issues.map((i) => i.message).join("\n") : String(error)}`, url);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
@@ -301,8 +301,8 @@ function dedent(templ, ...values) {
|
|
|
301
301
|
const endentations = string.match(/(?:^|\n)( *)$/);
|
|
302
302
|
const endentation = endentations ? endentations[1] : "";
|
|
303
303
|
let indentedValue = value;
|
|
304
|
-
if (typeof value === "string" && value.includes("\n")) indentedValue = String(value).split("\n").map((str, i
|
|
305
|
-
return i
|
|
304
|
+
if (typeof value === "string" && value.includes("\n")) indentedValue = String(value).split("\n").map((str, i) => {
|
|
305
|
+
return i === 0 ? str : `${endentation}${str}`;
|
|
306
306
|
}).join("\n");
|
|
307
307
|
string += `${String(indentedValue)}${strings[i + 1]}`;
|
|
308
308
|
});
|
|
@@ -563,7 +563,7 @@ async function addListAllDocumentationTool(server, enabled) {
|
|
|
563
563
|
const ctx = server.ctx.custom;
|
|
564
564
|
if (ctx?.sources?.some((s) => s.url)) {
|
|
565
565
|
const multiSourceManifests = await getMultiSourceManifests(ctx.sources, ctx.request, ctx.manifestProvider);
|
|
566
|
-
const lists
|
|
566
|
+
const lists = formatMultiSourceManifestsToLists(multiSourceManifests);
|
|
567
567
|
const firstSuccess = multiSourceManifests.find((m) => !m.error);
|
|
568
568
|
if (firstSuccess) await ctx.onListAllDocumentation?.({
|
|
569
569
|
context: ctx,
|
|
@@ -571,12 +571,12 @@ async function addListAllDocumentationTool(server, enabled) {
|
|
|
571
571
|
componentManifest: firstSuccess.componentManifest,
|
|
572
572
|
docsManifest: firstSuccess.docsManifest
|
|
573
573
|
},
|
|
574
|
-
resultText: lists
|
|
574
|
+
resultText: lists,
|
|
575
575
|
sources: multiSourceManifests
|
|
576
576
|
});
|
|
577
577
|
return { content: [{
|
|
578
578
|
type: "text",
|
|
579
|
-
text: lists
|
|
579
|
+
text: lists
|
|
580
580
|
}] };
|
|
581
581
|
}
|
|
582
582
|
const manifests = await getManifests(ctx?.request, ctx?.manifestProvider);
|