Files
exchange-mcp/tools/folders.ts
T
2026-07-10 16:36:22 +03:00

39 lines
1.3 KiB
TypeScript

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. Returns a list of Folder objects (name, id, totalCount, unreadCount, childFolderCount).",
inputSchema: z.object({
parentFolderId: z.string().default("msgfolderroot").describe(
"Parent folder to list children of. Supports distinguished names (e.g. inbox, calendar). Default: msgfolderroot",
),
recursive: z.boolean().default(false).describe(
"If true, recursively traverse all subfolders. Default: false",
),
}),
},
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) }],
};
} catch (error: any) {
return {
content: [{
type: "text" as const,
text: JSON.stringify({ error: error.message ?? String(error) }),
}],
};
}
},
);
}