listFolders
Retrieve email folder structures from your Mail MCP Tool account to organize and navigate your inbox efficiently.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "listFolders"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| random_string | No |
Implementation Reference
- src/tools/mail.ts:1021-1054 (handler)The handler function for the 'listFolders' tool. It calls mailService.getFolders() to retrieve the list of email folders and formats the response.
this.server.tool( "listFolders", { random_string: z.string().optional() }, async () => { try { const folders = await this.mailService.getFolders(); if (folders.length === 0) { return { content: [ { type: "text", text: "没有找到邮件文件夹。" } ] }; } let resultText = `📁 邮件文件夹列表 (${folders.length}个):\n\n`; folders.forEach((folder, index) => { resultText += `${index + 1}. ${folder}\n`; }); return { content: [ { type: "text", text: resultText } ] }; } catch (error) { return { content: [ { type: "text", text: `获取邮件文件夹列表时发生错误: ${error instanceof Error ? error.message : String(error)}` } ] }; } } ); - src/tools/mail.ts:1021-1054 (registration)Registration of the 'listFolders' tool using this.server.tool(), including schema and inline handler.
this.server.tool( "listFolders", { random_string: z.string().optional() }, async () => { try { const folders = await this.mailService.getFolders(); if (folders.length === 0) { return { content: [ { type: "text", text: "没有找到邮件文件夹。" } ] }; } let resultText = `📁 邮件文件夹列表 (${folders.length}个):\n\n`; folders.forEach((folder, index) => { resultText += `${index + 1}. ${folder}\n`; }); return { content: [ { type: "text", text: resultText } ] }; } catch (error) { return { content: [ { type: "text", text: `获取邮件文件夹列表时发生错误: ${error instanceof Error ? error.message : String(error)}` } ] }; } } ); - src/tools/mail.ts:1023-1023 (schema)Input schema for listFolders tool (minimal, optional random_string).
{ random_string: z.string().optional() }, - src/tools/mail-service.ts:183-209 (helper)The getFolders helper method in MailService class that connects to IMAP and recursively retrieves all folder names using getBoxes.
async getFolders(): Promise<string[]> { await this.connectImap(); return new Promise((resolve, reject) => { this.imapClient.getBoxes((err, boxes) => { if (err) { reject(err); return; } const folderNames: string[] = []; // 递归遍历所有邮件文件夹 const processBoxes = (boxes: IMAP.MailBoxes, prefix = '') => { for (const name in boxes) { folderNames.push(prefix + name); if (boxes[name].children) { processBoxes(boxes[name].children, `${prefix}${name}${boxes[name].delimiter}`); } } }; processBoxes(boxes); resolve(folderNames); }); }); }