sonance-brand-mcp 1.3.33 → 1.3.35

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.
@@ -393,39 +393,58 @@ CRITICAL: Only use file paths from the VALID FILES list above. Do NOT create new
393
393
  );
394
394
  }
395
395
 
396
- // Build list of valid file paths
397
- const validPaths = new Set<string>();
396
+ // Build list of known file paths (for logging)
397
+ const knownPaths = new Set<string>();
398
398
  if (pageContext.pageFile) {
399
- validPaths.add(pageContext.pageFile);
399
+ knownPaths.add(pageContext.pageFile);
400
400
  }
401
401
  for (const comp of pageContext.componentSources) {
402
- validPaths.add(comp.path);
402
+ knownPaths.add(comp.path);
403
403
  }
404
404
 
405
- debugLog("VALIDATION: Valid file paths from page context", {
405
+ debugLog("VALIDATION: Known file paths from page context", {
406
406
  pageFile: pageContext.pageFile,
407
- validPaths: Array.from(validPaths),
407
+ knownPaths: Array.from(knownPaths),
408
408
  aiRequestedFiles: (aiResponse.modifications || []).map(m => m.filePath)
409
409
  });
410
410
 
411
- // Validate AI response - reject any file paths not in our valid list
412
- const invalidMods = (aiResponse.modifications || []).filter(
413
- (mod) => !validPaths.has(mod.filePath)
414
- );
411
+ // Validate AI response - trust the LLM to identify the correct file
412
+ // Only reject paths that are outside the project or don't exist
413
+ for (const mod of aiResponse.modifications || []) {
414
+ const fullPath = path.join(projectRoot, mod.filePath);
415
415
 
416
- if (invalidMods.length > 0) {
417
- debugLog("REJECTED: AI attempted to create new files", { invalidMods: invalidMods.map(m => m.filePath) });
418
- console.error(
419
- "AI attempted to create new files:",
420
- invalidMods.map((m) => m.filePath)
421
- );
422
- return NextResponse.json(
423
- {
424
- success: false,
425
- error: `Cannot create new files. The following paths were not found in the project: ${invalidMods.map((m) => m.filePath).join(", ")}. Please try a more specific request targeting existing components.`,
426
- } as VisionEditResponse,
427
- { status: 400 }
428
- );
416
+ // Security: Ensure path is within project (prevent path traversal)
417
+ const normalizedPath = path.normalize(fullPath);
418
+ if (!normalizedPath.startsWith(projectRoot)) {
419
+ debugLog("REJECTED: Path outside project", { filePath: mod.filePath });
420
+ return NextResponse.json(
421
+ {
422
+ success: false,
423
+ error: `Invalid file path: ${mod.filePath} (outside project directory)`,
424
+ } as VisionEditResponse,
425
+ { status: 400 }
426
+ );
427
+ }
428
+
429
+ // Check if file exists - LLM should only edit existing files
430
+ if (!fs.existsSync(fullPath)) {
431
+ debugLog("REJECTED: File not found", { filePath: mod.filePath });
432
+ return NextResponse.json(
433
+ {
434
+ success: false,
435
+ error: `File not found: ${mod.filePath}. The file may have been moved or deleted.`,
436
+ } as VisionEditResponse,
437
+ { status: 400 }
438
+ );
439
+ }
440
+
441
+ // If file wasn't in our known context, log it (LLM identified it from screenshot)
442
+ if (!knownPaths.has(mod.filePath)) {
443
+ debugLog("LLM identified file not in import chain - trusting its judgment", {
444
+ filePath: mod.filePath,
445
+ exists: true
446
+ });
447
+ }
429
448
  }
430
449
 
431
450
  // Process modifications - apply patches to get modified content
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sonance-brand-mcp",
3
- "version": "1.3.33",
3
+ "version": "1.3.35",
4
4
  "description": "MCP Server for Sonance Brand Guidelines and Component Library - gives Claude instant access to brand colors, typography, and UI components.",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",