Filesystem

v2.4.1
io.github.modelcontextprotocol/server-filesystem Checked 2 hours ago Published 4 days ago

Read, write, search and edit files, with access limited to allowed directories or client Roots

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

read_file Read File (Deprecated)

Read the complete contents of a file as text. DEPRECATED: Use read_text_file instead.

ParameterTypeDescription
path *stringThe file to read as text. Absolute, or relative to an allowed directory; it must resolve inside the allowed directories.
headintegerIf provided, returns only the first N lines of the file
tailintegerIf provided, returns only the last N lines of the file

read_text_file Read Text File

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. Use the 'head' parameter to read only the first N lines of a file, or the 'tail' parameter to read only the last N lines of a file. Operates on the file as text regardless of extension. Only works within allowed directories.

ParameterTypeDescription
path *stringThe file to read as text. Absolute, or relative to an allowed directory; it must resolve inside the allowed directories.
headintegerIf provided, returns only the first N lines of the file
tailintegerIf provided, returns only the last N lines of the file

read_media_file Read Media File

Read a file and return it as a base64-encoded content block with its MIME type. Image and audio files are returned as image/audio content; any other file type is returned as an embedded resource. Only works within allowed directories.

ParameterTypeDescription
path *stringThe image, audio or other file to read as base64. Absolute, or relative to an allowed directory; it must resolve inside the allowed directories.

read_multiple_files Read Multiple Files

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. Only works within allowed directories.

ParameterTypeDescription
paths *arrayArray of file paths to read. Each path must be a string pointing to a valid file within allowed directories.

write_file Write File

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.

ParameterTypeDescription
content *stringThe complete text the file will contain, replacing any it had
path *stringThe file to create, or to overwrite if it exists; its parent directory must exist. Absolute, or relative to an allowed directory; it must resolve inside the allowed directories.

append_file Append File

Append text to the end of a file, creating the file if it does not exist. The existing content is never changed or replaced. The text is appended exactly as given, with no newline added before or after it, so end it with a newline if the next append should start on a new line. Only works within allowed directories.

ParameterTypeDescription
content *stringText to append, exactly as given. No newline is added: end it with \n if the next append should start on a new line.
path *stringThe file to append to; it is created if it does not exist. Absolute, or relative to an allowed directory; it must resolve inside the allowed directories.

edit_file Edit File

Make line-based edits to a text file. Edits apply in order, each to the result of the ones before it, and each replaces the first match of its oldText with newText. oldText must match the file's text exactly, except that line endings (LF or CRLF) never matter and, when there is no exact match, a run of whole lines matches if each line is equal once leading and trailing whitespace is ignored (newText then takes the file's indentation). Whitespace inside a line must match. If any edit has no match, nothing is written and the error shows the closest lines of the file, numbered, to copy oldText fr…

ParameterTypeDescription
edits *arrayThe replacements to make, applied in order, each to the result of the ones before it. If any one has no match, none is written.
path *stringThe text file to edit. Absolute, or relative to an allowed directory; it must resolve inside the allowed directories.
dryRunbooleanPreview changes using git-style diff format

create_directory Create Directory

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. Only works within allowed directories.

ParameterTypeDescription
path *stringThe directory to create, with any missing parents; an existing directory is left as is. Absolute, or relative to an allowed directory; it must resolve inside the allowed directories.

list_directory List Directory

List the files and directories directly inside a path, each marked [FILE] or [DIR]. Use it to see what a directory contains; when you also need each entry's size or want entries sorted by size, use list_directory_with_sizes instead, and for a recursive view use directory_tree. Returns one line per entry. Only works within allowed directories.

ParameterTypeDescription
path *stringThe directory to list. Absolute, or relative to an allowed directory; it must resolve inside the allowed directories.

list_directory_with_sizes List Directory with Sizes

List the files and directories directly inside a path with each file's size, marked [FILE] or [DIR], sorted by name or by size, largest first (sortBy). Use it when sizes matter, such as finding the largest files; for names only, use list_directory, which returns less text. Returns one line per entry, followed by the totals. Only works within allowed directories.

ParameterTypeDescription
path *stringThe directory to list. Absolute, or relative to an allowed directory; it must resolve inside the allowed directories.
sortBystringSort entries by name or size

directory_tree Directory Tree

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), except at the last level when 'depth' limits the tree: those directories are not read and have no children array. The output is formatted with 2-space indentation for readability. Only works within allowed directories.

ParameterTypeDescription
path *stringThe directory at the root of the tree. Absolute, or relative to an allowed directory; it must resolve inside the allowed directories.
depthintegerHow many levels to descend: 1 lists only the entries directly in path. Directories at the last level have no children array. Omit for the whole tree.
excludePatternsarrayPatterns for entries to leave out, with their contents, matched against each entry's path relative to path. A pattern with no '*' matches that name at any depth ('node_modules' leaves out every node_m…

move_file Move File

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. Both source and destination must be within allowed directories.

ParameterTypeDescription
destination *stringIts new path, including the name; nothing may exist there yet. Absolute, or relative to an allowed directory; it must resolve inside the allowed directories.
source *stringThe file or directory to move or rename. Absolute, or relative to an allowed directory; it must resolve inside the allowed directories.

copy_file Copy File

Copy a file to a new location, without reading its content into the conversation. Copies one regular file, keeping its permissions and modification time; directories are not copied. If the destination exists, the operation will fail: it never overwrites. Both source and destination must be within allowed directories.

ParameterTypeDescription
destination *stringWhere to create the copy; nothing may exist there yet
source *stringThe file to copy

search_files Search Files

Find files and directories by NAME, not by content: this tool never reads or searches inside files. It walks the tree under 'path' and matches a glob pattern against each entry's path relative to 'path' (case-sensitive). Use '*.ext' to match entries directly under 'path', and '**/*.ext' or '**/name' to match at any depth. Returns full paths to all matching items. Great for finding files when you don't know their exact location. Only searches within allowed directories.

ParameterTypeDescription
path *stringThe directory to search under. Absolute, or relative to an allowed directory; it must resolve inside the allowed directories.
pattern *stringGlob matched against each entry's path relative to path, never its content: '*.ts' matches directly under path, '**/*.ts' at any depth.
excludePatternsarrayPatterns for entries to leave out, with their contents, matched against each entry's path relative to path. A pattern with no '*' matches that name at any depth ('node_modules' leaves out every node_m…

get_file_info Get File Info

Retrieve detailed metadata about a file or directory. Returns comprehensive information including size, creation time, last modified time, permissions, type and hard-link count. This tool is perfect for understanding file characteristics without reading the actual content. Only works within allowed directories.

ParameterTypeDescription
path *stringThe file or directory to describe. Absolute, or relative to an allowed directory; it must resolve inside the allowed directories.

list_allowed_directories List Allowed Directories

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.