@itcase/storybook-config 1.3.1 → 1.3.2

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 CHANGED
@@ -99,4 +99,21 @@ Vite-сборки (`ADDONS_VITE` и Next.js + Vite) поднимают MCP-се
99
99
  }
100
100
  ```
101
101
 
102
- Сервер должен быть запущен, иначе агент не подключится. Для публикации MCP на свой хост позже используйте `@storybook/mcp` и манифесты из `storybook build` — локальный аддон для этого не нужен.
102
+ Сервер должен быть запущен, иначе агент не подключится.
103
+
104
+ ## MCP (Docker)
105
+
106
+ Сервер статики + MCP лежит в `@itcase/storybook-config` (`dist/storybook-host`). В потребителе остаётся свой `Dockerfile`: скрипты берутся из пакета, в runtime ставятся только `@storybook/mcp` и `srvx`.
107
+
108
+ ```dockerfile
109
+ USER node
110
+ RUN npm init -y \
111
+ && npm install --omit=dev @storybook/mcp@0.8.0 srvx@0.8.16 \
112
+ && npm cache clean --force
113
+ COPY --from=builder --chown=node:node /app/node_modules/@itcase/storybook-config/dist/storybook-host ./
114
+ COPY --from=builder --chown=node:node /app/storybook-static ./storybook-static
115
+ CMD ["node", "index.mjs"]
116
+ ```
117
+
118
+ - Storybook: `http://<host>:6006/`
119
+ - MCP: `http://<host>:6006/mcp`
@@ -0,0 +1,11 @@
1
+ import path from 'node:path'
2
+
3
+ function isPathInsideRoot(rootDirectory, targetPath) {
4
+ const relativePath = path.relative(rootDirectory, targetPath)
5
+ return (
6
+ relativePath === '' ||
7
+ (!relativePath.startsWith('..') && !path.isAbsolute(relativePath))
8
+ )
9
+ }
10
+
11
+ export { isPathInsideRoot }
@@ -0,0 +1,3 @@
1
+ import { startStorybookServer } from './server/startStorybookServer.mjs'
2
+
3
+ await startStorybookServer()
@@ -0,0 +1,23 @@
1
+ import { readFile } from 'node:fs/promises'
2
+ import path from 'node:path'
3
+
4
+ import { createStorybookMcpHandler } from '@storybook/mcp'
5
+
6
+ import { isPathInsideRoot } from '../helpers/isPathInsideRoot.mjs'
7
+
8
+ async function createMcpHandler(storybookRoot) {
9
+ return createStorybookMcpHandler({
10
+ manifestProvider: async function (_request, manifestPath) {
11
+ const relativePath = manifestPath.replace(/^\.?\//, '')
12
+ const filePath = path.resolve(storybookRoot, relativePath)
13
+ if (!isPathInsideRoot(storybookRoot, filePath)) {
14
+ throw new Error(
15
+ `Refusing to read manifest outside base: ${relativePath}`,
16
+ )
17
+ }
18
+ return readFile(filePath, 'utf8')
19
+ },
20
+ })
21
+ }
22
+
23
+ export { createMcpHandler }
@@ -0,0 +1,44 @@
1
+ import { stat } from 'node:fs/promises'
2
+ import path from 'node:path'
3
+
4
+ import { serve } from 'srvx'
5
+
6
+ import { createMcpHandler } from '../mcp/createMcpHandler.mjs'
7
+ import { serveStorybook } from '../storybook/serveStorybook.mjs'
8
+
9
+ async function startStorybookServer() {
10
+ const storybookRoot = path.resolve(process.cwd(), 'storybook-static')
11
+ const port = Number(process.env.PORT ?? 6006)
12
+ const componentsManifestPath = path.join(
13
+ storybookRoot,
14
+ 'manifests',
15
+ 'components.json',
16
+ )
17
+
18
+ try {
19
+ await stat(componentsManifestPath)
20
+ } catch {
21
+ throw new Error(
22
+ `Storybook manifests not found in ${storybookRoot}. Run storybook build first.`,
23
+ )
24
+ }
25
+
26
+ const mcpHandler = await createMcpHandler(storybookRoot)
27
+
28
+ serve({
29
+ fetch: async function (request) {
30
+ const pathname = new URL(request.url).pathname.replace(/\/$/, '') || '/'
31
+ if (pathname === '/mcp') {
32
+ return mcpHandler(request)
33
+ }
34
+ return serveStorybook(storybookRoot, pathname)
35
+ },
36
+ hostname: '0.0.0.0',
37
+ port: port,
38
+ })
39
+
40
+ console.log(`Storybook UI: http://0.0.0.0:${port}/`)
41
+ console.log(`MCP server: http://0.0.0.0:${port}/mcp`)
42
+ }
43
+
44
+ export { startStorybookServer }
@@ -0,0 +1,48 @@
1
+ import { readFile, stat } from 'node:fs/promises'
2
+ import path from 'node:path'
3
+
4
+ import { isPathInsideRoot } from '../helpers/isPathInsideRoot.mjs'
5
+
6
+ const MIME_TYPES = {
7
+ '.css': 'text/css; charset=utf-8',
8
+ '.html': 'text/html; charset=utf-8',
9
+ '.ico': 'image/x-icon',
10
+ '.js': 'text/javascript; charset=utf-8',
11
+ '.json': 'application/json; charset=utf-8',
12
+ '.map': 'application/json; charset=utf-8',
13
+ '.png': 'image/png',
14
+ '.svg': 'image/svg+xml',
15
+ '.woff': 'font/woff',
16
+ '.woff2': 'font/woff2',
17
+ }
18
+
19
+ async function serveStorybook(storybookRoot, pathname) {
20
+ const relativePath =
21
+ pathname === '/'
22
+ ? 'index.html'
23
+ : decodeURIComponent(pathname).replace(/^\//, '')
24
+ const requestedPath = path.resolve(storybookRoot, relativePath)
25
+
26
+ if (!isPathInsideRoot(storybookRoot, requestedPath)) {
27
+ return new Response('Forbidden', { status: 403 })
28
+ }
29
+
30
+ let filePath = requestedPath
31
+ try {
32
+ const fileStats = await stat(requestedPath)
33
+ if (fileStats.isDirectory()) {
34
+ filePath = path.join(requestedPath, 'index.html')
35
+ }
36
+ } catch {
37
+ filePath = path.join(storybookRoot, 'index.html')
38
+ }
39
+
40
+ const contentType =
41
+ MIME_TYPES[path.extname(filePath)] ?? 'application/octet-stream'
42
+ const fileContents = await readFile(filePath)
43
+ return new Response(fileContents, {
44
+ headers: { 'Content-Type': contentType },
45
+ })
46
+ }
47
+
48
+ export { serveStorybook }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itcase/storybook-config",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "author": "ITCase",
5
5
  "description": "Storybook configuration package",
6
6
  "engines": {
@@ -70,7 +70,11 @@
70
70
  "types": "./dist/utils/index.d.ts",
71
71
  "import": "./dist/utils/index.js",
72
72
  "require": "./dist/utils/index.js"
73
- }
73
+ },
74
+ "./storybook-host": "./dist/storybook-host/index.mjs"
75
+ },
76
+ "bin": {
77
+ "itcase-storybook-host": "./dist/storybook-host/index.mjs"
74
78
  },
75
79
  "files": [
76
80
  "README.md",
@@ -113,6 +117,7 @@
113
117
  "@storybook/addon-vitest": "^10.5.7",
114
118
  "@storybook/addon-webpack5-compiler-swc": "^4.0.3",
115
119
  "@storybook/builder-vite": "^10.5.7",
120
+ "@storybook/mcp": "0.8.0",
116
121
  "@storybook/nextjs": "^10.5.7",
117
122
  "@storybook/nextjs-vite": "^10.5.7",
118
123
  "@storybook/react": "^10.5.7",
@@ -139,6 +144,7 @@
139
144
  "react-native-worklets": "^0.11.4",
140
145
  "storybook": "^10.5.7",
141
146
  "storybook-addon-source-link": "^2.0.1",
147
+ "srvx": "^0.8.16",
142
148
  "vite": "^8.2.1",
143
149
  "vite-plugin-babel": "^1.7.3",
144
150
  "vite-plugin-svgr": "^5.2.0",