Allow filesystem to accept DOCKER_ROOT_WORKSPACE
This commit is contained in:
parent
4e8a8d270a
commit
bb0adaafd8
2 changed files with 17 additions and 8 deletions
|
|
@ -122,6 +122,7 @@ Note: you can provide sandboxed directories to the server by mounting them to `/
|
||||||
"--mount", "type=bind,src=/Users/username/Desktop,dst=/projects/Desktop",
|
"--mount", "type=bind,src=/Users/username/Desktop,dst=/projects/Desktop",
|
||||||
"--mount", "type=bind,src=/path/to/other/allowed/dir,dst=/projects/other/allowed/dir,ro",
|
"--mount", "type=bind,src=/path/to/other/allowed/dir,dst=/projects/other/allowed/dir,ro",
|
||||||
"--mount", "type=bind,src=/path/to/file.txt,dst=/projects/path/to/file.txt",
|
"--mount", "type=bind,src=/path/to/file.txt,dst=/projects/path/to/file.txt",
|
||||||
|
"--env", "DOCKER_ROOT_WORKSPACE=/projects",
|
||||||
"ai/mcp-filesystem"
|
"ai/mcp-filesystem"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,20 @@ import { minimatch } from 'minimatch';
|
||||||
|
|
||||||
// Command line argument parsing
|
// Command line argument parsing
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
if (args.length === 0) {
|
|
||||||
console.error("Usage: mcp-server-filesystem <allowed-directory> [additional-directories...]");
|
let allowedDirectories: string[] = [];
|
||||||
process.exit(1);
|
|
||||||
|
if (process.env.DOCKER_ROOT_WORKSPACE) {
|
||||||
|
allowedDirectories = await fs.readdir(process.env.DOCKER_ROOT_WORKSPACE);
|
||||||
|
}
|
||||||
|
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
|
// Normalize all paths consistently
|
||||||
|
|
@ -35,12 +46,9 @@ function expandHome(filepath: string): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store allowed directories in normalized form
|
// Store allowed directories in normalized form
|
||||||
const allowedDirectories = args.map(dir =>
|
|
||||||
normalizePath(path.resolve(expandHome(dir)))
|
|
||||||
);
|
|
||||||
|
|
||||||
// Validate that all directories exist and are accessible
|
// Validate that all directories exist and are accessible
|
||||||
await Promise.all(args.map(async (dir) => {
|
await Promise.all(allowedDirectories.map(async (dir) => {
|
||||||
try {
|
try {
|
||||||
const stats = await fs.stat(dir);
|
const stats = await fs.stat(dir);
|
||||||
if (!stats.isDirectory()) {
|
if (!stats.isDirectory()) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue