We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/patelnav/my-tools-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
path-validator.ts•1.48 KiB
/**
* Path validation module for tool documentation
*
* Handles validation of project paths and directory access checks.
*/
import path from 'path';
import { access, stat } from 'fs/promises';
import { constants } from 'fs';
import { logger } from './logger';
/**
* Validates a project path for security and accessibility
* @param projectPath The path to validate
* @returns Promise<boolean> indicating if the path is valid and accessible
*/
export async function validateProjectPath(projectPath: string): Promise<boolean> {
try {
// Resolve to absolute path
const absolutePath = path.resolve(projectPath);
logger.debug(`Validating project path: ${absolutePath}`);
// Check if path exists and is a directory
const stats = await stat(absolutePath);
if (!stats.isDirectory()) {
logger.warn(`Project path is not a directory: ${absolutePath}`);
return false;
}
// Check if we have read access
await access(absolutePath, constants.R_OK);
return true;
} catch (error) {
logger.warn(`Error validating project path: ${error}`);
return false;
}
}
/**
* Confirms that a directory exists and is accessible
* @param projectPath The path to check
* @returns Promise<boolean> indicating if the directory exists and is accessible
*/
export async function confirmDirectoryExists(projectPath: string): Promise<boolean> {
try {
const stats = await stat(projectPath);
return stats.isDirectory();
} catch {
return false;
}
}