@tpitre/story-ui 2.1.4 → 2.2.0

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
@@ -30,6 +30,7 @@ Story UI revolutionizes component documentation by automatically generating Stor
30
30
  - **Production Mode**: Clean deployment without generated stories
31
31
  - **Auto Port Detection**: Automatically finds available ports
32
32
  - **Hot Reload Integration**: Stories update automatically as you chat
33
+ - **MCP Server Integration**: Use Story UI directly from Claude Desktop or other MCP clients
33
34
 
34
35
  ## 🚀 Quick Start
35
36
 
@@ -72,17 +73,17 @@ Story UI uses advanced AI to understand your component library and generate appr
72
73
  export default {
73
74
  // Component library import path
74
75
  importPath: 'your-component-library',
75
-
76
+
76
77
  // Path to your local components (for custom libraries)
77
78
  componentsPath: './src/components',
78
-
79
+
79
80
  // Generated stories location
80
81
  generatedStoriesPath: './src/stories/generated/',
81
-
82
+
82
83
  // Story configuration
83
84
  storyPrefix: 'Generated/',
84
85
  defaultAuthor: 'Story UI AI',
85
-
86
+
86
87
  // Layout rules for multi-column layouts
87
88
  layoutRules: {
88
89
  multiColumnWrapper: 'div',
@@ -147,6 +148,42 @@ AI: "I'll modify the existing story to make the buttons full width..."
147
148
 
148
149
  The AI will preserve your existing code and only modify what you requested!
149
150
 
151
+ ## 🤖 MCP Server Integration
152
+
153
+ Story UI can be used as a Model Context Protocol (MCP) server, allowing you to generate stories directly from Claude Desktop or other MCP-compatible clients.
154
+
155
+ ### Quick Setup for Claude Desktop
156
+
157
+ 1. Add to your Claude Desktop config (`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS):
158
+
159
+ ```json
160
+ {
161
+ "mcpServers": {
162
+ "story-ui": {
163
+ "command": "npx",
164
+ "args": ["@tpitre/story-ui", "mcp"],
165
+ "env": {
166
+ "CLAUDE_API_KEY": "your-claude-api-key-here"
167
+ }
168
+ }
169
+ }
170
+ }
171
+ ```
172
+
173
+ 2. Start the Story UI HTTP server in your project:
174
+ ```bash
175
+ story-ui start
176
+ ```
177
+
178
+ 3. Restart Claude Desktop
179
+
180
+ Now you can generate stories directly in Claude Desktop! Just ask:
181
+ - "Use Story UI to create a hero section with a title and CTA button"
182
+ - "List all available components in Story UI"
183
+ - "Show me the stories I've generated"
184
+
185
+ For detailed MCP setup instructions, see [docs/MCP_INTEGRATION.md](docs/MCP_INTEGRATION.md).
186
+
150
187
  ## 📖 Documentation Support
151
188
 
152
189
  ### Directory-Based Documentation (Recommended)
package/dist/cli/index.js CHANGED
@@ -257,4 +257,33 @@ program
257
257
  cleanupDefaultStorybookComponents();
258
258
  console.log('✅ Cleanup complete! Component discovery should now work properly.');
259
259
  });
260
+ program
261
+ .command('mcp')
262
+ .description('Start Story UI as an MCP server (for use with Claude Desktop and other MCP clients)')
263
+ .option('--http-port <port>', 'Port for the HTTP server', '4001')
264
+ .action(async (options) => {
265
+ // For MCP mode, DO NOT output anything to stdout - it's reserved for JSON-RPC
266
+ // Use stderr for all logging
267
+ console.error('🚀 Starting Story UI as MCP server...');
268
+ console.error('📡 This server uses stdio transport for MCP communication');
269
+ console.error('⚠️ Note: The HTTP server must be running on port ' + options.httpPort);
270
+ console.error(' Run "story-ui start" in another terminal if not already running.\n');
271
+ // Use absolute path to MCP stdio server
272
+ const pkgRoot = path.resolve(__dirname, '..');
273
+ const mcpServerPath = path.join(pkgRoot, 'mcp-server/mcp-stdio-server.js');
274
+ const env = {
275
+ ...process.env,
276
+ STORY_UI_HTTP_PORT: options.httpPort
277
+ };
278
+ const mcpServer = spawn('node', [mcpServerPath], {
279
+ stdio: 'inherit',
280
+ env
281
+ });
282
+ mcpServer.on('close', (code) => {
283
+ console.error(`MCP server exited with code ${code}`);
284
+ });
285
+ process.on('SIGINT', () => {
286
+ mcpServer.kill('SIGINT');
287
+ });
288
+ });
260
289
  program.parse(process.argv);
@@ -12,12 +12,14 @@ import cors from 'cors';
12
12
  import { getComponents, getProps } from './routes/components.js';
13
13
  import { claudeProxy } from './routes/claude.js';
14
14
  import { generateStoryFromPrompt } from './routes/generateStory.js';
15
- import { getStoriesMetadata, getStoryById, getStoryContent, deleteStory, clearAllStories, getMemoryStats } from './routes/memoryStories.js';
15
+ import { clearAllStories, getMemoryStats } from './routes/memoryStories.js';
16
+ import { getAllStories, getStoryById, getStoryContent, deleteStory } from './routes/hybridStories.js';
16
17
  import { getSyncedStories, deleteSyncedStory, clearAllSyncedStories, syncChatHistory, validateChatSession, getSyncedStoryById } from './routes/storySync.js';
17
18
  import { setupProductionGitignore } from '../story-generator/productionGitignoreManager.js';
18
19
  import { getInMemoryStoryService } from '../story-generator/inMemoryStoryService.js';
19
20
  import { loadUserConfig } from '../story-generator/configLoader.js';
20
21
  import fs from 'fs';
22
+ import { UrlRedirectService } from '../story-generator/urlRedirectService.js';
21
23
  const app = express();
22
24
  app.use(cors());
23
25
  app.use(express.json());
@@ -27,8 +29,8 @@ app.get('/mcp/props', getProps);
27
29
  // AI generation routes
28
30
  app.post('/mcp/claude', claudeProxy);
29
31
  app.post('/mcp/generate-story', generateStoryFromPrompt);
30
- // In-memory story management routes (production)
31
- app.get('/mcp/stories', getStoriesMetadata);
32
+ // Hybrid story management routes (works in both dev and production)
33
+ app.get('/mcp/stories', getAllStories);
32
34
  app.get('/mcp/stories/:id', getStoryById);
33
35
  app.get('/mcp/stories/:id/content', getStoryContent);
34
36
  app.delete('/mcp/stories/:id', deleteStory);
@@ -42,7 +44,7 @@ app.delete('/mcp/sync/stories', clearAllSyncedStories);
42
44
  app.get('/mcp/sync/chat-history', syncChatHistory);
43
45
  app.get('/mcp/sync/validate/:id', validateChatSession);
44
46
  // Proxy routes for frontend compatibility (maps /story-ui/ to /mcp/)
45
- app.get('/story-ui/stories', getStoriesMetadata);
47
+ app.get('/story-ui/stories', getAllStories);
46
48
  app.get('/story-ui/stories/:id', getStoryById);
47
49
  app.get('/story-ui/stories/:id/content', getStoryContent);
48
50
  app.delete('/story-ui/stories/:id', deleteStory);
@@ -107,10 +109,22 @@ app.delete('/story-ui/sync/stories/:id', deleteSyncedStory);
107
109
  app.delete('/story-ui/sync/stories', clearAllSyncedStories);
108
110
  app.get('/story-ui/sync/chat-history', syncChatHistory);
109
111
  app.get('/story-ui/sync/validate/:id', validateChatSession);
112
+ // Redirect service endpoint
113
+ app.get('/mcp/redirects.js', (req, res) => {
114
+ res.set('Content-Type', 'application/javascript');
115
+ res.send(redirectService.getRedirectScript());
116
+ });
117
+ // Also serve at story-ui path for compatibility
118
+ app.get('/story-ui/redirects.js', (req, res) => {
119
+ res.set('Content-Type', 'application/javascript');
120
+ res.send(redirectService.getRedirectScript());
121
+ });
110
122
  // Set up production-ready gitignore and directory structure on startup
111
123
  const config = loadUserConfig();
112
124
  const gitignoreManager = setupProductionGitignore(config);
113
125
  const storyService = getInMemoryStoryService(config);
126
+ // Initialize URL redirect service
127
+ const redirectService = new UrlRedirectService(process.cwd());
114
128
  const PORT = parseInt(process.env.PORT || '4001', 10);
115
129
  // Start server
116
130
  app.listen(PORT, () => {