文件系统MCP服务器
](https://www.npmjs.com/package/%40j0hanz%2Ffilesystem-mcp) 
 
用于读取、写入、搜索、区分和修补文件的安全文件系统MCP服务器。
目录
- 概述
- 主要特点
- 客户端配置
- 用例
- 建筑
- MCP表面 — 工具 · 资源 · 提示
- MCP能力 — 工具注释 · 结构化输出
- 配置 — HTTP和身份验证 · 文件大小限制 · 访问控制 · 输出和在线限制 · 任务 · 记录和诊断 · 演出
- HTTP端点
- 安全
- 发展
- 故障排除
- 学分
- 贡献和许可
概述
安全、生产就绪 模型上下文协议 服务器,使AI助手能够控制对本地文件系统的访问。所有操作都被沙盒化到明确允许的目录,具有路径遍历防止、敏感文件阻止和可选的承载令牌身份验证功能。
支持stdio(默认)和节点流式HTTP传输。HTTP会话是使用隔离的每会话服务器状态实现的。默认情况下,HTTP传输是有状态的,目前不可恢复;它不会持久化事件存储 Last-Event-ID 重播。
主要特点
- 18个文件系统工具 --具有结构化输出模式的读、写、搜索、差异、补丁、哈希和批量操作
- 安全第一 -路径验证、符号链接转义防止、敏感文件denylist、localhost-only CORS、环回HTTP绑定的主机头验证、可选API密钥验证
- 双重运输 --stdio用于本地使用,Node Streamable HTTP用于网络/多会话部署
- 结构化输出 --所有工具返回类型
outputSchema/structuredContent用于可靠的LLM解析 - 自我记录 --6个内置资源(
internal://instructions,internal://tool-catalog等)和4个内置提示(get-help,compare-files,analyze-path,get-tool-help)
需求
- Node.js>=24
快速开始
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
}
}码头工人
docker run -i --rm -v /path/to/project:/workspace:ro ghcr.io/j0hanz/filesystem-mcp /workspace或者使用Docker Compose:
services:
filesystem-mcp:
build: .
stdin_open: true
volumes:
- ./:/projects/workspace:ro
command: ['/projects/workspace']CLI使用情况
filesystem-mcp [options] [allowedDirs...]
Arguments:
allowedDirs Directories the server can access
Options:
--allow-cwd Allow the current working directory as an additional root
--port Enable HTTP transport on the given port
-v, --version Display server version
-h, --help Display help
Examples:
$ npx @j0hanz/filesystem-mcp@latest /path/to/project
$ npx @j0hanz/filesystem-mcp@latest --allow-cwd
$ npx @j0hanz/filesystem-mcp@latest --port 3000 /path/to/project客户端配置
Install in VS Code

添加 .vscode/mcp.json:
{
"servers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
}
}或通过CLI安装:
code --add-mcp '{"name":"filesystem","command":"npx","args":["-y","@j0hanz/filesystem-mcp@latest"]}'Install in VS Code Insiders

添加 .vscode/mcp.json:
{
"servers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
}
}或通过CLI安装:
code-insiders --add-mcp '{"name":"filesystem","command":"npx","args":["-y","@j0hanz/filesystem-mcp@latest"]}'Install in Cursor

添加 ~/.cursor/mcp.json:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
}
}Install in Visual Studio

添加 .mcp.json 或 %USERPROFILE%\.mcp.json:
{
"servers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
}
}Install in Goose
添加 ~/.config/goose/config.yaml:
extensions:
filesystem:
name: Filesystem MCP
cmd: npx
args:
- -y
- '@j0hanz/filesystem-mcp@latest'
enabled: true
type: stdioAdd to LM Studio

{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
}
}Install in Claude Desktop
添加 claude_desktop_config.json:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
}
}Install in Claude Code
claude mcp add filesystem-mcp -- npx -y @j0hanz/filesystem-mcp@latest或者添加一个项目范围 .mcp.json:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
}
}Install in Windsurf
添加 ~/.codeium/windsurf/mcp_config.json:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
}
}Install in Amp
amp mcp add filesystem-mcp -- npx -y @j0hanz/filesystem-mcp@latest或添加到 settings.json:
{
"amp.mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
}
}Install in Cline
添加 cline_mcp_settings.json:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
}
}Install in Codex
codex mcp add filesystem -- npx -y @j0hanz/filesystem-mcp@latest或添加到 ~/.codex/config.toml (或 .codex/config.toml 在受信任的项目中):
[mcp_servers.filesystem]
command = "npx"
args = ["-y", "@j0hanz/filesystem-mcp@latest"]Install in GitHub Copilot Coding Agent
将此JSON添加到存储库的GitHub Copilot编码代理MCP配置中:
{
"mcpServers": {
"filesystem": {
"type": "local",
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"],
"tools": ["*"]
}
}
}Install in Warp
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
}
}Install in Kiro
添加 .kiro/settings/mcp.json:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
}
}Install in Gemini CLI
添加 ~/.gemini/settings.json:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
}
}Install in Zed
添加 ~/.config/zed/settings.json:
{
"context_servers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"],
"env": {}
}
}
}Install in Augment
添加到VS代码 settings.json 在...之下 augment.advanced:
{
"augment.advanced": {
"mcpServers": [
{
"id": "filesystem",
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
]
}
}Install in Roo Code
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
}
}Install in Kilo Code
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@j0hanz/filesystem-mcp@latest"]
}
}
}用例
探索和理解代码库
发现项目结构并浏览不熟悉的存储库。从...开始 roots 要查看允许的目录,请使用 tree 为了概述, find 按模式定位文件,以及 read 或 read_many 检查内容。
相关工具: roots, ls, find, tree, read, read_many, stat
跨文件搜索
在项目中查找特定的代码模式、函数定义或配置值。使用 grep 用于支持正则表达式的内容搜索 find 用于文件名匹配。
编辑和重构代码
对源文件进行精确、有针对性的编辑。使用 edit 用于具有模拟运行预览的手术置换,或 search_and_replace 用于在匹配glob模式的多个文件之间进行批量更改。
相关工具: edit, search_and_replace, write
Diff和补丁工作流
比较文件版本并应用补丁。生成一个统一的差异 diff_files,预览 apply_patch(dryRun: true),然后申请。支持单文件和多文件补丁(每个文件尽最大努力 results[]).
相关工具: diff_files, apply_patch
文件管理
创建目录、移动/重命名文件、删除文件,并通过SHA-256哈希验证文件完整性。
相关工具: mkdir, mv, rm, calculate_hash, write
建筑
[MCP Client]
|
| Transport: stdio (default) or Node Streamable HTTP (--port)
v
[MCP Server: filesystem-mcp]
| Entry: src/index.ts -> src/server/bootstrap.ts
|
+-- initialize / initialized
|
+-- tools/call ──────────────────────────────────────────
| +-- [roots] — List allowed workspace roots
| +-- [ls] — List directory contents
| +-- [find] — Find files by glob
| +-- [tree] — Render directory tree
| +-- [read] — Read file contents
| +-- [read_many] — Read multiple files
| +-- [stat] — Get file metadata
| +-- [stat_many] — Get multiple file metadata
| +-- [grep] — Search file contents
| +-- [mkdir] — Create directory
| +-- [write] — Write file
| +-- [edit] — Edit file (string replacements)
| +-- [mv] — Move/rename file
| +-- [rm] — Delete file
| +-- [calculate_hash] — SHA-256 hash
| +-- [diff_files] — Unified diff
| +-- [apply_patch] — Apply unified patch
| +-- [search_and_replace]— Bulk search & replace
|
+-- resources/read ──────────────────────────────────────
| +-- internal://instructions
| +-- internal://tool-catalog
| +-- internal://workflows
| +-- internal://tool-info/{name}
| +-- filesystem-mcp://result/{id}
| +-- filesystem-mcp://metrics
|
+-- prompts/get ─────────────────────────────────────────
| +-- get-help (optional topic argument)
| +-- compare-files (original, modified)
| +-- analyze-path (path)
| +-- get-tool-help (name)
|
+-- Capabilities: logging, resources, tools, prompts, completions, tasks请求的生命周期
[Client] -- initialize {protocolVersion, capabilities} --> [Server]
[Server] -- {protocolVersion, capabilities, serverInfo} --> [Client]
[Client] -- notifications/initialized --> [Server]
[Client] -- tools/call {name, arguments} --> [Server]
[Server] -- validate(inputSchema) --> [Handler]
[Handler] -- {content: [{type, text}], structuredContent?, isError?} --> [Client]MCP表面
工具
roots · ls · find · tree · read · read_many · stat · stat_many · grep · mkdir · write · edit · mv · rm · calculate_hash · diff_files · apply_patch · search_and_replace
roots
列出允许的工作区根。首先调用——所有其他工具的作用域都在这些目录中。
_没有参数。_
______________________________________________________________________
ls
列出即时目录内容:名称、路径、类型、大小、修改日期。
| 参数 | 类型 | 必填 | 说明 | |||
|---|---|---|---|---|---|---|
path | string | no | 基本目录(默认:root) | |||
includeHidden | boolean | 否 | 包括点文件。违约: false | |||
includeIgnored | boolean | no | 包含被忽略的项(node_modules、.git)。违约: false | |||
maxDepth | integer | no | 提供模式时的最大递归深度(1-50) | |||
maxEntries | integer | no | 截断前的最大条目数。默认值:20000,最大值:20000 | |||
sortBy | enum | 否 | name | size | modified | type默认值: name |
pattern | string | no | 相对全局过滤器(例如。 **/*.ts).绝对路径和 .. 被拒绝 | |||
includeSymlinkTargets | boolean | no | 解析符号链接目标。违约: false | |||
cursor | string | no | 来自先前响应的分页光标 |
______________________________________________________________________
find
按glob模式查找文件。返回具有元数据的匹配文件。
| 参数 | 类型 | 必填 | 说明 | |||
|---|---|---|---|---|---|---|
path | string | no | 基本目录(默认:root) | |||
pattern | 字符串 | 是 | 相对球体模式(例如。 **/*.ts).绝对路径和 .. 被拒绝 | |||
maxResults | integer | 否 | 最大结果(1-10000)。默认值:100 | |||
includeIgnored | boolean | 否 | 包括忽略的项目。违约: false | |||
includeHidden | boolean | 否 | 包括点文件。违约: false | |||
sortBy | enum | 否 | path | name | size | modified默认值: path |
maxDepth | integer | 否 | 最大目录深度(0-100) | |||
cursor | string | no | 分页光标 |
______________________________________________________________________
tree
使用有界递归渲染目录树。返回ASCII树+结构化JSON。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
path | string | no | 基本目录(默认:root) |
maxDepth | integer | no | 深度(0=仅根节点)。默认值:5,最大值:50 |
maxEntries | integer | 否 | 最大条目数。默认值:1000,最大值:20000 |
includeHidden | boolean | 否 | 包括点文件。违约: false |
includeIgnored | boolean | 否 | 包括忽略的项目。违约: false |
includeSizes | boolean | 否 | 在树条目中包含文件大小。违约: false |
______________________________________________________________________
read
读取文本文件内容。使用 head/tail 预览大文件的前/后N行。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
path | 字符串 | 是 | 文件的绝对路径 |
head | integer | 否 | 读取前N行(1-100000) |
tail | integer | 否 | 读取最后N行(1-100000) |
startLine | integer | no | 起始行(从1开始,含1) |
endLine | integer | no | 结束行(从1开始,含1)。需要 startLine |
includeHash | boolean | 否 | 包含完整文件内容的SHA-256哈希值。违约: false |
______________________________________________________________________
read_many
在一个请求中读取多个文本文件。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
paths | string\[\] | 是 | 要读取的文件(1-100个路径) |
head | integer | no | 读取每个文件的前N行 |
tail | integer | no | 读取每个文件的最后N行 |
startLine | integer | no | 每个文件的起始行(从1开始) |
endLine | integer | no | 每个文件的结束行(从1开始) |
______________________________________________________________________
stat
获取文件/目录元数据:大小、已修改、权限、mime、tokenEstimate。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
path | 字符串 | 是 | 文件或目录的绝对路径 |
______________________________________________________________________
stat_many
在一个请求中获取多个文件/目录的元数据。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
paths | string\[\] | 是 | 文件/目录路径(1-100) |
______________________________________________________________________
grep
搜索文件内容(类似grep)。返回具有可选上下文的匹配行。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
path | string | no | 基本目录(默认:root) |
pattern | 字符串 | 是 | 在以下情况下搜索文本或RE2正则表达式 isRegex=true |
isRegex | boolean | no | 将模式视为RE2正则表达式。违约: false |
caseSensitive | boolean | 否 | 区分大小写的匹配。违约: false |
wholeWord | boolean | no | 仅匹配整个单词。违约: false |
contextLines | integer | no | 前后行上下文(0-50)。默认值:0 |
maxResults | integer | no | 最大匹配行数(0-10000)。默认值:500 |
filePattern | string | no | 候选文件的相对全局值(例如。 **/*.ts).违约: **/* |
includeHidden | boolean | 否 | 包括点文件。违约: false |
includeIgnored | boolean | 否 | 包括忽略的项目。违约: false |
______________________________________________________________________
mkdir
创建一个新目录(递归)。我暂时没有。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
path | string | no | 要创建的目录的绝对路径 |
paths | string\[\] | no | 要创建多个目录。要么 path 或 paths 必填项 |
______________________________________________________________________
write
将内容写入文件, 覆盖所有现有内容。如果需要,创建父目录。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
path | 字符串 | 是 | 文件的绝对路径 |
content | 字符串 | 是 | 要写的内容 |
______________________________________________________________________
edit
应用连续的文字字符串替换(每次编辑第一次出现)。使用 dryRun 预览。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
path | 字符串 | 是 | 文件的绝对路径 |
edits | 阵列 | 是 | 非空列表 {oldText, newText} 替代品 |
dryRun | boolean | no | 预览编辑而不写入。违约: false |
ignoreWhitespace | boolean | no | 将空白序列视为等效序列。违约: false |
______________________________________________________________________
mv
移动或重命名文件或目录。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
source | string | no | 要移动的单个路径(已弃用:使用 sources) |
sources | string\[\] | no | 要移动的路径。要么 source 或 sources 必填项 |
destination | 字符串 | 是 | 目的地路径 |
______________________________________________________________________
rm
永久删除文件或目录。 不可逆转。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
path | 字符串 | 是 | 文件或目录的绝对路径 |
recursive | boolean | no | 删除非空目录。违约: false |
ignoreIfNotExists | boolean | 否 | 如果缺少,则没有错误。违约: false |
______________________________________________________________________
calculate_hash
计算文件或目录的SHA-256哈希值。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
path | 字符串 | 是 | 文件或目录的绝对路径 |
______________________________________________________________________
diff_files
在两个文件之间生成统一的差异。输出直接馈入 apply_patch.
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
original | 字符串 | 是 | 原始文件的路径 |
modified | 字符串 | 是 | 修改文件的路径 |
context | integer | no | diff输出中的上下文行 |
ignoreWhitespace | boolean | no | 忽略前导/尾随空格。违约: false |
stripTrailingCr | boolean | no | 条尾回车。违约: false |
______________________________________________________________________
apply_patch
对一个或多个文件应用统一的差异补丁。单文件:失败时抛出。多文件:每个文件尽最大努力 results[].工作流程: diff_files -> apply_patch(dryRun) -> apply_patch.
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
path | 字符串 | 是 | 文件路径(单个)或基本目录(多文件补丁) |
patch | 字符串 | 是 | 统一差异 @@ 大块头文件(单个或多个文件) |
fuzzFactor | integer | no | 每个块的最大模糊不匹配(0-20) |
autoConvertLineEndings | boolean | no | 自动转换行尾。违约: true |
dryRun | boolean | no | 无需写入即可验证。违约: false |
______________________________________________________________________
search_and_replace
在与glob匹配的文件之间进行批量搜索和替换。替换 全部 每个文件的出现次数。总是 dryRun: true 第一。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
path | string | no | 基本目录(默认:root) |
filePattern | string | no | 相对全局模式(例如。 **/*.ts).违约: **/* |
searchPattern | 字符串 | 是 | 要搜索的文本。RE2正则表达式 isRegex=true |
replacement | 字符串 | 是 | 替换文本。支持 $1, $2 使用正则表达式 |
isRegex | boolean | no | 视为RE2正则表达式。违约: false |
dryRun | boolean | no | 预览与差异匹配。默认值: false |
includeHidden | boolean | 否 | 包括点文件。违约: false |
includeIgnored | boolean | 否 | 包括忽略的项目。违约: false |
returnDiff | boolean | no | 即使不是空运行,也会返回diff。违约: false |
maxFiles | integer | no | 停止前要处理的最大文件数(1-10000) |
caseSensitive | boolean | 否 | 区分大小写的匹配。违约: true |
资源
| 资源 | URI | MIME类型 | 描述 |
|---|---|---|---|
| 使用说明 | internal://instructions | text/markdown | 全面的使用规则和指南 |
| 工具目录 | internal://tool-catalog | text/markdown | 工具选择指南和数据流图 |
| 工作流程 | internal://workflows | text/markdown | 探索、搜索、编辑、补丁的标准操作程序 |
| 工具信息 | internal://tool-info/{name} | text/markdown | 每个工具的合同细节、细微差别、陷阱 |
| 结果缓存 | filesystem-mcp://result/{id} | text/plain | 临时缓存工具输出(此处外部化了大结果) |
| 指标 | filesystem-mcp://metrics | application/json | 实时工具调用/错误/avgDurationMs快照 |
提示
| 提示 | 参数 | 描述 |
|---|---|---|
get-help | topic (可选) | 返回使用说明。可选择按节标题前缀过滤 |
compare-files | original, modified | 使用以下命令生成用于比较两个文件的工作流 diff_files |
analyze-path | path | 生成用于分析文件或目录的工作流 |
get-tool-help | name | 返回一个提示,其中包含特定工具的权威合同 |
MCP能力
| 能力 | 状态 | 证据 |
|---|---|---|
logging | 已确认 | src/server/bootstrap.ts --已注册功能 |
resources | 已确认 | src/server/bootstrap.ts --已注册6个资源 |
tools | 已确认 | src/server/bootstrap.ts --已注册18个工具 |
prompts | 已确认 | src/server/bootstrap.ts --已注册4个提示 |
completions | 已确认 | src/completions.ts --路径、主题和工具名称自动完成 |
tasks | 已确认 | src/server/bootstrap.ts --可选任务支持(列表、取消、请求) |
工具注释
| 注释 | 工具 | 值 |
|---|---|---|
readOnlyHint: true | roots, ls, find, tree, read, read_many, stat, stat_many, grep, calculate_hash, diff_files | 只读、幂等、非破坏性 |
destructiveHint: true | write, edit, rm, mv, search_and_replace, apply_patch | 破坏性写作,不幂等 |
idempotentHint: true | mkdir | 即时写入,非破坏性 |
结构化输出
所有18个工具定义 outputSchema (Zod->JSON模式)并返回 structuredContent 旁边文字 content.Set FS_CONTEXT_STRIP_STRUCTURED=true 从工具定义中剥离输出模式(减少不使用结构化输出的LLM的令牌使用)。
配置
HTTP和身份验证
| 变量 | 默认值 | 描述 |
|---|---|---|
FILESYSTEM_MCP_API_KEY | _(无)_ | 将HTTP绑定到非环回主机时需要承载令牌 |
FILESYSTEM_MCP_MAX_HTTP_SESSIONS | 100 | 最大并发HTTP会话数(1-10000) |
FILESYSTEM_MCP_HTTP_HOST | 127.0.0.1 | HTTP服务器绑定地址 |
FS_CONTEXT_MAX_REQUEST_BYTES | 4194304 (4 MB) | 最大HTTP请求体大小(1 KB-256 MB) |
文件大小限制
| 变量 | 默认值 | 描述 |
|---|---|---|
MAX_FILE_SIZE | 10485760 (10 MB) | 文本读取操作的最大文件大小(1 MB-100 MB) |
MAX_SEARCH_SIZE | 1048576 (1 MB) | 内容搜索/grep的最大文件大小(100 KB-10 MB) |
MAX_READ_MANY_TOTAL_SIZE | 524288 (512 KB) | 的最大累积大小 read_many 请求(10 KB-100 MB) |
DEFAULT_SEARCH_TIMEOUT | 5000 | 搜索操作超时(毫秒)(100-60000) |
访问控制
| 变量 | 默认值 | 描述 |
|---|---|---|
FS_CONTEXT_ALLOW_SENSITIVE | false | 允许读取敏感文件(.env、.key、凭据、令牌) |
FS_CONTEXT_DENYLIST | _(无)_ | CSV/换行符分隔的glob模式要阻止(除了内置的denylist) |
FS_CONTEXT_ALLOWLIST | _(无)_ | 允许CSV/换行分隔的glob模式(覆盖denylist) |
输出和在线限制
| 变量 | 默认值 | 描述 |
|---|---|---|
FS_CONTEXT_MAX_INLINE_CHARS | 20000 | 外部化之前的最大内联结果字符数 filesystem-mcp://result/{id} |
FS_CONTEXT_MAX_INLINE_MATCHES | 50 | 截断前的最大内联搜索匹配数 |
FS_CONTEXT_STRIP_STRUCTURED | false | 带钢 outputSchema 从工具定义(减少标记) |
任务
| 变量 | 默认值 | 描述 |
|---|---|---|
FILESYSTEM_MCP_MAX_TASK_TTL_MS | 3600000 (1小时) | 自动驱逐前的最大任务TTL(1秒-24小时) |
FILESYSTEM_MCP_MAX_CONCURRENT_TASKS | 100 | 最大并发任务执行数(1-10000) |
记录和诊断
| 变量 | 默认值 | 描述 |
|---|---|---|
FILESYSTEM_MCP_LOG_LEVEL | info | MCP日志级别:调试、信息、通知、警告、错误、严重、警报、紧急 |
FS_CONTEXT_DIAGNOSTICS | false | 启用诊断日志记录 |
FS_CONTEXT_DIAGNOSTICS_DETAIL | false | 启用详细的诊断输出 |
FS_CONTEXT_TOOL_LOG_ERRORS | false | 将工具错误记录到stderr |
FS_CONTEXT_SEARCH_WORKERS_DEBUG | false | 搜索工作池的调试日志记录 |
演出
| 变量 | 默认值 | 描述 |
|---|---|---|
FS_CONTEXT_SEARCH_WORKERS | CPU内核(≤8) | 并发搜索工作线程(1-16) |
FS_CONTEXT_LIST_CURSOR_TTL_MS | 300000 (5分钟) | 光标TTL ls 分页快照 |
HTTP端点
当开始时 --port ,服务器公开一个MCP端点:
| 方法 | 路径 | 目的 |
|---|---|---|
POST | /mcp | 初始化会话或发送请求(流式HTTP) |
GET | /mcp | HTTP流会话端点 |
DELETE | /mcp | 终止会话 |
所需标题:
mcp-protocol-version--在初始化后的HTTP请求上使用协商的MCP协议版本mcp-session-id--需要GET/DELETE(返回者POST初始化时)
身份验证: 对非环回HTTP绑定的请求需要 FILESYSTEM_MCP_API_KEY;然后客户必须发送 Authorization: Bearer 仅环回绑定可能会省略本地使用的身份验证。使用SHA-256定时安全比较。
CORS: 只允许本地主机来源(127.0.0.1, ::1, localhost).
主机验证: 环回HTTP绑定验证 Host 头球localhost, 127.0.0.1, [::1])以降低DNS重新绑定的风险。非环回绑定仍然需要 FILESYSTEM_MCP_API_KEY.
安全
| 控制 | 状态 | 证据 |
|---|---|---|
| 路径沙盒 | 已确认 | src/lib/paths.ts --根据允许的根验证所有路径 |
| 横向预防 | 已确认 | src/lib/paths.ts --归一化后检查的解析路径 |
| Symlink防逃逸 | 已确认 | src/__tests__/security.test.ts --符号链接边界执行 |
| 敏感文件目录 | 已确认 | src/lib/constants.ts --砌块 .git, .env*SSH密钥、证书、机密 |
| 原产地验证 | 已确认 | src/server/bootstrap.ts --仅限本地主机的源代码列表 |
| 承载身份验证 | 已确认 | src/server/bootstrap.ts --可选 FILESYSTEM_MCP_API_KEY 具有定时安全比较功能 |
| 输入验证 | 已确认 | src/schemas.ts --Zod对所有工具输入都有严格的模式 |
| 请求正文限制 | 已确认 | src/server/bootstrap.ts --可配置的最大请求大小(溢出时为413) |
| 远程绑定保护 | 已确认 | src/server/bootstrap.ts --拒绝非环回绑定 FILESYSTEM_MCP_API_KEY |
发展
dev—tsc --watch --preserveWatchOutput--观看模式TypeScript编译dev:run—node --env-file=.env --watch dist/index.js--使用自动重新加载运行服务器start—node dist/index.js--运行生产服务器build—node scripts/tasks.mjs build--清洁建筑test—node scripts/tasks.mjs test--构建并运行所有测试test:fast—node --test --import tsx/esm src/__tests__/**/*.test.ts node-tests/**/*.test.ts--运行测试而不进行构建lint—eslint .--棉绒来源type-check—node scripts/tasks.mjs type-check--类型检查src+测试format—prettier --write .--格式代码inspector—npm run build && npx -y @modelcontextprotocol/inspector node dist/index.js ${workspaceFolder}--启动MCP检查器
构建与发布
- CI:
.github/workflows/release.yml--在标记/发布之前运行lint、类型检查、测试、构建。 - Docker: 多阶段构建
node:24-alpine.Builder编译TypeScript+本机模块(re2);发布阶段以非root身份运行mcp用户。 - npm:
npm run prepublishOnly运行lint+类型检查+构建。
故障排除
- “不允许使用目录” --至少传递一个目录参数或使用
--allow-cwd. - 敏感文件被阻止 --与denylist匹配的文件(
.env*,.gitSSH密钥)被设计阻止。检查src/lib/constants.ts查看完整列表。 - 大型结果外部化 --当工具输出超过内联限制时,它会作为资源缓存在
filesystem-mcp://result/{id}。读取资源URI以获取完整内容。 - Stdio:stdout上的日志 --仅在stderr上保留日志。服务器使用
console.error用于诊断。 - HTTP 413 --请求正文超过
FS_CONTEXT_MAX_REQUEST_BYTES.增加限制或减小有效载荷大小。 - HTTP 401 —
FILESYSTEM_MCP_API_KEY已设置,但请求丢失或不正确Authorization: Bearer头球
学分
| 依赖关系 | 描述 |
|---|---|
| @模型上下文协议/服务器 | MCP服务器SDK包 |
| @模型上下文协议/客户端 | MCP客户端SDK包 |
| @模型上下文协议/节点 | MCP运行时的节点传输包 |
| 指挥官 | CLI参数解析 |
| 差异 | 统一的差异生成和补丁应用程序 |
| 忽视 | .gitignore 模式匹配 |
| re2 | 安全的RE2正则表达式引擎(无ReDoS) |
| 黄道带 | 模式验证和JSON模式生成 |
许可证
MIT许可证。看 许可证 了解详情。
