Revert filesystem back to original cli arg sandboxing
This commit is contained in:
parent
4034df774e
commit
0b36cb4b54
1 changed files with 52 additions and 69 deletions
|
|
@ -17,28 +17,10 @@ import { minimatch } from 'minimatch';
|
|||
|
||||
// Command line argument parsing
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
let allowedDirectories: string[] = [];
|
||||
|
||||
let hasProjectsDirectory = false;
|
||||
|
||||
// If the projects directory has contents, use it as the root workspace
|
||||
const projectsContents = await fs.readdir('/projects');
|
||||
if (projectsContents.length > 0) {
|
||||
hasProjectsDirectory = true;
|
||||
allowedDirectories = projectsContents.map(dir =>
|
||||
normalizePath(path.resolve(expandHome(dir)))
|
||||
);
|
||||
}
|
||||
else {
|
||||
if (args.length === 0) {
|
||||
console.error("Usage: mcp-server-filesystem <allowed-directory> [additional-directories...]");
|
||||
process.exit(1);
|
||||
}
|
||||
allowedDirectories = args.map(dir =>
|
||||
normalizePath(path.resolve(expandHome(dir)))
|
||||
);
|
||||
}
|
||||
|
||||
// Normalize all paths consistently
|
||||
function normalizePath(p: string): string {
|
||||
|
|
@ -53,12 +35,15 @@ function expandHome(filepath: string): string {
|
|||
}
|
||||
|
||||
// Store allowed directories in normalized form
|
||||
const allowedDirectories = args.map(dir =>
|
||||
normalizePath(path.resolve(expandHome(dir)))
|
||||
);
|
||||
|
||||
// Validate that all directories exist and are accessible
|
||||
await Promise.all(allowedDirectories.map(async (dir) => {
|
||||
await Promise.all(args.map(async (dir) => {
|
||||
try {
|
||||
const stats = await fs.stat(dir);
|
||||
if (!stats.isDirectory() && !hasProjectsDirectory) {
|
||||
if (!stats.isDirectory()) {
|
||||
console.error(`Error: ${dir} is not a directory`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
|
@ -621,11 +606,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|||
const validPath = await validatePath(parsed.data.path);
|
||||
const info = await getFileStats(validPath);
|
||||
return {
|
||||
content: [{
|
||||
type: "text", text: Object.entries(info)
|
||||
content: [{ type: "text", text: Object.entries(info)
|
||||
.map(([key, value]) => `${key}: ${value}`)
|
||||
.join("\n")
|
||||
}],
|
||||
.join("\n") }],
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue