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
import { promises as fs } from 'fs';
import path from 'path';
import os from 'os';
import { normalizePath } from '../utils/path-utils.js';
import { logger } from '../logger.js';
async function parseRootUri(rootUri) {
try {
const rawPath = rootUri.startsWith('file://') ? rootUri.slice(7) : rootUri;
const expandedPath = rawPath.startsWith('~/') || rawPath === '~' ? path.join(os.homedir(), rawPath.slice(1)) : rawPath;
const absolutePath = path.resolve(expandedPath);
const resolvedPath = await fs.realpath(absolutePath);
return normalizePath(resolvedPath);
}
catch {
return null;
}
}
function formatDirectoryError(dir, error, reason) {
if (reason)
return `Skipping ${reason}: ${dir}`;
const message = error instanceof Error ? error.message : String(error);
return `Skipping invalid directory: ${dir} due to error: ${message}`;
}
export async function getValidRootDirectories(requestedRoots) {
const validatedDirectories = [];
for (const requestedRoot of requestedRoots) {
const resolvedPath = await parseRootUri(requestedRoot.uri);
if (!resolvedPath) {
logger.error(formatDirectoryError(requestedRoot.uri, undefined, 'invalid path or inaccessible'));
continue;
}
try {
const stats = await fs.stat(resolvedPath);
if (stats.isDirectory())
validatedDirectories.push(resolvedPath);
else
logger.error(formatDirectoryError(resolvedPath, undefined, 'non-directory root'));
}
catch (error) {
logger.error(formatDirectoryError(resolvedPath, error));
}
}
return validatedDirectories;
}