MCPcopy Create free account
hub / github.com/echoVic/blade-code / mcpCommand

Function mcpCommand

src/commands/mcp.ts:11–351  ·  view source on GitHub ↗
(program: Command)

Source from the content-addressed store, hash-verified

9 * MCP 相关命令
10 */
11export function mcpCommand(program: Command): void {
12 const mcpCmd = program.command('mcp').description('🔗 MCP (Model Context Protocol) 管理命令');
13
14 // MCP 服务器命令
15 const serverCmd = mcpCmd.command('server').description('MCP 服务器管理');
16
17 serverCmd
18 .command('start')
19 .description('启动 MCP 服务器')
20 .option('-p, --port <port>', '监听端口', '3001')
21 .option('-h, --host <host>', '监听地址', 'localhost')
22 .option('-t, --transport <type>', '传输类型 (ws|stdio)', 'ws')
23 .action(async options => {
24 let spinner = UIProgress.spinner('正在初始化服务器配置...');
25 spinner.start();
26
27 try {
28 const serverConfig = mcpConfig.getServerConfig();
29 const config = {
30 port: parseInt(options.port) || serverConfig.port,
31 host: options.host || serverConfig.host,
32 transport: options.transport || serverConfig.transport,
33 auth: serverConfig.auth,
34 };
35
36 spinner.succeed('配置初始化完成');
37
38 spinner = UIProgress.spinner('正在启动工具管理器...');
39 spinner.start();
40
41 const toolManager = await createToolManager();
42
43 spinner.succeed('工具管理器启动完成');
44
45 UILayout.card(
46 'MCP 服务器配置',
47 [
48 `传输方式: ${config.transport}`,
49 config.transport === 'ws' ? `监听地址: ws://${config.host}:${config.port}` : null,
50 ].filter(Boolean) as string[],
51 { icon: '🚀' }
52 );
53
54 spinner = UIProgress.spinner('正在启动 MCP 服务器...');
55 spinner.start();
56
57 const server = new MCPServer(config, toolManager);
58 await server.start();
59
60 server.on('started', info => {
61 spinner.succeed('MCP 服务器启动成功');
62
63 if (info.host && info.port) {
64 UIDisplay.success(`服务器地址: ws://${info.host}:${info.port}`);
65 }
66 UIDisplay.info('按 Ctrl+C 停止服务器');
67 });
68

Callers 1

index.tsFile · 0.85

Calls 15

startMethod · 0.95
stopMethod · 0.95
connectMethod · 0.95
disconnectMethod · 0.95
createToolManagerFunction · 0.85
runInteractiveClientFunction · 0.85
showServerInfoFunction · 0.85
spinnerMethod · 0.80
getServerConfigMethod · 0.80
succeedMethod · 0.80
cardMethod · 0.80
successMethod · 0.80

Tested by

no test coverage detected