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.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。