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

Function listTools

src/commands/mcp.ts:500–530  ·  view source on GitHub ↗

* 列出工具

(client: MCPClient, sessionId: string)

Source from the content-addressed store, hash-verified

498 * 列出工具
499 */
500async function listTools(client: MCPClient, sessionId: string): Promise<void> {
501 try {
502 const tools = await client.listTools(sessionId);
503
504 if (tools.length === 0) {
505 console.log(chalk.yellow('🔧 没有可用的工具'));
506 return;
507 }
508
509 console.log(chalk.blue(`🔧 可用工具 (${tools.length}):`));
510 tools.forEach((tool, index) => {
511 console.log(chalk.green(`${index + 1}. ${tool.name}`));
512 console.log(chalk.gray(` 描述: ${tool.description}`));
513
514 const properties = tool.inputSchema.properties;
515 if (properties && Object.keys(properties).length > 0) {
516 console.log(chalk.gray(' 参数:'));
517 Object.entries(properties).forEach(([key, value]: [string, any]) => {
518 const required = tool.inputSchema.required?.includes(key) ? ' (必需)' : '';
519 console.log(chalk.gray(` • ${key}${required}: ${value.description || value.type}`));
520 });
521 }
522 console.log('');
523 });
524 } catch (error) {
525 console.error(
526 chalk.red('❌ 获取工具列表失败:'),
527 error instanceof Error ? error.message : error
528 );
529 }
530}
531
532/**
533 * 调用工具

Callers 1

runInteractiveClientFunction · 0.85

Calls 3

listToolsMethod · 0.80
logMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected