Config tweaks for docker

- Remove `$` interpolation for env
- Allow puppeteer to work headless in docker, headful with npx
This commit is contained in:
colinmcneil
2024-12-18 11:00:11 -05:00
committed by Jim Clark
parent 308b71c698
commit c64f8de15f
12 changed files with 78 additions and 65 deletions

View File

@@ -22,4 +22,6 @@ ENV NODE_ENV=production
RUN npm ci --ignore-scripts --omit-dev
ENTRYPOINT ["node", "dist/index.js"]
WORKDIR /projects
ENTRYPOINT ["node", "/app/dist/index.js"]

View File

@@ -109,6 +109,7 @@ Add this to your `claude_desktop_config.json`:
Note: you can provide sandboxed directories to the server by mounting them to `/projects`. Adding the `ro` flag will make the directory readonly by the server.
### Docker
Note: all directories must be mounted to `/projects` by default.
```json
{
@@ -122,7 +123,6 @@ 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=/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",
"--env", "DOCKER_ROOT_WORKSPACE=/projects",
"ai/mcp-filesystem"
]
}

View File

@@ -20,8 +20,15 @@ const args = process.argv.slice(2);
let allowedDirectories: string[] = [];
if (process.env.DOCKER_ROOT_WORKSPACE) {
allowedDirectories = await fs.readdir(process.env.DOCKER_ROOT_WORKSPACE);
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) {
@@ -51,7 +58,7 @@ function expandHome(filepath: string): string {
await Promise.all(allowedDirectories.map(async (dir) => {
try {
const stats = await fs.stat(dir);
if (!stats.isDirectory()) {
if (!stats.isDirectory() && !hasProjectsDirectory) {
console.error(`Error: ${dir} is not a directory`);
process.exit(1);
}
@@ -262,7 +269,7 @@ function createUnifiedDiff(originalContent: string, newContent: string, filepath
async function applyFileEdits(
filePath: string,
edits: Array<{oldText: string, newText: string}>,
edits: Array<{ oldText: string, newText: string }>,
dryRun = false
): Promise<string> {
// Read file content and normalize line endings
@@ -398,10 +405,10 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
{
name: "directory_tree",
description:
"Get a recursive tree view of files and directories as a JSON structure. " +
"Each entry includes 'name', 'type' (file/directory), and 'children' for directories. " +
"Files have no children array, while directories always have a children array (which may be empty). " +
"The output is formatted with 2-space indentation for readability. Only works within allowed directories.",
"Get a recursive tree view of files and directories as a JSON structure. " +
"Each entry includes 'name', 'type' (file/directory), and 'children' for directories. " +
"Files have no children array, while directories always have a children array (which may be empty). " +
"The output is formatted with 2-space indentation for readability. Only works within allowed directories.",
inputSchema: zodToJsonSchema(DirectoryTreeArgsSchema) as ToolInput,
},
{
@@ -538,49 +545,49 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
};
}
case "directory_tree": {
const parsed = DirectoryTreeArgsSchema.safeParse(args);
if (!parsed.success) {
throw new Error(`Invalid arguments for directory_tree: ${parsed.error}`);
}
interface TreeEntry {
name: string;
type: 'file' | 'directory';
children?: TreeEntry[];
}
async function buildTree(currentPath: string): Promise<TreeEntry[]> {
const validPath = await validatePath(currentPath);
const entries = await fs.readdir(validPath, {withFileTypes: true});
const result: TreeEntry[] = [];
for (const entry of entries) {
const entryData: TreeEntry = {
name: entry.name,
type: entry.isDirectory() ? 'directory' : 'file'
};
if (entry.isDirectory()) {
const subPath = path.join(currentPath, entry.name);
entryData.children = await buildTree(subPath);
}
result.push(entryData);
}
return result;
}
const treeData = await buildTree(parsed.data.path);
return {
content: [{
type: "text",
text: JSON.stringify(treeData, null, 2)
}],
};
case "directory_tree": {
const parsed = DirectoryTreeArgsSchema.safeParse(args);
if (!parsed.success) {
throw new Error(`Invalid arguments for directory_tree: ${parsed.error}`);
}
interface TreeEntry {
name: string;
type: 'file' | 'directory';
children?: TreeEntry[];
}
async function buildTree(currentPath: string): Promise<TreeEntry[]> {
const validPath = await validatePath(currentPath);
const entries = await fs.readdir(validPath, { withFileTypes: true });
const result: TreeEntry[] = [];
for (const entry of entries) {
const entryData: TreeEntry = {
name: entry.name,
type: entry.isDirectory() ? 'directory' : 'file'
};
if (entry.isDirectory()) {
const subPath = path.join(currentPath, entry.name);
entryData.children = await buildTree(subPath);
}
result.push(entryData);
}
return result;
}
const treeData = await buildTree(parsed.data.path);
return {
content: [{
type: "text",
text: JSON.stringify(treeData, null, 2)
}],
};
}
case "move_file": {
const parsed = MoveFileArgsSchema.safeParse(args);
if (!parsed.success) {
@@ -614,9 +621,11 @@ 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)
.map(([key, value]) => `${key}: ${value}`)
.join("\n") }],
content: [{
type: "text", text: Object.entries(info)
.map(([key, value]) => `${key}: ${value}`)
.join("\n")
}],
};
}