How to Get File Information Including Sheet Names for Excel Files with Desktop Commander MCP
Desktop Commander MCP extracts Excel metadata and sheet names through the file info command, using the exceljs library in src/utils/files/excel.ts to parse .xlsx, .xls, .xlsm, and .xlsb files and return structured JSON containing worksheet names, dimensions, and cell data.
Desktop Commander MCP provides native support for Excel workbooks as first-class file types within its Model Context Protocol implementation. The server leverages the exceljs library to read workbook structures and exposes file information through both CLI and programmatic APIs. This guide demonstrates how to retrieve comprehensive Excel metadata, including worksheet enumeration and per-sheet data extraction, using the tools implemented in the wonderwhy-er/DesktopCommanderMCP repository.
How Desktop Commander MCP Processes Excel Files
Format Detection and Validation
The entry point for Excel handling resides in src/utils/files/excel.ts, where the isExcel(filePath) helper validates file extensions. This function recognizes standard Excel formats including .xlsx, .xls, .xlsm, and .xlsb, ensuring only compatible workbooks proceed to the parsing stage.
Workbook Parsing with exceljs
Upon validation, the system imports the Workbook class from exceljs and loads the file using await workbook.xlsx.readFile(path). This asynchronous operation reads the entire workbook structure into memory, making all worksheets accessible through the workbook.worksheets array.
Metadata Extraction
The utility iterates over each worksheet object to collect:
- Sheet names: Accessed via
sheet.name - Dimensions: Retrieved through
sheet.actualRowCountandsheet.columnCount - Data preview: Optional extraction of cell values using
sheet.getRow(rowNumber).values
Retrieving Excel File Information and Sheet Names
Basic CLI Usage (Active Sheet Only)
To fetch file information for the default active worksheet, use the file info command without additional flags. The endpoint GET /file/info?path=... processes the request through src/commands/fileInfo.ts.
desktop-commander file info /path/to/report.xlsx
This returns a JSON object where the data field contains a 2-D array representing the active sheet's contents.
Extract All Sheets with the --includeSheets Flag
To retrieve file information including sheet names for all worksheets simultaneously, append the --includeSheets parameter. When this flag is present, the response transforms into a map structure where each key corresponds to a sheet.name and each value contains that sheet's 2-D array data.
desktop-commander file info /path/to/workbook.xlsm --includeSheets
Response structure:
{
"type": "excel",
"sheets": {
"Summary": [
["Metric", "Value"],
["Total", 98765]
],
"2024-Q1": [
["Month", "Sales"],
["Jan", 12000]
]
}
}
List Sheet Names Without Loading Data
For scenarios requiring only worksheet enumeration without cell data extraction, use the --listSheets flag. This minimizes memory usage by reading only workbook metadata rather than full cell contents.
desktop-commander file info /data/project.xlsx --listSheets
Response:
{
"type": "excel",
"sheetNames": ["Overview", "Expenses", "Revenue"]
}
Programmatic API Access
Integrate Excel file inspection directly into Node.js applications using the JavaScript client. Import getFileInfo from desktop-commander-client and pass the includeSheets: true option to the options parameter.
import { getFileInfo } from "desktop-commander-client";
async function inspectExcel(filePath) {
const info = await getFileInfo(filePath, { includeSheets: true });
if (info.type === "excel") {
console.log("Available sheets:", Object.keys(info.sheets));
const firstSheetData = info.sheets[Object.keys(info.sheets)[0]];
console.table(firstSheetData);
}
}
inspectExcel("./budget.xlsx");
Summary
- Desktop Commander MCP treats Excel files as native types through the handler in
src/utils/files/excel.ts - The system uses
exceljsto parse.xlsx,.xls,.xlsm, and.xlsbformats viaworkbook.xlsx.readFile() - Use
desktop-commander file info <path>for active sheet data, or add--includeSheetsto get all sheet names and their contents as a mapped object - The
--listSheetsflag provides sheet name enumeration without loading cell data, returning only thesheetNamesarray - Programmatic access is available via
getFileInfo()with theincludeSheetsboolean option
Frequently Asked Questions
What Excel file formats does Desktop Commander MCP support?
According to the source code in src/utils/files/excel.ts, the isExcel() function recognizes .xlsx, .xls, .xlsm, and .xlsb extensions. The underlying exceljs library handles the parsing for these formats through the Workbook class.
How can I retrieve only sheet names without loading the full workbook data?
Use the --listSheets flag in the CLI command. This option instructs the server to return only the sheetNames array in the JSON response, avoiding the memory overhead of reading cell values from workbook.worksheets.
Does the API expose row and column counts for each worksheet?
Yes. While the CLI output focuses on data arrays, the underlying implementation in src/utils/files/excel.ts accesses sheet.actualRowCount and sheet.columnCount during processing. These dimensions are available when working directly with the workbook.worksheets objects in programmatic integrations.
Which library powers the Excel processing in Desktop Commander MCP?
The repository uses exceljs as its primary dependency for Excel operations. The server imports the Workbook class from this package and calls workbook.xlsx.readFile(path) to load file contents, as implemented in the Excel utility module.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →