Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/mcp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"@modelcontextprotocol/sdk": "^1.10.2",
"@seed-design/figma": "0.1.12",
"cac": "^6.7.14",
"cosmiconfig": "^9.0.0",
"typescript": "^5.9.2",
"uuid": "^11.1.0",
"ws": "^8.18.1",
"yargs": "^18.0.0",
Expand All @@ -33,8 +35,7 @@
"devDependencies": {
"@types/bun": "^1.2.10",
"@types/ws": "^8.18.1",
"@types/yargs": "^17.0.33",
"typescript": "^5.8.3"
"@types/yargs": "^17.0.33"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/mcp/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { logger } from "../logger";
import { createFigmaWebSocketClient } from "../websocket";
import { registerEditingTools, registerTools } from "../tools";
import { registerPrompts } from "../prompts";
import { version } from "../../package.json" assert { type: "json" };
import { version } from "../../package.json" with { type: "json" };
import type { Server, ServerWebSocket } from "bun";
import { loadConfig, type McpConfig } from "../config";

Expand Down
40 changes: 8 additions & 32 deletions packages/mcp/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,23 @@
import type { CreatePipelineConfig } from "@seed-design/figma/codegen/targets/react";
import fs from "node:fs";
import path from "node:path";
import { logger } from "./logger";
import { cosmiconfig } from "cosmiconfig";

// Define config type
export interface McpConfig {
extend?: CreatePipelineConfig["extend"];
}

// Config loader
export async function loadConfig(configPath: string) {
try {
const resolvedPath = path.resolve(process.cwd(), configPath);
export async function loadConfig(configPath: string): Promise<McpConfig | null> {
const explorer = cosmiconfig("mcp");

if (!fs.existsSync(resolvedPath)) {
logger.error(`Config file not found: ${resolvedPath}`);
return null;
}
const searchResult = await explorer.load(configPath);

// Handle different file types
if (resolvedPath.endsWith(".json")) {
const content = fs.readFileSync(resolvedPath, "utf-8");
return JSON.parse(content);
}
if (!searchResult) {
logger.error(`Config file not found: ${configPath}`);

if (
resolvedPath.endsWith(".js") ||
resolvedPath.endsWith(".mjs") ||
resolvedPath.endsWith(".ts") ||
resolvedPath.endsWith(".mts")
) {
// For JS/MJS/TS/MTS files, we can dynamically import with Bun
// Bun has built-in TypeScript support without requiring transpilation
const config = await import(resolvedPath);
return config.default || config;
}

logger.error(`Unsupported config file format: ${resolvedPath}`);
return null;
} catch (error) {
logger.error(
`Failed to load config file: ${error instanceof Error ? error.message : String(error)}`,
);
return null;
}

return searchResult.config;
}