Skip to main content
Glama

add_worksheet

Add a new worksheet to an existing Excel workbook by specifying the file path and sheet name using the Excel MCP Server tool.

Instructions

既存のワークブックにワークシートを追加します

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYes対象のExcelファイルの絶対パス。既存のファイルである必要があります
sheetNameYes作成するワークシート名。英数字、日本語、アンダースコア、ハイフンが使用可能です

Implementation Reference

  • Zod schema defining the input parameters for the add_worksheet tool: filePath and sheetName.
    const AddWorksheetSchema = z.object({ filePath: z.string().describe("対象のExcelファイルの絶対パス。既存のファイルである必要があります"), sheetName: z.string().describe("作成するワークシート名。英数字、日本語、アンダースコア、ハイフンが使用可能です"), });
  • Core handler function that loads the Excel workbook, checks for existing sheet, adds new worksheet using ExcelJS, saves the file, and returns confirmation.
    async function addWorksheet(filePath: string, sheetName: string): Promise<string> { try { if (!sheetName || sheetName.trim() === '') { throw new Error("ワークシート名が空です"); } const workbook = await loadWorkbook(filePath); // 既存のシート名と重複チェック const existingSheet = workbook.getWorksheet(sheetName); if (existingSheet) { throw new Error(`ワークシート '${sheetName}' は既に存在します`); } workbook.addWorksheet(sheetName); await workbook.xlsx.writeFile(filePath); return `ワークシート '${sheetName}' を追加しました。`; } catch (error) { throw new McpError(ErrorCode.InternalError, `ワークシート追加エラー: ${error}`); } }
  • src/index.ts:476-480 (registration)
    Tool registration in the listTools handler, defining name, description, and input schema.
    { name: "add_worksheet", description: "既存のワークブックにワークシートを追加します", inputSchema: zodToJsonSchema(AddWorksheetSchema) },
  • src/index.ts:535-538 (registration)
    Tool implementation wrapper in the dispatch map, which parses args with schema and delegates to the handler function.
    add_worksheet: async (args: any) => { const { filePath, sheetName } = AddWorksheetSchema.parse(args); return await addWorksheet(filePath, sheetName); },
  • Helper function to load and validate an Excel workbook, used by the addWorksheet handler.
    async function loadWorkbook(filePath: string): Promise<ExcelJS.Workbook> { try { validateFilePath(filePath); const workbook = new ExcelJS.Workbook(); await workbook.xlsx.readFile(filePath); return workbook; } catch (error) { throw new McpError(ErrorCode.InternalError, `ワークブック読み込みエラー: ${error}`); } }

Other Tools

Related Tools

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/SuperPyonchiX/excel_mcp_server'

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