@storybook/mcp 11.0.0-alpha.6 → 11.0.0-alpha.7
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/README.md +3 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +143 -27
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -151,6 +151,7 @@ type StorybookContext = {
|
|
|
151
151
|
input: { id: string; storybookId?: string };
|
|
152
152
|
foundDocumentation: ComponentManifest | Doc;
|
|
153
153
|
resultText: string;
|
|
154
|
+
resolvedStorybookId?: string;
|
|
154
155
|
}
|
|
155
156
|
| {
|
|
156
157
|
context: StorybookContext;
|
|
@@ -225,6 +226,7 @@ Type:
|
|
|
225
226
|
input: { id: string; storybookId?: string };
|
|
226
227
|
foundDocumentation: ComponentManifest | Doc;
|
|
227
228
|
resultText: string;
|
|
229
|
+
resolvedStorybookId?: string;
|
|
228
230
|
}
|
|
229
231
|
| {
|
|
230
232
|
context: StorybookContext;
|
|
@@ -236,6 +238,7 @@ Type:
|
|
|
236
238
|
Optional callback after `docs-show` runs:
|
|
237
239
|
|
|
238
240
|
- When a component/docs entry is found, receives `foundDocumentation` and `resultText`.
|
|
241
|
+
- When it is found in another source than `input.storybookId`, also receives that source as `resolvedStorybookId`.
|
|
239
242
|
- When not found, receives only `context` and `input`.
|
|
240
243
|
|
|
241
244
|
##### `sources`
|
package/dist/index.d.ts
CHANGED
|
@@ -689,17 +689,20 @@ type StorybookContext = {
|
|
|
689
689
|
};
|
|
690
690
|
} & ({
|
|
691
691
|
foundDocumentation: ComponentManifest | Doc;
|
|
692
|
-
resultText: string;
|
|
692
|
+
resultText: string; /** The source the documentation came from, set only when it is not `input.storybookId`. */
|
|
693
|
+
resolvedStorybookId?: string;
|
|
693
694
|
} | {
|
|
694
695
|
foundDocumentation?: never;
|
|
695
696
|
resultText?: never;
|
|
697
|
+
resolvedStorybookId?: never;
|
|
696
698
|
})) => void | Promise<void>;
|
|
697
699
|
/**
|
|
698
700
|
* Optional in-process resolver for a single component or docs entry, used in
|
|
699
701
|
* Storybook's dev server when `docgenServer` is enabled. When set,
|
|
700
702
|
* single-entry tools (`docs-show`, `docs-show-story`) call
|
|
701
703
|
* this instead of fetching the (potentially all-component) manifest index, so a
|
|
702
|
-
*
|
|
704
|
+
* lookup that finds its entry never triggers docgen extraction for every component.
|
|
705
|
+
* A `docs-show` miss still reads the index, to suggest close ids.
|
|
703
706
|
*
|
|
704
707
|
* Returns the fully-resolved component or doc in `@storybook/mcp`'s internal
|
|
705
708
|
* shape (already adapted from the open-service payloads), or `undefined` when the
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_ttmoxus8kgs from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_ttmoxus8kgs from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_ttmoxus8kgs from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_ttmoxus8kgs.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_ttmoxus8kgs.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_ttmoxus8kgs.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -24,7 +24,7 @@ import { HttpTransport } from "@tmcp/transport-http";
|
|
|
24
24
|
// package.json
|
|
25
25
|
var package_default = {
|
|
26
26
|
name: "@storybook/mcp",
|
|
27
|
-
version: "11.0.0-alpha.
|
|
27
|
+
version: "11.0.0-alpha.7",
|
|
28
28
|
description: "MCP server that serves knowledge about your components based on your Storybook stories and documentation",
|
|
29
29
|
keywords: [
|
|
30
30
|
"mcp",
|
|
@@ -839,6 +839,15 @@ Only use properties explicitly documented or shown in example stories. Only refe
|
|
|
839
839
|
|
|
840
840
|
- With multiple sources configured, **${ref("docs.list")}** returns entries from every source; pass \`storybookId\` to **${ref("docs.show")}** to scope one.
|
|
841
841
|
`;
|
|
842
|
+
async function listEntryNames(access) {
|
|
843
|
+
if (access.listNames)
|
|
844
|
+
return access.listNames();
|
|
845
|
+
let manifests = await access.list({ withStoryIds: !1 });
|
|
846
|
+
return [
|
|
847
|
+
...Object.values(manifests.componentManifest.components),
|
|
848
|
+
...Object.values(manifests.docsManifest?.docs ?? {})
|
|
849
|
+
].map(({ id, name }) => ({ id, name }));
|
|
850
|
+
}
|
|
842
851
|
function emptyManifests() {
|
|
843
852
|
return { componentManifest: { v: 1, components: {} } };
|
|
844
853
|
}
|
|
@@ -874,6 +883,10 @@ function extractDocsSummary(content) {
|
|
|
874
883
|
if (result = result.replace(/<[^>]+>/g, ""), result = result.replace(/\s+/g, " ").trim(), !!result)
|
|
875
884
|
return result.length > 90 ? `${result.slice(0, 90)}...` : result;
|
|
876
885
|
}
|
|
886
|
+
var docgenTypeString = (propType) => {
|
|
887
|
+
let members = (propType?.value ?? []).map((member) => member.value);
|
|
888
|
+
return members.length > 0 ? members.join(" | ") : propType?.raw ?? propType?.name;
|
|
889
|
+
};
|
|
877
890
|
function serializeTsType(tsType) {
|
|
878
891
|
if (tsType) {
|
|
879
892
|
if ("raw" in tsType && typeof tsType.raw == "string" && tsType.raw.trim().length > 0)
|
|
@@ -940,8 +953,9 @@ var parseReactDocgen = (reactDocgen) => {
|
|
|
940
953
|
{
|
|
941
954
|
description: prop.description || void 0,
|
|
942
955
|
// RDT uses prop.type.name as a flat string (e.g. "() => void", "{ id: string }")
|
|
943
|
-
// For enums, prefer prop.type.raw which has the full union
|
|
944
|
-
|
|
956
|
+
// For enums, prefer prop.type.raw which has the full union; for a named-alias enum
|
|
957
|
+
// raw only holds the alias name, so use the expanded members instead (issue #35778)
|
|
958
|
+
type: docgenTypeString(prop.type),
|
|
945
959
|
defaultValue: prop.defaultValue?.value,
|
|
946
960
|
required: prop.required
|
|
947
961
|
}
|
|
@@ -1034,8 +1048,9 @@ function formatPropsSection(parsedDocgen, options = {}) {
|
|
|
1034
1048
|
let title = options.title ?? "## Props", typeName = options.typeName ?? "Props", parts = [];
|
|
1035
1049
|
parts.push(title), parts.push(""), parts.push("```"), parts.push(`export type ${typeName} = {`);
|
|
1036
1050
|
for (let [propName, propInfo] of propEntries) {
|
|
1037
|
-
let type = propInfo.type ?? "any", isRequired = propInfo.required ?? !0, hasDefault = propInfo.defaultValue !== void 0;
|
|
1038
|
-
|
|
1051
|
+
let type = propInfo.type ?? "any", isRequired = propInfo.required ?? !0, hasDefault = propInfo.defaultValue !== void 0, { description: description22 } = propInfo;
|
|
1052
|
+
description22 !== void 0 && (description22.includes(`
|
|
1053
|
+
`) ? (parts.push(" /**"), parts.push(` ${description22}`), parts.push(" */")) : parts.push(` /** ${description22} */`));
|
|
1039
1054
|
let propLine = ` ${propName}`;
|
|
1040
1055
|
isRequired || (propLine += "?"), propLine += `: ${type}`, hasDefault && (propLine += ` = ${propInfo.defaultValue}`), propLine += ";", parts.push(propLine);
|
|
1041
1056
|
}
|
|
@@ -1070,9 +1085,9 @@ function formatSubcomponentsSection(subcomponents) {
|
|
|
1070
1085
|
}
|
|
1071
1086
|
function formatComponentManifest(componentManifest) {
|
|
1072
1087
|
let parts = [], parsedDocgen = getParsedDocgen(componentManifest), jsDocTags = getComponentTags(componentManifest, parsedDocgen);
|
|
1073
|
-
parts.push(`# ${componentManifest.name}`), parts.push(""), parts.push(`ID: ${componentManifest.id}`), parts.push(""), parts.push(...formatJsDocTags(jsDocTags, isTopJsDocTag)), componentManifest.description && (parts.push(componentManifest.description), parts.push("")), parts.push(...formatJsDocTags(jsDocTags, isGenericJsDocTag)), parts.push(...formatExampleJsDocTags(jsDocTags))
|
|
1088
|
+
parts.push(`# ${componentManifest.name}`), parts.push(""), parts.push(`ID: ${componentManifest.id}`), parts.push(""), parts.push(...formatJsDocTags(jsDocTags, isTopJsDocTag)), componentManifest.description && (parts.push(componentManifest.description), parts.push("")), parts.push(...formatJsDocTags(jsDocTags, isGenericJsDocTag)), parts.push(...formatExampleJsDocTags(jsDocTags));
|
|
1074
1089
|
let { apiDescription } = componentManifest;
|
|
1075
|
-
apiDescription
|
|
1090
|
+
apiDescription ? (parts.push(apiDescription), parts.push("")) : parts.push(...formatPropsSection(parsedDocgen)), parts.push(...formatSubcomponentsSection(componentManifest.subcomponents));
|
|
1076
1091
|
let stories = Array.isArray(componentManifest.stories) ? componentManifest.stories : [];
|
|
1077
1092
|
if (stories.length > 0) {
|
|
1078
1093
|
parts.push("## Stories"), parts.push("");
|
|
@@ -1088,7 +1103,7 @@ function formatComponentManifest(componentManifest) {
|
|
|
1088
1103
|
parts.push("");
|
|
1089
1104
|
}
|
|
1090
1105
|
}
|
|
1091
|
-
if (
|
|
1106
|
+
if (componentManifest.docs && Object.keys(componentManifest.docs).length > 0) {
|
|
1092
1107
|
let docsWithContent = Object.values(componentManifest.docs).filter(
|
|
1093
1108
|
(doc) => (doc.content ?? "").trim().length > 0
|
|
1094
1109
|
);
|
|
@@ -1106,10 +1121,14 @@ function formatDocsManifest(doc) {
|
|
|
1106
1121
|
|
|
1107
1122
|
${doc.content ?? ""}`;
|
|
1108
1123
|
}
|
|
1124
|
+
var NO_ENTRIES = "No components or docs entries found. A component is listed here once it has a story.";
|
|
1109
1125
|
function formatManifestsToLists(manifests, options = {}) {
|
|
1126
|
+
let components = Object.values(manifests.componentManifest.components);
|
|
1127
|
+
if (components.length === 0 && Object.keys(manifests.docsManifest?.docs ?? {}).length === 0)
|
|
1128
|
+
return NO_ENTRIES;
|
|
1110
1129
|
let parts = [];
|
|
1111
1130
|
parts.push("# Components"), parts.push("");
|
|
1112
|
-
for (let component of
|
|
1131
|
+
for (let component of components)
|
|
1113
1132
|
if (parts.push(formatComponentLine(component)), options.withStoryIds && Array.isArray(component.stories))
|
|
1114
1133
|
for (let story of component.stories)
|
|
1115
1134
|
parts.push(formatStorySubLine(story));
|
|
@@ -1133,7 +1152,11 @@ function formatMultiSourceManifestsToLists(sources, options = {}) {
|
|
|
1133
1152
|
parts.push(formatRequiresOwnMcpNotice(source, notice.endpoint, { includeHeader: !1 })), parts.push("");
|
|
1134
1153
|
continue;
|
|
1135
1154
|
}
|
|
1136
|
-
let components = Object.values(manifests?.componentManifest.components ?? {});
|
|
1155
|
+
let components = Object.values(manifests?.componentManifest.components ?? {}), docs = Object.values(manifests?.docsManifest?.docs ?? {});
|
|
1156
|
+
if (components.length === 0 && docs.length === 0) {
|
|
1157
|
+
parts.push(NO_ENTRIES), parts.push("");
|
|
1158
|
+
continue;
|
|
1159
|
+
}
|
|
1137
1160
|
if (components.length > 0) {
|
|
1138
1161
|
parts.push("## Components"), parts.push("");
|
|
1139
1162
|
for (let component of components)
|
|
@@ -1142,7 +1165,6 @@ function formatMultiSourceManifestsToLists(sources, options = {}) {
|
|
|
1142
1165
|
parts.push(formatStorySubLine(story));
|
|
1143
1166
|
parts.push("");
|
|
1144
1167
|
}
|
|
1145
|
-
let docs = Object.values(manifests?.docsManifest?.docs ?? {});
|
|
1146
1168
|
if (docs.length > 0) {
|
|
1147
1169
|
parts.push("## Docs"), parts.push("");
|
|
1148
1170
|
for (let doc of docs)
|
|
@@ -1542,6 +1564,28 @@ ${listings.map((listing) => `- ${listing.source.title}: ${listing.error}`).join(
|
|
|
1542
1564
|
);
|
|
1543
1565
|
return listings;
|
|
1544
1566
|
}
|
|
1567
|
+
function tokenize(value) {
|
|
1568
|
+
let words2 = value.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean), runs = /* @__PURE__ */ new Set();
|
|
1569
|
+
for (let start = 0; start < words2.length; start++) {
|
|
1570
|
+
let longestEnd = Math.min(words2.length, start + 5);
|
|
1571
|
+
for (let end = start + 1; end <= longestEnd; end++)
|
|
1572
|
+
runs.add(words2.slice(start, end).join(""));
|
|
1573
|
+
}
|
|
1574
|
+
return runs;
|
|
1575
|
+
}
|
|
1576
|
+
function suggestEntries(id, candidates) {
|
|
1577
|
+
let componentId = id.split("--")[0], sourceIds = new Set(candidates.map((candidate) => candidate.storybookId)), wanted = new Set([...tokenize(componentId)].filter((token) => !sourceIds.has(token))), idCountByToken = /* @__PURE__ */ new Map();
|
|
1578
|
+
for (let candidate of candidates)
|
|
1579
|
+
for (let token of tokenize(candidate.id))
|
|
1580
|
+
idCountByToken.set(token, (idCountByToken.get(token) ?? 0) + 1);
|
|
1581
|
+
let maxIdCount = Math.max(2, candidates.length / 4), distinctive = [...wanted].filter((token) => (idCountByToken.get(token) ?? 0) <= maxIdCount), scoreOf = (candidate) => {
|
|
1582
|
+
let candidateTokens = /* @__PURE__ */ new Set([...tokenize(candidate.id), ...tokenize(candidate.name)]), sharedWords = distinctive.filter((token) => candidateTokens.has(token)).length, joinedName = candidate.name.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
1583
|
+
return sharedWords + (wanted.has(joinedName) ? 2 : 0);
|
|
1584
|
+
}, tierOf = (candidate) => candidate.id === id ? 0 : candidate.id === componentId ? 1 : 2;
|
|
1585
|
+
return candidates.map((candidate) => ({ candidate, tier: tierOf(candidate), score: scoreOf(candidate) })).filter(({ tier, score }) => tier < 2 || score > 0).sort(
|
|
1586
|
+
(a, b) => a.tier - b.tier || b.score - a.score || a.candidate.id.localeCompare(b.candidate.id)
|
|
1587
|
+
).slice(0, 5).map(({ candidate }) => candidate);
|
|
1588
|
+
}
|
|
1545
1589
|
function isWhitespace(code) {
|
|
1546
1590
|
return code === 32 || code === 9 || code === 10 || code === 13;
|
|
1547
1591
|
}
|
|
@@ -1620,9 +1664,34 @@ Returns the first ${MAX_STORIES_TO_SHOW} stories (including story IDs) with code
|
|
|
1620
1664
|
|
|
1621
1665
|
Example: id="button" returns Primary, Secondary, Large stories with code like <Button variant="primary" size="large"> showing actual prop combinations.`;
|
|
1622
1666
|
}
|
|
1623
|
-
function
|
|
1624
|
-
let
|
|
1625
|
-
return
|
|
1667
|
+
function formatShowCall({ id, storybookId }, ctx2) {
|
|
1668
|
+
let tool = getToolName(ctx2)(DOCS_METHOD_REFS.show);
|
|
1669
|
+
return ctx2.transport === "cli" ? `${tool} --id ${id}${storybookId ? ` --storybookId ${storybookId}` : ""}` : `${tool} ${JSON.stringify({ id, storybookId })}`;
|
|
1670
|
+
}
|
|
1671
|
+
function formatEntryNotFound({ id, storybookId, suggestions = [], unreadableSources = [] }, ctx2) {
|
|
1672
|
+
let suffix = storybookId ? ` in source "${storybookId}"` : "", notFound = `Component or Docs Entry not found: "${id}"${suffix}.`, listHint = `Use the ${getToolName(ctx2)(DOCS_METHOD_REFS.list)} tool to see available components and documentation entries.`;
|
|
1673
|
+
return suggestions.length === 0 && unreadableSources.length === 0 ? `${notFound} ${listHint}` : [
|
|
1674
|
+
notFound,
|
|
1675
|
+
...suggestions.length > 0 ? [
|
|
1676
|
+
"",
|
|
1677
|
+
"Closest matches:",
|
|
1678
|
+
...suggestions.map(
|
|
1679
|
+
(suggestion) => `- ${suggestion.name}: ${formatShowCall(suggestion, ctx2)}`
|
|
1680
|
+
)
|
|
1681
|
+
] : [],
|
|
1682
|
+
...unreadableSources.length > 0 ? [
|
|
1683
|
+
"",
|
|
1684
|
+
"Sources that could not be read:",
|
|
1685
|
+
...unreadableSources.map((source) => `- ${source.storybookId}: ${source.error}`)
|
|
1686
|
+
] : [],
|
|
1687
|
+
"",
|
|
1688
|
+
listHint
|
|
1689
|
+
].join(`
|
|
1690
|
+
`);
|
|
1691
|
+
}
|
|
1692
|
+
function formatResolvedElsewhere({ id, storybookId, resolvedStorybookId }, ctx2) {
|
|
1693
|
+
let scope = ctx2.transport === "cli" ? `--storybookId ${resolvedStorybookId}` : `storybookId "${resolvedStorybookId}"`;
|
|
1694
|
+
return `> "${id}" is not in source "${storybookId}"; showing it from source "${resolvedStorybookId}". Pass ${scope} on follow-up calls for this source.`;
|
|
1626
1695
|
}
|
|
1627
1696
|
function renderShow(data, ctx2) {
|
|
1628
1697
|
let resolution = resolveShow(data);
|
|
@@ -1631,9 +1700,13 @@ function renderShow(data, ctx2) {
|
|
|
1631
1700
|
case "notice":
|
|
1632
1701
|
return resolution.message;
|
|
1633
1702
|
case "entry-missing":
|
|
1634
|
-
return formatEntryNotFound(data
|
|
1635
|
-
case "found":
|
|
1636
|
-
|
|
1703
|
+
return formatEntryNotFound(data, ctx2);
|
|
1704
|
+
case "found": {
|
|
1705
|
+
let documentation = resolution.entry.kind === "doc" ? formatDocsManifest(resolution.entry.doc) : formatComponentManifest(resolution.entry.component);
|
|
1706
|
+
return data.resolvedStorybookId ? `${formatResolvedElsewhere(data, ctx2)}
|
|
1707
|
+
|
|
1708
|
+
${documentation}` : documentation;
|
|
1709
|
+
}
|
|
1637
1710
|
default:
|
|
1638
1711
|
return resolution;
|
|
1639
1712
|
}
|
|
@@ -1671,6 +1744,19 @@ var storybookIdField = {
|
|
|
1671
1744
|
"local"
|
|
1672
1745
|
)
|
|
1673
1746
|
};
|
|
1747
|
+
async function readEntries({
|
|
1748
|
+
storybookId,
|
|
1749
|
+
access
|
|
1750
|
+
}) {
|
|
1751
|
+
try {
|
|
1752
|
+
let names = await listEntryNames(access);
|
|
1753
|
+
return { storybookId, entries: names.map((name) => ({ ...name, storybookId })) };
|
|
1754
|
+
} catch (error) {
|
|
1755
|
+
let reason = error instanceof RequiresOwnMcpError ? `private, read it through its own MCP endpoint: ${error.endpoint}` : (error instanceof Error ? error.message : String(error)).split(`
|
|
1756
|
+
`)[0];
|
|
1757
|
+
return { storybookId, entries: [], error: reason };
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1674
1760
|
async function resolveFromSource(access, id) {
|
|
1675
1761
|
try {
|
|
1676
1762
|
return { entry: await access.resolve(id) };
|
|
@@ -1716,7 +1802,32 @@ function createDocsToolset(options) {
|
|
|
1716
1802
|
'The human-readable story name (e.g., "Primary"). Use together with componentId.'
|
|
1717
1803
|
)
|
|
1718
1804
|
)
|
|
1719
|
-
}, showStorySchema = multiSource ? strictObject({ ...showStoryFields, ...storybookIdField }) : strictObject(showStoryFields), access = (storybookId, ctx2) => multiSource ? selectSource(sources, storybookId, ctx2) : { access: docsAccess }
|
|
1805
|
+
}, showStorySchema = multiSource ? strictObject({ ...showStoryFields, ...storybookIdField }) : strictObject(showStoryFields), access = (storybookId, ctx2) => multiSource ? selectSource(sources, storybookId, ctx2) : { access: docsAccess }, sourceAccesses = multiSource ? sources.map(({ source, access: sourceAccess }) => ({
|
|
1806
|
+
storybookId: source.id,
|
|
1807
|
+
access: sourceAccess
|
|
1808
|
+
})) : [{ access: docsAccess }], recoverMissedId = async (id, requestedStorybookId) => {
|
|
1809
|
+
let others = sourceAccesses.filter((source) => source.storybookId !== requestedStorybookId), hits = (await Promise.all(
|
|
1810
|
+
others.map(async (source) => ({
|
|
1811
|
+
source,
|
|
1812
|
+
entry: await source.access.resolve(id).catch(() => {
|
|
1813
|
+
})
|
|
1814
|
+
}))
|
|
1815
|
+
)).filter(({ entry }) => entry !== void 0);
|
|
1816
|
+
if (hits.length === 1) {
|
|
1817
|
+
let [{ source, entry }] = hits;
|
|
1818
|
+
return { entry, resolvedStorybookId: source.storybookId };
|
|
1819
|
+
}
|
|
1820
|
+
let listings = await Promise.all(sourceAccesses.map(readEntries)), suggestions = suggestEntries(
|
|
1821
|
+
id,
|
|
1822
|
+
listings.flatMap(({ entries }) => entries).filter((entry) => entry.id !== id || entry.storybookId !== requestedStorybookId)
|
|
1823
|
+
), unreadableSources = listings.flatMap(
|
|
1824
|
+
({ storybookId, error }) => storybookId !== void 0 && error !== void 0 ? [{ storybookId, error }] : []
|
|
1825
|
+
);
|
|
1826
|
+
return {
|
|
1827
|
+
...suggestions.length > 0 ? { suggestions } : {},
|
|
1828
|
+
...unreadableSources.length > 0 ? { unreadableSources } : {}
|
|
1829
|
+
};
|
|
1830
|
+
};
|
|
1720
1831
|
return defineToolset({
|
|
1721
1832
|
id: DOCS_TOOLSET_ID,
|
|
1722
1833
|
description: "Storybook component and docs documentation.",
|
|
@@ -1759,10 +1870,14 @@ function createDocsToolset(options) {
|
|
|
1759
1870
|
title: "Get Documentation",
|
|
1760
1871
|
description: describeShow,
|
|
1761
1872
|
handler: async (input, ctx2) => {
|
|
1762
|
-
let { id, storybookId } = input, selected = access(storybookId, ctx2), data = selected.sourceError ? { id, storybookId, sourceError: selected.sourceError } : { id, storybookId, ...await resolveFromSource(selected.access, id) }
|
|
1873
|
+
let { id, storybookId } = input, selected = access(storybookId, ctx2), data = selected.sourceError ? { id, storybookId, sourceError: selected.sourceError } : { id, storybookId, ...await resolveFromSource(selected.access, id) };
|
|
1874
|
+
resolveShow(data).kind === "entry-missing" && (data = { ...data, ...await recoverMissedId(id, storybookId) });
|
|
1875
|
+
let markdown = renderShow(data, ctx2), telemetry = {
|
|
1763
1876
|
payload: {
|
|
1764
1877
|
componentId: id,
|
|
1765
1878
|
found: data.entry !== void 0,
|
|
1879
|
+
resolvedElsewhere: data.resolvedStorybookId !== void 0,
|
|
1880
|
+
suggestionCount: data.suggestions?.length ?? 0,
|
|
1766
1881
|
resultTokenCount: estimateTokens(markdown)
|
|
1767
1882
|
}
|
|
1768
1883
|
};
|
|
@@ -1946,13 +2061,14 @@ async function addGetDocumentationTool(server, enabled, options) {
|
|
|
1946
2061
|
async (input) => {
|
|
1947
2062
|
let context = server.ctx.custom, { data, result } = await call(server, "show", input);
|
|
1948
2063
|
if (data) {
|
|
1949
|
-
let { entry } = data, found = entry ? entry.kind === "component" ? entry.component : entry.doc : void 0;
|
|
2064
|
+
let { entry, resolvedStorybookId } = data, found = entry ? entry.kind === "component" ? entry.component : entry.doc : void 0;
|
|
1950
2065
|
await context?.onGetDocumentation?.(
|
|
1951
2066
|
found ? {
|
|
1952
2067
|
context,
|
|
1953
2068
|
input,
|
|
1954
2069
|
foundDocumentation: found,
|
|
1955
|
-
resultText: result.content[0].text
|
|
2070
|
+
resultText: result.content[0].text,
|
|
2071
|
+
resolvedStorybookId
|
|
1956
2072
|
} : { context, input }
|
|
1957
2073
|
);
|
|
1958
2074
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/mcp",
|
|
3
|
-
"version": "11.0.0-alpha.
|
|
3
|
+
"version": "11.0.0-alpha.7",
|
|
4
4
|
"description": "MCP server that serves knowledge about your components based on your Storybook stories and documentation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"react-docgen": "^8.0.2",
|
|
50
50
|
"react-docgen-typescript": "^2.4.0",
|
|
51
51
|
"srvx": "^0.8.16",
|
|
52
|
-
"storybook": "11.0.0-alpha.
|
|
52
|
+
"storybook": "11.0.0-alpha.7",
|
|
53
53
|
"tinyexec": "^1.0.2",
|
|
54
54
|
"typescript": "^6.0.3"
|
|
55
55
|
},
|