MCP File Server
Provides secure, sandboxed filesystem operations including reading, writing, listing, searching, and managing files and directories within a configurable working directory with strict security controls.
README
š MCP File Server
MCP File Server is a secure, sandboxed file server providing controlled access to filesystem operations via the Model Control Protocol (MCP). It supports reading, writing, listing, creating, and deleting files and directories within a configurable working directory while enforcing strict security checks.
Table of Contents
- Features
- Installation & Quick Start
- CommandāLine Options
- Integration with LMāÆStudio
- MCP API Overview
- Available Tools
- Security Features
šÆ Features
- Sandboxed operations ā all paths are confined to a userāspecified working directory.
- Path traversal protection, fileāsize limits, and blocked extensions.
- Binary support via Base64 encoding for safe transport of nonātext data.
- Simple lineādelimited JSONāRPC protocol suitable for stdin/stdout integration.
- Readyātoāuse with LMāÆStudio through a minimal
mcp.jsonconfiguration.
š¦ Installation & Quick Start
# Clone the repository (if not already done)
git clone https://github.com/undici77/MCPFileServer.git
cd MCPFileServer
# Run the startup script ā it creates a virtual environment,
# installs dependencies, and starts the server.
./run.sh -d /path/to/working/directory
The script will:
- Verify that PythonāÆ3 is available.
- Create a
.venvvirtual environment (if missing). - Install required packages (
aiofiles). - Start
main.pywith the supplied working directory.
š Tip: Ensure the script has execution permission:
chmod +x run.sh
āļø CommandāLine Options
| Option | Description |
|---|---|
-d, --directory |
Path to the working directory. If omitted, the server uses the current process directory. The directory must exist and be readable/writable. |
š¤ Integration with LMāÆStudio
Add an entry for the file server in your project's mcp.json:
{
"mcpServers": {
"file-server": {
"command": "/absolute/path/to/MCPFileServer/run.sh",
"args": [
"-d",
"/absolute/path/to/working/directory"
],
"env": {
"WORKING_DIR": "."
}
}
}
}
- Replace the paths with absolute locations on your machine.
- Ensure
run.shis executable (chmod +x run.sh) and dependencies are installed.
š” MCP API Overview
All communication follows JSONāRPCāÆ2.0 over stdin/stdout.
initialize
Sent by the client to obtain server capabilities.
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {}
}
The server responds with protocol version, capabilities, and its name/version.
tools/list
Retrieves a machineāreadable list of supported tools.
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}
The response contains an array of tool definitions (name, description, input schema).
tools/call
Invokes a specific tool.
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "<tool_name>",
"arguments": { ⦠}
}
}
Note: The key for the tool name is
**name**, nottool. This matches the server implementation.
š ļø Available Tools
| Tool | Description |
|---|---|
read_file |
Read a fileās contents (text or binary). |
write_file |
Write text or Base64āencoded binary data to a file. |
list_files |
List files and directories with optional filtering. |
create_directory |
Create a new subādirectory (parents created as needed). |
delete_file |
Delete a single file. |
delete_directory |
Remove a directory; optionally force deletion of nonāempty trees. |
search_in_file |
Search for a string in a file or recursively in a directory, returning contextual excerpts. |
read_file
Read the contents of a file inside the working directory. Parameters
| Name | Type | Required | Description |
|---|---|---|---|
path |
string | ā | Relative path to the target file. |
binary |
boolean | ā (default: false) |
Set to true to read the file as binary; the result is Base64āencoded. |
| Example |
{
"method": "tools/call",
"params": {
"name": "read_file",
"arguments": {
"path": "example.txt",
"binary": false
}
}
}
write_file
Write content to a file (creating intermediate directories if needed). Parameters
| Name | Type | Required | Description |
|---|---|---|---|
path |
string | ā | Relative path of the target file. |
content |
string | ā | Text to write, or Base64āencoded binary data when binary=true. |
binary |
boolean | ā (default: false) |
Set to true to treat content as Base64āencoded binary. |
| Example |
{
"method": "tools/call",
"params": {
"name": "write_file",
"arguments": {
"path": "output.txt",
"content": "Hello, world!",
"binary": false
}
}
}
list_files
List files and directories under the working directory. Parameters
| Name | Type | Required | Description |
|---|---|---|---|
extensions |
array of strings | ā | Filter by file extensions (e.g., [".py", ".txt"]). If omitted, all files are listed. |
recursive |
boolean | ā (default: true) |
Search subādirectories recursively when true. |
show_empty_dirs |
boolean | ā (default: true) |
Include directories that contain no matching files. |
| Example |
{
"method": "tools/call",
"params": {
"name": "list_files",
"arguments": {
"extensions": [".py", ".txt"],
"recursive": true,
"show_empty_dirs": false
}
}
}
The response lists entries prefixed with DIR: or FILE: and includes a summary line.
create_directory
Create a new directory (including any missing parent directories). Parameters
| Name | Type | Required | Description |
|---|---|---|---|
path |
string | ā | Relative path of the directory to create. |
| Example |
{
"method": "tools/call",
"params": {
"name": "create_directory",
"arguments": { "path": "new_folder/subfolder" }
}
}
delete_file
Delete a file inside the working directory. Parameters
| Name | Type | Required | Description |
|---|---|---|---|
path |
string | ā | Relative path of the file to delete. |
| Example |
{
"method": "tools/call",
"params": {
"name": "delete_file",
"arguments": { "path": "temp.txt" }
}
}
delete_directory
Delete a directory, optionally forcing removal of its contents. Parameters
| Name | Type | Required | Description |
|---|---|---|---|
path |
string | ā | Relative path of the directory to delete. |
force |
boolean | ā (default: false) |
When true, deletes nonāempty directories recursively. |
| Example |
{
"method": "tools/call",
"params": {
"name": "delete_directory",
"arguments": { "path": "old_folder", "force": true }
}
}
search_in_file
Search for a string in a file or recursively in all files within a directory, returning contextual excerpts. Parameters
| Name | Type | Required | Description |
|---|---|---|---|
path |
string | ā | Relative path to a file or directory. |
search_string |
string | ā | Text to search for. |
context_lines |
integer | ā (default: 3) |
Number of lines before and after each match to include. |
case_sensitive |
boolean | ā (default: false) |
Perform a caseāsensitive search when true. |
max_matches |
integer | ā (default: 50) |
Maximum matches returned per file. |
| Example |
{
"method": "tools/call",
"params": {
"name": "search_in_file",
"arguments": {
"path": "log.txt",
"search_string": "ERROR",
"context_lines": 2,
"case_sensitive": false,
"max_matches": 10
}
}
}
The response contains formatted excerpts with line numbers and a summary of total matches.
š Security Features
- Path traversal protection ā all paths are resolved against the working directory; attempts to escape result in an error.
- Blocked extensions & sensitive filenames ā files such as
.exe,.bat,passwd, etc., are rejected. - Fileāsize limits ā reads/writes exceeding
100āÆMiB(MAX_FILE_SIZE) are denied. - Null byte and dangerous pattern checks ā prevent malformed input attacks.
Ā© 2025 Undici77 ā All rights reserved.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
E2B
Using MCP to run code via e2b.