Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ npx @magicuidesign/cli@latest install <client>

### Supported Clients

- [x] vscode
- [x] cursor
- [x] windsurf
- [x] claude
Expand Down
26 changes: 20 additions & 6 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export const clientPaths: Record<string, string> = {
),
windsurf: path.join(homeDir, ".codeium", "windsurf", "mcp_config.json"),
cursor: path.join(homeDir, ".cursor", "mcp.json"),
vscode: path.join(
baseDir,
vscodePath,
"..",
"settings.json",
),
};

export const createPlatformCommand = (passedArgs: string[]) => {
Expand All @@ -54,13 +60,21 @@ export const createPlatformCommand = (passedArgs: string[]) => {
};
};

export const getDefaultConfig = () => {
export const getDefaultConfig = (client?: string) => {
const args = ["-y", "@magicuidesign/mcp@latest"];
const command = createPlatformCommand(args);

return {
mcpServers: {
"@magicuidesign/mcp": command,
},
};
return client === "vscode"
? {
mcp: {
servers: {
"@magicuidesign/mcp": command,
},
},
}
: {
mcpServers: {
"@magicuidesign/mcp": command,
},
};
};
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function install(client: ValidClient): Promise<void> {
).start();

try {
const config = { ...getDefaultConfig() };
const config = getDefaultConfig(client);

writeConfig(client, config);
spinner.succeed(
Expand Down
9 changes: 7 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ export type ValidClient =
| "cline"
| "roo-cline"
| "windsurf"
| "cursor";
| "cursor"
| "vscode";

export const VALID_CLIENTS: ValidClient[] = [
"claude",
"cline",
"roo-cline",
"windsurf",
"cursor",
"vscode",
];

export interface ServerConfig {
Expand All @@ -19,7 +21,10 @@ export interface ServerConfig {
}

export interface ClientConfig {
mcpServers: Record<string, ServerConfig>;
mcpServers?: Record<string, ServerConfig>;
mcp?: {
servers: Record<string, ServerConfig>;
};
Comment thread
olguzzar marked this conversation as resolved.
Outdated
}

export interface InstallOptions {
Expand Down
51 changes: 40 additions & 11 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,24 @@ export function readConfig(client: ValidClient): ClientConfig {
const configPath = getConfigPath(client);

if (!fs.existsSync(configPath)) {
return { mcpServers: {} };
return client === "vscode" ? { mcp: { servers: {} } } : { mcpServers: {} };
}

try {
const rawConfig = JSON.parse(fs.readFileSync(configPath, "utf8"));
if (client === "vscode") {
return {
mcp: {
servers: (rawConfig.mcp && rawConfig.mcp.servers) || {},
},
};
}
return {
...rawConfig,
mcpServers: rawConfig.mcpServers || {},
};
} catch (error) {
return { mcpServers: {} };
return client === "vscode" ? { mcp: { servers: {} } } : { mcpServers: {} };
}
}

Expand All @@ -37,11 +44,19 @@ export function writeConfig(client: ValidClient, config: ClientConfig): void {
fs.mkdirSync(configDir, { recursive: true });
}

if (!config.mcpServers || typeof config.mcpServers !== "object") {
// Validate config structure
if (client === "vscode") {
if (!config.mcp?.servers || typeof config.mcp.servers !== "object") {
throw new Error("Invalid mcp.servers structure for vscode");
}
} else if (!config.mcpServers || typeof config.mcpServers !== "object") {
throw new Error("Invalid mcpServers structure");
}

let existingConfig: ClientConfig = { mcpServers: {} };
let existingConfig: ClientConfig = client === "vscode"
? { mcp: { servers: {} } }
: { mcpServers: {} };

try {
if (fs.existsSync(configPath)) {
existingConfig = JSON.parse(fs.readFileSync(configPath, "utf8"));
Expand All @@ -50,13 +65,27 @@ export function writeConfig(client: ValidClient, config: ClientConfig): void {
// If reading fails, continue with empty existing config
}

const mergedConfig = {
...existingConfig,
mcpServers: {
...existingConfig.mcpServers,
...config.mcpServers,
},
};
let mergedConfig;
if (client === "vscode" && config.mcp?.servers) {
mergedConfig = {
...existingConfig,
mcp: {
...existingConfig.mcp,
servers: {
...(existingConfig.mcp?.servers || {}),
...config.mcp.servers,
},
},
};
} else if (config.mcpServers) {
mergedConfig = {
...existingConfig,
mcpServers: {
...existingConfig.mcpServers,
...config.mcpServers,
},
};
}

fs.writeFileSync(configPath, JSON.stringify(mergedConfig, null, 2));
}