Skip to content

Commit

Permalink
feat: mcp cli changes
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarsh-dixit committed Feb 25, 2025
1 parent 5deccb1 commit 34140d3
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 153 deletions.
2 changes: 1 addition & 1 deletion js/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import whoami from "./whoami";
// SDK Imports
import { TELEMETRY_LOGGER } from "../sdk/utils/telemetry";
import { TELEMETRY_EVENTS } from "../sdk/utils/telemetry/events";
import mcpCommand from "./server";
import mcpCommand from "./mcp";

const program = new Command().name("composio").description("Composio CLI");

Expand Down
130 changes: 130 additions & 0 deletions js/src/cli/mcp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/* eslint-disable no-console */
import chalk from "chalk";
import { Command } from "commander";
import fs from "fs";
import path from "path";
import os from "os";

import client from "../sdk/client/client";

Check warning on line 8 in js/src/cli/mcp.ts

View workflow job for this annotation

GitHub Actions / lint-and-prettify

'client' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 8 in js/src/cli/mcp.ts

View workflow job for this annotation

GitHub Actions / lint-and-prettify

'client' is defined but never used. Allowed unused vars must match /^_/u
import { getOpenAPIClient } from "../sdk/utils/config";

type ErrorWithMessage = {
message: string;
};

export default class MCPCommand {
private program: Command;

constructor(program: Command) {
this.program = program;

const command = this.program
.command("mcp")
.argument("<url>", "The app to use")
.option("--client <client>", "Client to use (claude, windsurf)", "claude")
.description("MCP command for app integration");

command.action(this.handleAction.bind(this));
}

private async handleAction(
url: string,
options: { client: string }
): Promise<void> {

getOpenAPIClient();
const clientType = options.client;

// Validate client type
if (!["claude", "windsurf"].includes(clientType)) {
console.log(
chalk.red("❌ Error: Invalid client type specified")
);
console.log(chalk.yellow("Please use one of these supported clients:"));
console.log(chalk.yellow("- claude"));
console.log(chalk.yellow("- windsurf"));
return;
}

try {
console.log(chalk.cyan("📝 Configuration Details:"));
console.log(` URL: ${chalk.green(url)}`);
console.log(` Client: ${chalk.green(clientType)}\n`);

const mcpUrl = url;
const command = `npx -y supergateway --sse "${mcpUrl}"`;

console.log(chalk.cyan("💾 Saving configurations..."));

this.saveMcpConfig(url, clientType, mcpUrl, command);

console.log(chalk.cyan(`\n🚀 All done! Please restart ${clientType} for changes to take effect\n`));

} catch (error) {
console.log(chalk.red("\n❌ Error occurred while setting up MCP:"));
console.log(chalk.red(` ${(error as ErrorWithMessage).message}`));
console.log(chalk.yellow("\nPlease try again or contact support if the issue persists.\n"));
return;
}
}

private saveMcpConfig(
url: string,
clientType: string,
mcpUrl: string,
command: string

Check warning on line 75 in js/src/cli/mcp.ts

View workflow job for this annotation

GitHub Actions / lint-and-prettify

'command' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 75 in js/src/cli/mcp.ts

View workflow job for this annotation

GitHub Actions / lint-and-prettify

'command' is defined but never used. Allowed unused args must match /^_/u
): void {
const config = {
command: "npx",
args: ["-y", "supergateway", "--sse", mcpUrl]
};

if (clientType === "claude") {
let configDir;
let configPath;

if (os.platform() === "darwin") {
configDir = path.join(os.homedir(), 'Library', 'Application Support', 'Claude');
configPath = path.join(configDir, 'claude_desktop_config.json');
} else if (os.platform() === "win32") {
configDir = path.join(process.env.APPDATA || '', 'Claude');
configPath = path.join(configDir, 'claude_desktop_config.json');
} else {
console.log(chalk.yellow("\n⚠️ Claude Desktop is not supported on this platform."));
return;
}

if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir, { recursive: true });
}

fs.writeFileSync(configPath, JSON.stringify({
mcpServers: { [url]: config }
}, null, 2));

console.log(chalk.green(`✅ Configuration saved to: ${configPath}`));

} else if (clientType === "windsurf") {
const configDir = path.join(os.homedir(), '.codeium', 'windsurf');
const configPath = path.join(configDir, 'mcp_config.json');

if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir, { recursive: true });
}

let windsurfConfig = { mcpServers: {} };
if (fs.existsSync(configPath)) {
try {
windsurfConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'));
if (!windsurfConfig.mcpServers) windsurfConfig.mcpServers = {};
} catch (error) {

Check warning on line 120 in js/src/cli/mcp.ts

View workflow job for this annotation

GitHub Actions / lint-and-prettify

'error' is defined but never used. Allowed unused caught errors must match /^_/u

Check warning on line 120 in js/src/cli/mcp.ts

View workflow job for this annotation

GitHub Actions / lint-and-prettify

'error' is defined but never used. Allowed unused caught errors must match /^_/u
console.log(chalk.yellow("⚠️ Creating new config file"));
}
}

windsurfConfig.mcpServers[url] = config;
fs.writeFileSync(configPath, JSON.stringify(windsurfConfig, null, 2));
console.log(chalk.green(`✅ Configuration saved to: ${configPath}`));
}
}
}
152 changes: 0 additions & 152 deletions js/src/cli/server.ts

This file was deleted.

0 comments on commit 34140d3

Please sign in to comment.