@sethdouglasford/claude-flow
Version:
Claude Code Flow - Advanced AI-powered development workflows with SPARC methodology
195 lines ⢠7.83 kB
JavaScript
/**
* MCP command for Claude-Flow
*/
import { Command } from "../cliffy-compat.js";
import chalk from "chalk";
import { logger } from "../../core/logger.js";
import { configManager } from "../../core/config.js";
import { MCPServer } from "../../mcp/server.js";
import { eventBus } from "../../core/event-bus.js";
// Color compatibility
const colors = {
gray: chalk.gray,
yellow: chalk.yellow,
red: chalk.red,
green: chalk.green,
cyan: chalk.cyan,
blue: chalk.blue,
bold: chalk.bold,
};
let mcpServer = null;
export const mcpCommand = new Command()
.name("mcp")
.description("Manage MCP server and tools")
.action(() => {
console.log(colors.yellow("Please specify a subcommand:"));
console.log(" start - Start the MCP server");
console.log(" stop - Stop the MCP server");
console.log(" status - Show MCP server status");
console.log(" tools - List available MCP tools");
console.log(" config - Show MCP configuration");
console.log(" restart - Restart the MCP server");
console.log(" logs - Show MCP server logs");
})
.command("start")
.description("Start the MCP server")
.option("-p, --port <port>", "Port for MCP server", "3000")
.option("-h, --host <host>", "Host for MCP server", "localhost")
.option("--transport <transport>", "Transport type (stdio, http)", "stdio")
.action(async (options) => {
try {
await configManager.load();
const config = configManager.get();
// Override with CLI options
const mcpConfig = {
...config.mcp,
port: parseInt(String(options.port || "3000")),
host: options.host || "localhost",
transport: options.transport || "stdio",
};
mcpServer = new MCPServer(mcpConfig, eventBus, logger);
await mcpServer.start();
console.log(colors.green(`ā
MCP server started on ${options.host}:${options.port}`));
console.log(colors.cyan(`š” Server URL: http://${options.host}:${options.port}`));
console.log(colors.cyan("š§ Available tools: Research, Code, Terminal, Memory"));
console.log(colors.cyan(`š API documentation: http://${options.host}:${options.port}/docs`));
}
catch (error) {
console.error(colors.red(`ā Failed to start MCP server: ${error.message}`));
process.exit(1);
}
})
.command("stop")
.description("Stop the MCP server")
.action(async () => {
try {
if (mcpServer) {
await mcpServer.stop();
mcpServer = null;
console.log(colors.green("ā
MCP server stopped"));
}
else {
console.log(colors.yellow("ā ļø MCP server is not running"));
}
}
catch (error) {
console.error(colors.red(`ā Failed to stop MCP server: ${error.message}`));
process.exit(1);
}
})
.command("status")
.description("Show MCP server status")
.action(async () => {
try {
await configManager.load();
const config = configManager.get();
const isRunning = mcpServer !== null;
console.log(colors.cyan("MCP Server Status:"));
console.log(`š Status: ${isRunning ? colors.green("Running") : colors.red("Stopped")}`);
if (isRunning) {
console.log(`š Address: ${config.mcp.host}:${config.mcp.port}`);
console.log(`š Authentication: ${config.mcp.auth ? colors.green("Enabled") : colors.yellow("Disabled")}`);
console.log(`š§ Tools: ${colors.green("Available")}`);
console.log(`š Metrics: ${colors.green("Collecting")}`);
}
else {
console.log(colors.gray("Use \"claude-flow mcp start\" to start the server"));
}
}
catch (error) {
console.error(colors.red(`ā Failed to get MCP status: ${error.message}`));
process.exit(1);
}
})
.command("tools")
.description("List available MCP tools")
.action(() => {
console.log(colors.cyan("Available MCP Tools:"));
console.log("\nš Research Tools:");
console.log(" ⢠web_search - Search the web for information");
console.log(" ⢠web_fetch - Fetch content from URLs");
console.log(" ⢠knowledge_query - Query knowledge base");
console.log("\nš» Code Tools:");
console.log(" ⢠code_edit - Edit code files");
console.log(" ⢠code_search - Search through codebase");
console.log(" ⢠code_analyze - Analyze code quality");
console.log("\nš„ļø Terminal Tools:");
console.log(" ⢠terminal_execute - Execute shell commands");
console.log(" ⢠terminal_session - Manage terminal sessions");
console.log(" ⢠file_operations - File system operations");
console.log("\nš¾ Memory Tools:");
console.log(" ⢠memory_store - Store information");
console.log(" ⢠memory_query - Query stored information");
console.log(" ⢠memory_index - Index and search content");
})
.command("config")
.description("Show MCP configuration")
.action(async () => {
try {
await configManager.load();
const config = configManager.get();
console.log(colors.cyan("MCP Configuration:"));
console.log(JSON.stringify(config.mcp, null, 2));
}
catch (error) {
console.error(colors.red(`ā Failed to show MCP config: ${error.message}`));
process.exit(1);
}
})
.command("restart")
.description("Restart the MCP server")
.action(async () => {
try {
console.log(colors.yellow("š Stopping MCP server..."));
if (mcpServer) {
await mcpServer.stop();
}
console.log(colors.yellow("š Starting MCP server..."));
await configManager.load();
const config = configManager.get();
mcpServer = new MCPServer(config.mcp, eventBus, logger);
await mcpServer.start();
console.log(colors.green(`ā
MCP server restarted on ${config.mcp.host}:${config.mcp.port}`));
}
catch (error) {
console.error(colors.red(`ā Failed to restart MCP server: ${error.message}`));
process.exit(1);
}
})
.command("logs")
.description("Show MCP server logs")
.option("-n, --lines <lines>", "Number of log lines to show", "50")
.action((options) => {
console.log(colors.cyan(`MCP Server Logs (last ${options.lines} lines):`));
// Mock logs since logging system might not be fully implemented
const logEntries = [
"2024-01-10 10:00:00 [INFO] MCP server started on localhost:3000",
"2024-01-10 10:00:01 [INFO] Tools registered: 12",
"2024-01-10 10:00:02 [INFO] Authentication disabled",
"2024-01-10 10:01:00 [INFO] Client connected: claude-desktop",
"2024-01-10 10:01:05 [INFO] Tool called: web_search",
"2024-01-10 10:01:10 [INFO] Tool response sent successfully",
"2024-01-10 10:02:00 [INFO] Tool called: terminal_execute",
"2024-01-10 10:02:05 [INFO] Command executed successfully",
"2024-01-10 10:03:00 [INFO] Memory operation: store",
"2024-01-10 10:03:01 [INFO] Data stored in namespace: default",
];
const lines = parseInt(options.lines ?? "50", 10);
const startIndex = Math.max(0, logEntries.length - lines);
const displayLogs = logEntries.slice(startIndex);
for (const entry of displayLogs) {
if (entry.includes("[ERROR]")) {
console.log(colors.red(entry));
}
else if (entry.includes("[WARN]")) {
console.log(colors.yellow(entry));
}
else if (entry.includes("[INFO]")) {
console.log(colors.green(entry));
}
else {
console.log(colors.gray(entry));
}
}
});
//# sourceMappingURL=mcp.js.map