Skip to main content
Glama
ahmetshbz1

Filesystem MCP Server

by ahmetshbz1
search.js1.59 kB
import fs from 'fs/promises'; import path from 'path'; import { minimatch } from 'minimatch'; import { validatePath } from './validation.js'; export async function searchFilesWithValidation(rootPath, pattern, allowedDirectories, options = {}) { const { excludePatterns = [], caseSensitive = false, maxDepth, fileTypes } = options; const results = []; async function search(currentPath, depth = 0) { if (maxDepth !== undefined && depth > maxDepth) return; const entries = await fs.readdir(currentPath, { withFileTypes: true }); for (const entry of entries) { const fullPath = path.join(currentPath, entry.name); try { await validatePath(fullPath); const relativePath = path.relative(rootPath, fullPath); const shouldExclude = excludePatterns.some(excludePattern => minimatch(relativePath, excludePattern, { dot: true })); if (shouldExclude) continue; const matchOptions = { dot: true, nocase: !caseSensitive }; if (minimatch(relativePath, pattern, matchOptions)) { if (!fileTypes || fileTypes.some(type => entry.name.endsWith(type))) { results.push(fullPath); } } if (entry.isDirectory()) { await search(fullPath, depth + 1); } } catch { continue; } } } await search(rootPath); return results; }

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/ahmetshbz1/filesystem-mcp'

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