UNPKG

docwriter-mcp-server

Version:

A Model Context Protocol (MCP) server for programmatic creation, modification, and compilation of structured LaTeX documents. Enables AI agents and automated workflows to generate reports, articles, and papers from templates, with secure, structured conte

45 lines (44 loc) 1.83 kB
/** * @fileoverview Core logic for the docwriter_list_latex_documents tool. * This module handles listing all LaTeX documents in the data directory. * @module src/mcp-server/tools/listLatexDocuments/logic */ import { promises as fs } from "fs"; import { z } from "zod"; import { config } from "../../../config/index.js"; import { BaseErrorCode, McpError } from "../../../types-global/errors.js"; import { logger } from "../../../utils/index.js"; /** * Zod schema for validating input arguments for the `docwriter_list_latex_documents` tool. */ export const ListLatexDocumentsInputSchema = z.object({}); /** * Processes the core logic for the `docwriter_list_latex_documents` tool. * @param {ListLatexDocumentsInput} params - The validated input parameters for the tool. * @param {RequestContext} context - The request context for logging and tracing. * @returns {Promise<ListLatexDocumentsResponse>} A promise that resolves to an object containing the list of documents. * @throws {McpError} If a file system error occurs. */ export async function listLatexDocumentsLogic(params, context) { logger.debug("Processing list_latex_documents logic.", { ...context, toolInput: params, }); try { const files = await fs.readdir(config.docwriterDataPath); const documents = files .filter((file) => file.endsWith(".tex")) .map((file) => file.replace(".tex", "")); const toolResponse = { documents, }; logger.notice("Listed LaTeX documents successfully.", { ...context, documentCount: documents.length, }); return toolResponse; } catch (error) { throw new McpError(BaseErrorCode.FILE_SYSTEM_ERROR, "Failed to list documents.", { originalError: error, context }); } }