get_cell_value
Retrieve specific cell values from an Excel file by providing the file path, sheet name, and cell location in A1 format.
Instructions
指定されたセルの値を取得します
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cell | Yes | セル位置。A1形式で指定(例: A1, B2, AA10) | |
| filePath | Yes | 対象のExcelファイルの絶対パス | |
| sheetName | Yes | 対象のワークシート名 |
Implementation Reference
- src/index.ts:250-264 (handler)Core handler function that validates the cell address, loads the Excel workbook using loadWorkbook, retrieves the specified worksheet, gets the cell value using ExcelJS, and returns the formatted result or throws an MCP error on failure.async function getCellValue(filePath: string, sheetName: string, cell: string): Promise<string> { try { validateCellAddress(cell); const workbook = await loadWorkbook(filePath); const worksheet = workbook.getWorksheet(sheetName); if (!worksheet) { throw new Error(`ワークシート '${sheetName}' が見つかりません。利用可能なシート: ${getSheetNames(workbook)}`); } const cellValue = worksheet.getCell(cell).value; return `セル ${cell} の値: ${cellValue}`; } catch (error) { throw new McpError(ErrorCode.InternalError, `セル値取得エラー: ${error}`); } }
- src/index.ts:37-41 (schema)Zod schema defining the input parameters for the get_cell_value tool: filePath (absolute path to Excel file), sheetName, and cell (A1-style address). Used for validation in tool calls.const GetCellValueSchema = z.object({ filePath: z.string().describe("対象のExcelファイルの絶対パス"), sheetName: z.string().describe("対象のワークシート名"), cell: z.string().describe("セル位置。A1形式で指定(例: A1, B2, AA10)"), });
- src/index.ts:487-490 (registration)Tool registration in the ListToolsRequestSchema handler, specifying name, description, and inputSchema for discovery by MCP clients.name: "get_cell_value", description: "指定されたセルの値を取得します", inputSchema: zodToJsonSchema(GetCellValueSchema) },
- src/index.ts:543-546 (handler)MCP tool dispatcher wrapper that parses input arguments using the schema and delegates to the core getCellValue handler function.get_cell_value: async (args: any) => { const { filePath, sheetName, cell } = GetCellValueSchema.parse(args); return await getCellValue(filePath, sheetName, cell); },
- src/index.ts:113-118 (helper)Helper function to validate the cell address format using regex (A-Z+ followed by digits starting from 1), throws error on invalid format. Called by getCellValue.function validateCellAddress(cell: string): void { const cellPattern = /^[A-Z]+[1-9]\d*$/; if (!cellPattern.test(cell)) { throw new Error(`無効なセル位置: '${cell}'。正しい形式: A1, B2, AA10など`); } }