@makeshkumar/mcp-xl-reader 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +51 -29
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -133,13 +133,12 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
133
133
  },
134
134
  {
135
135
  name: "find_excel_files",
136
- description: "Finds all .xlsx files in a given directory.",
136
+ description: "Finds all .xlsx files in a given directory. If directoryPath is omitted, it automatically searches the allowed directories or current working directory.",
137
137
  inputSchema: {
138
138
  type: "object",
139
139
  properties: {
140
- directoryPath: { type: "string", description: "Absolute path to the directory to search." }
141
- },
142
- required: ["directoryPath"]
140
+ directoryPath: { type: "string", description: "Absolute path to the directory to search (optional)." }
141
+ }
143
142
  }
144
143
  },
145
144
  {
@@ -195,15 +194,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
195
194
  content: [{ type: "text", text: "Invalid arguments provided." }]
196
195
  };
197
196
  }
198
- if (name === "find_excel_files") {
199
- if (!args.directoryPath) {
200
- return {
201
- isError: true,
202
- content: [{ type: "text", text: "Missing required directoryPath parameter." }]
203
- };
204
- }
205
- }
206
- else {
197
+ if (name !== "find_excel_files") {
207
198
  if (!args.filePath) {
208
199
  return {
209
200
  isError: true,
@@ -211,12 +202,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
211
202
  };
212
203
  }
213
204
  }
214
- let absolutePath;
205
+ let absolutePath = "";
215
206
  try {
216
- if (name === "find_excel_files") {
217
- absolutePath = await validateDirectoryPath(args.directoryPath);
218
- }
219
- else {
207
+ if (name !== "find_excel_files") {
220
208
  absolutePath = await validateFilePath(args.filePath);
221
209
  }
222
210
  }
@@ -230,18 +218,52 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
230
218
  const workbook = new ExcelJS.Workbook();
231
219
  switch (name) {
232
220
  case "find_excel_files": {
233
- // Read all files recursively in the given directory
234
- const files = await fs.readdir(absolutePath, { recursive: true, withFileTypes: true });
235
- const excelFiles = files
236
- .filter(dirent => dirent.isFile() && dirent.name.toLowerCase().endsWith('.xlsx'))
237
- // fs.readdir with recursive=true returns relative paths in dirent.name or dirent.parentPath
238
- .map(dirent => {
239
- const d = dirent;
240
- const parentPath = d.parentPath || d.path || absolutePath;
241
- return path.resolve(parentPath, dirent.name);
242
- });
221
+ let directoriesToSearch = [];
222
+ if (args && args.directoryPath) {
223
+ directoriesToSearch.push(await validateDirectoryPath(args.directoryPath));
224
+ }
225
+ else {
226
+ const allowedDirectories = process.env.ALLOWED_DIRECTORIES ? process.env.ALLOWED_DIRECTORIES.split(',') : [];
227
+ if (allowedDirectories.length > 0) {
228
+ for (const dir of allowedDirectories) {
229
+ try {
230
+ directoriesToSearch.push(await validateDirectoryPath(dir.trim()));
231
+ }
232
+ catch (e) {
233
+ // ignore invalid ones
234
+ }
235
+ }
236
+ }
237
+ else {
238
+ // fallback to current working directory
239
+ directoriesToSearch.push(process.cwd());
240
+ }
241
+ }
242
+ if (directoriesToSearch.length === 0) {
243
+ return {
244
+ isError: true,
245
+ content: [{ type: "text", text: "No valid directories to search." }]
246
+ };
247
+ }
248
+ const allExcelFiles = [];
249
+ for (const dir of directoriesToSearch) {
250
+ try {
251
+ const files = await fs.readdir(dir, { recursive: true, withFileTypes: true });
252
+ const excelFiles = files
253
+ .filter(dirent => dirent.isFile() && dirent.name.toLowerCase().endsWith('.xlsx'))
254
+ .map(dirent => {
255
+ const d = dirent;
256
+ const parentPath = d.parentPath || d.path || dir;
257
+ return path.resolve(parentPath, dirent.name);
258
+ });
259
+ allExcelFiles.push(...excelFiles);
260
+ }
261
+ catch (e) {
262
+ // Skip if one directory fails
263
+ }
264
+ }
243
265
  return {
244
- content: [{ type: "text", text: JSON.stringify(excelFiles, null, 2) }]
266
+ content: [{ type: "text", text: JSON.stringify(allExcelFiles, null, 2) }]
245
267
  };
246
268
  }
247
269
  case "list_sheets": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makeshkumar/mcp-xl-reader",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "scripts": {