import { type McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { z } from "zod/v4"; import { EwsClient, loadConfig } from "../ews_client.ts"; export function registerFolderTools(server: McpServer): void { server.registerTool( "get_folders", { description: "List mailbox folders from the Exchange mailbox.", inputSchema: z.object({ parentFolderId: z.string().default("msgfolderroot").describe( "Parent folder to list children of." + " Supports distinguished names (e.g. inbox, calendar)", ), recursive: z.boolean().default(false).describe( "If true, recursively traverse all subfolders", ), }), outputSchema: z.object({ folders: z.array(z.object({ name: z.string(), id: z.string(), totalCount: z.number(), unreadCount: z.number(), childFolderCount: z.number(), })), }), }, async ({ parentFolderId, recursive }) => { try { const client = new EwsClient(loadConfig()); const folders = await client.findFolders(parentFolderId, recursive); return { content: [{ type: "text" as const, text: JSON.stringify(folders) }], structuredContent: { folders }, }; } catch (error: any) { return { content: [{ type: "text" as const, text: JSON.stringify({ error: error.message ?? String(error) }), }], }; } }, ); }