MCP Filesystem
Give your agent secure, sandboxed read and write access to the local filesystem.
- Package:
@modelcontextprotocol/server-filesystem - Provider: Anthropic / MCP
Overview
The Filesystem MCP server gives your agent controlled access to read, write, list, and search files on the local filesystem. Access is scoped to one or more directories you specify — the agent cannot access paths outside the configured roots, making it safe to use in automated workflows.
Scope Your Directories Carefully
Only grant access to directories your agent genuinely needs. Avoid pointing it at sensitive locations like your home directory or system paths.
Getting Started
Install the package:
pnpm add @modelcontextprotocol/server-filesystemUse the server in your agent:
import { McpFilesystem } from "@iqai/adk";
const toolset = McpFilesystem({
env: {
ALLOWED_DIRECTORIES: "/path/to/your/project",
},
});
const tools = await toolset.getTools();import { McpToolset } from "@iqai/adk";
const toolset = new McpToolset({
name: "Filesystem MCP Client",
description: "Client for sandboxed local filesystem access",
transport: {
mode: "stdio",
command: "npx",
args: ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/your/project"],
},
});
const tools = await toolset.getTools();{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/path/to/your/project"
]
}
}
}Environment Variables
| Variable | Required | Description |
|---|---|---|
ALLOWED_DIRECTORIES | No | Comma-separated list of directories the agent is allowed to access |
Configuration
You can configure allowed directories via the ALLOWED_DIRECTORIES env var (comma-separated) or pass them directly as arguments in the Verbose/Claude Desktop configs:
# Single directory
npx -y @modelcontextprotocol/server-filesystem /home/user/projects
# Multiple directories
npx -y @modelcontextprotocol/server-filesystem /home/user/projects /tmp/workspaceAvailable Tools
read_filepath:stringtail:numberhead:number
read_fileDescription
Read the complete contents of a file as text. DEPRECATED: Use read_text_file instead.
read_text_filepath:stringtail:numberhead:number
read_text_fileDescription
Read the complete contents of a file from the file system as text. Handles various text encodings and provides detailed error messages if the file cannot be read. Use this tool when you need to examine the contents of a single file.
read_media_filepath:string
read_media_fileDescription
Read an image or audio file. Returns the base64 encoded data and MIME type. Only works within allowed directories.
read_multiple_filespaths:array
read_multiple_filesDescription
Read the contents of multiple files simultaneously. This is more efficient than reading files one by one when you need to analyze or compare multiple files. Each file's content is returned with its path as a reference. Failed reads for individual files won't stop the entire operation.
write_filepath:stringcontent:string
write_fileDescription
Create a new file or completely overwrite an existing file with new content. Use with caution as it will overwrite existing files without warning. Handles text content with proper encoding. Only works within allowed directories.
edit_filepath:stringedits:arraydryRun:boolean
edit_fileDescription
Make line-based edits to a text file. Each edit replaces exact line sequences with new content. Returns a git-style diff showing the changes made. Only works within allowed directories.
create_directorypath:string
create_directoryDescription
Create a new directory or ensure a directory exists. Can create multiple nested directories in one operation. If the directory already exists, this operation will succeed silently. Perfect for setting up directory structures for projects or ensuring required paths exist.
list_directorypath:string
list_directoryDescription
Get a detailed listing of all files and directories in a specified path. Results clearly distinguish between files and directories with [FILE] and [DIR] prefixes. This tool is essential for understanding directory structure and finding specific files within a directory.
list_directory_with_sizespath:stringsortBy:string
list_directory_with_sizesDescription
Get a detailed listing of all files and directories in a specified path, including sizes. Results clearly distinguish between files and directories with [FILE] and [DIR] prefixes. This tool is useful for understanding directory structure and finding specific files within a directory.
directory_treepath:stringexcludePatterns:array
directory_treeDescription
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).
move_filesource:stringdestination:string
move_fileDescription
Move or rename files and directories. Can move files between directories and rename them in a single operation. If the destination exists, the operation will fail. Works across different directories and can be used for simple renaming within the same directory.
search_filespath:stringpattern:stringexcludePatterns:array
search_filesDescription
Recursively search for files and directories matching a pattern. The patterns should be glob-style patterns that match paths relative to the working directory. Use pattern like '.ext' to match files in current directory, and '**/.ext' to match files in all subdirectories.
get_file_infopath:string
get_file_infoDescription
Retrieve detailed metadata about a file or directory. Returns comprehensive information including size, creation time, last modified time, permissions, and type. This tool is perfect for understanding file characteristics without reading the actual content. Only works within allowed directories.
list_allowed_directoriesNo parameters
list_allowed_directoriesNo parameters
Description
Returns the list of directories that this server is allowed to access. Subdirectories within these allowed directories are also accessible. Use this to understand which directories and their nested paths are available before trying to access files.
Integration Example
import { AgentBuilder, McpFilesystem } from "@iqai/adk";
import * as dotenv from "dotenv";
dotenv.config();
async function main() {
// Initialize McpFilesystem toolset
const toolset = McpFilesystem({
env: {
ALLOWED_DIRECTORIES: process.cwd(),
},
});
// Get available McpFilesystem tools
const filesystemTools = await toolset.getTools();
// Create agent with McpFilesystem tools
const { runner } = await AgentBuilder.create("filesystem_agent")
.withModel("gemini-2.5-flash")
.withDescription(
"An agent that can read and write files in the current project directory",
)
.withTools(...filesystemTools)
.build();
const response = await runner.ask(
"List all TypeScript files in the src directory and show me the contents of index.ts",
);
console.log(response);
}
main().catch(console.error);