viewgate-mcp 1.0.59 → 1.0.61

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.
Files changed (2) hide show
  1. package/dist/index.js +39 -56
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -398,38 +398,35 @@ function createMcpServer(apiKey, personalKey) {
398
398
  const errorBody = await response.text();
399
399
  throw new Error(`Backend responded with ${response.status}: ${errorBody}`);
400
400
  }
401
- const data = await response.json();
402
- return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
401
+ const data = (await response.json());
402
+ const styleHandler = data?.settings?.styleHandler || 'unknown';
403
+ const language = data?.settings?.language || 'en';
404
+ const contextHeader = `*** [PROJECT CONTEXT: styleHandler=${styleHandler}, language=${language}] ***\n\n`;
405
+ return { content: [{ type: "text", text: contextHeader + JSON.stringify(data, null, 2) }] };
403
406
  }
404
407
  case "generate_ui_components": {
405
408
  const args = argsAny;
406
409
  const limit = Math.min(args.limit || 1, 10);
407
- // Fetch project styleHandler from config
408
- let styleHandler = args.styleHandler || 'css';
409
- let isOverridden = !!args.styleHandler;
410
- try {
411
- const configRes = await fetch(`${BACKEND_URL}/api/mcp/config`, {
412
- headers: {
413
- 'x-api-key': apiKey,
414
- 'x-mcp-tool-name': 'generate_ui_components',
415
- ...(personalKey ? { 'x-personal-key': personalKey } : {})
416
- }
417
- });
418
- if (configRes.ok) {
419
- const configData = (await configRes.json());
420
- const projectStyle = configData?.settings?.styleHandler;
421
- if (!isOverridden && projectStyle) {
422
- styleHandler = projectStyle;
423
- }
424
- console.error(`[MCP] Style handler identified: ${styleHandler} (Project: ${configData?.settings?.projectName || 'unknown'}, Overridden: ${isOverridden})`);
425
- }
426
- else {
427
- console.error(`[MCP] Could not fetch project config, status: ${configRes.status}. Defaulting to: ${styleHandler}`);
410
+ const fetchUrl = new URL(`${BACKEND_URL}/api/mcp/components`);
411
+ fetchUrl.searchParams.append("limit", limit.toString());
412
+ fetchUrl.searchParams.append("status", "pending");
413
+ const response = await fetch(fetchUrl, {
414
+ headers: {
415
+ 'x-api-key': apiKey,
416
+ 'x-mcp-tool-name': toolName,
417
+ ...(personalKey ? { 'x-personal-key': personalKey } : {})
428
418
  }
419
+ });
420
+ if (!response.ok) {
421
+ const errorBody = await response.text();
422
+ throw new Error(`Backend responded with ${response.status}: ${errorBody}`);
429
423
  }
430
- catch (e) {
431
- console.error('[MCP] Exception fetching project config:', e.message);
432
- }
424
+ const payload = (await response.json());
425
+ const items = payload?.data || [];
426
+ // Use project settings from the components response root
427
+ const projectSettings = payload?.settings || {};
428
+ let styleHandler = args.styleHandler || projectSettings.styleHandler || 'css';
429
+ const isOverridden = !!args.styleHandler;
433
430
  const styleHandlerLabels = {
434
431
  'css': 'Plain CSS (vanilla, no framework dependencies)',
435
432
  'sass': 'SASS/SCSS (use .scss syntax conventions in comments, output as CSS-in-string or inline styles for compatibility)',
@@ -445,28 +442,12 @@ function createMcpServer(apiKey, personalKey) {
445
442
  'css': `Use CSS custom properties for all colors. Read theme values like: const primary = theme?.primary || 'var(--vg-primary)'. Apply them inline or inject a <style> block using these variables. Never hardcode colors.`,
446
443
  'sass': `Use CSS custom properties as values. Resolve theme at runtime: const primary = theme?.primary || 'var(--vg-primary)'. Apply via inline style or injected <style>.`,
447
444
  'css-modules': `CSS Modules can use CSS vars. In JS: const primary = theme?.primary || 'var(--vg-primary)'. Pass primary as CSS var via style={{ '--component-primary': primary }} on the root element and reference it inside the .module.css.`,
448
- 'tailwind': `Use Tailwind's arbitrary value syntax for theme colors: className={\`bg-[\${theme?.primary || 'var(--vg-primary)'}]\`}. For text and borders follow the same pattern. Never use fixed Tailwind color classes like text-blue-500.`,
445
+ 'tailwind': `Use Tailwind's standard 'primary' color class which is dynamically injected by the preview engine. Example: className="bg-primary hover:bg-primary-hover text-primary-foreground". If manually overriding, use: style={{ backgroundColor: theme?.primary || 'var(--vg-primary)' }}. NEVER use fixed classes like text-blue-500.`,
449
446
  'css-in-js': `In styled-components template literals, read the theme prop: color: \${({ theme: t }) => t?.primary || 'var(--vg-primary)'}. Accept the full theme object via props and propagate it through styled-components ThemeProvider if needed.`,
450
447
  'bootstrap': `Override Bootstrap CSS vars on the root element: style={{ '--bs-primary': theme?.primary || 'var(--vg-primary)' }}. Use btn-primary, text-primary etc. classes which will inherit the overridden variable.`,
451
448
  'mui': `Use createTheme({ palette: { primary: { main: theme?.primary || 'var(--vg-primary)' } } }) inside the component and wrap with ThemeProvider. Accept the theme prop and recreate the MUI theme from it.`,
452
449
  };
453
450
  const themingInstruction = themingByHandler[styleHandler] ?? themingByHandler['css'];
454
- const fetchUrl = new URL(`${BACKEND_URL}/api/mcp/components`);
455
- fetchUrl.searchParams.append("limit", limit.toString());
456
- fetchUrl.searchParams.append("status", "pending");
457
- const response = await fetch(fetchUrl, {
458
- headers: {
459
- 'x-api-key': apiKey,
460
- 'x-mcp-tool-name': toolName,
461
- ...(personalKey ? { 'x-personal-key': personalKey } : {})
462
- }
463
- });
464
- if (!response.ok) {
465
- const errorBody = await response.text();
466
- throw new Error(`Backend responded with ${response.status}: ${errorBody}`);
467
- }
468
- const payload = (await response.json());
469
- const items = payload?.data || [];
470
451
  if (!Array.isArray(items) || items.length === 0) {
471
452
  return { content: [{ type: "text", text: JSON.stringify({ ok: true, generated: 0, message: "No pending UI components." }, null, 2) }] };
472
453
  }
@@ -488,25 +469,26 @@ function createMcpServer(apiKey, personalKey) {
488
469
  instruction: `You MUST use ${styleLabel} for ALL styling. Do not mix or use any other styling approach. The component must be fully styled using this technology and be production-ready.`
489
470
  },
490
471
  themingTokens: {
491
- description: 'The component MUST accept an optional `theme` prop for color customization. This is the primary mechanism for users to apply their own brand colors via a JSON file in their project.',
472
+ description: 'CRITICAL: The component MUST accept an optional `theme` prop. This is non-negotiable for production-ready components.',
492
473
  propInterface: {
493
- primary: 'string — main brand/accent color (buttons, links, active states)',
494
- primaryHover: 'string — hover state of primary, slightly darker',
495
- primaryLight: 'string — light tint of primary for backgrounds (10% opacity)',
474
+ primary: 'string — main brand/accent color (buttons, active states)',
475
+ primaryHover: 'string — hover state of primary',
476
+ primaryLight: 'string — light tint of primary for backgrounds',
477
+ primaryForeground: 'string — contrasting text color for primary backgrounds (white/black)',
496
478
  surface: 'string — card/panel background color',
497
- surfaceAlt: 'string — alternative surface for inputs/hover states',
479
+ surfaceAlt: 'string — alternative surface for inputs',
498
480
  border: 'string — border and divider color',
499
481
  text: 'string — primary text color',
500
482
  textMuted: 'string — secondary/muted text color',
501
- radius: 'string — base border radius (e.g. "8px", "12px")',
483
+ radius: 'string — base border radius (e.g. "12px")',
502
484
  },
503
- fallbackMechanism: 'When theme prop is not provided, fall back to CSS custom properties: var(--vg-primary), var(--vg-surface), etc. This allows the ViewGate dashboard preview (which injects CSS vars) and custom ThemeProviders to work without explicit props.',
485
+ fallbackMechanism: 'When theme prop is not provided, you MUST fall back to CSS custom properties: var(--vg-primary), var(--vg-surface), etc. This ensures the component is self-theming via global dashboard injection.',
504
486
  handlerSpecificInstruction: themingInstruction,
505
487
  criticalRules: [
506
- 'NEVER hardcode any color value (no #hex, no rgb(), no named colors like blue/red)',
507
- 'ALWAYS prefer theme prop values first, then var(--vg-*) CSS vars as fallback',
508
- 'The theme prop must be optional component must work without it using CSS var fallbacks',
509
- 'Expose the theme prop explicitly in the component TypeScript/PropTypes interface',
488
+ 'NEVER hardcode hex, rgb, or named colors. Use theme props or var(--vg-*) fallbacks.',
489
+ 'MUST use Tailwind standard "primary" class (e.g. bg-primary, text-primary-foreground) as these are dynamically injected in the dashboard.',
490
+ 'The theme prop MUST be optional and typed in the component interface.',
491
+ 'Micro-animations MUST be implemented with Framer Motion (use whileHover, whileTap, etc.)',
510
492
  ]
511
493
  },
512
494
  constraints: {
@@ -576,8 +558,9 @@ function createMcpServer(apiKey, personalKey) {
576
558
  const errorBody = await response.text();
577
559
  throw new Error(`Backend responded with ${response.status}: ${errorBody}`);
578
560
  }
579
- const data = await response.json();
580
- return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
561
+ const data = (await response.json());
562
+ const confirmation = `Component registered successfully. PREVIEW AVAILABLE in dashboard. The generated code has been validated against the project's mandated styling technology.`;
563
+ return { content: [{ type: "text", text: JSON.stringify({ ...data, confirmation }, null, 2) }] };
581
564
  }
582
565
  case "get_annotations": {
583
566
  const args = argsAny;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viewgate-mcp",
3
- "version": "1.0.59",
3
+ "version": "1.0.61",
4
4
  "main": "dist/index.js",
5
5
  "bin": {
6
6
  "viewgate-mcp": "./dist/index.js"