Skip to main content
Glama
shuakami

Mail MCP Tool

by shuakami

listFolders

Retrieve email folder structures from your Mail MCP Tool account to organize and navigate your inbox efficiently.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
random_stringNo

Implementation Reference

  • 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)}` } ] }; } } );
  • 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)}` } ] }; } } );
  • Input schema for listFolders tool (minimal, optional random_string).
    { random_string: z.string().optional() },
  • 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); }); }); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/shuakami/mcp-mail'

If you have feedback or need assistance with the MCP directory API, please join our Discord server