* 列出资源
(client: MCPClient, sessionId: string)
| 432 | * 列出资源 |
| 433 | */ |
| 434 | async function listResources(client: MCPClient, sessionId: string): Promise<void> { |
| 435 | try { |
| 436 | const resources = await client.listResources(sessionId); |
| 437 | |
| 438 | if (resources.length === 0) { |
| 439 | console.log(chalk.yellow('📭 没有可用的资源')); |
| 440 | return; |
| 441 | } |
| 442 | |
| 443 | console.log(chalk.blue(`📁 可用资源 (${resources.length}):`)); |
| 444 | resources.forEach((resource, index) => { |
| 445 | console.log(chalk.green(`${index + 1}. ${resource.name}`)); |
| 446 | console.log(chalk.gray(` URI: ${resource.uri}`)); |
| 447 | if (resource.description) { |
| 448 | console.log(chalk.gray(` 描述: ${resource.description}`)); |
| 449 | } |
| 450 | if (resource.mimeType) { |
| 451 | console.log(chalk.gray(` 类型: ${resource.mimeType}`)); |
| 452 | } |
| 453 | console.log(''); |
| 454 | }); |
| 455 | } catch (error) { |
| 456 | console.error( |
| 457 | chalk.red('❌ 获取资源列表失败:'), |
| 458 | error instanceof Error ? error.message : error |
| 459 | ); |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * 读取资源 |
no test coverage detected