mcpField
M
mcp-server-filesystem

mcp-server-filesystem

本地服务
github.com/bytedance文件与存储39.4k3 周前更新

关于 mcp-server-filesystem

FileSystem MCP Server 是一个提供文件系统操作的 MCP 服务,基于 Node.js 运行,可通过 npx 启动。它可在 VS Code、Cursor、Windsurf、Claude Desktop 等多种 MCP 客户端中使用。

主要功能

  1. 01通过 npx 启动的本地 stdio 服务
  2. 02支持 SSE 与 Streamable HTTP 远程端点
  3. 03可通过 --allowed-directories 限制访问目录
  4. 04可在 JavaScript/TypeScript 项目中以进程内方式调用

适用场景

  1. 01让 AI 助手读写本地项目目录中的文件
  2. 02在 Cursor 或 Claude Desktop 中为模型提供文件访问能力

MCP 相关

该项目是一个 MCP 服务,向 MCP 客户端提供文件系统操作能力。客户端可通过 stdio、SSE 或 Streamable HTTP 连接。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"bytedance-mcp-server-filesystem": {
"command": "npx",
"args": [
"-y",
"@agent-infra/mcp-server-filesystem"
]
}
}
}
启动命令npx -y @agent-infra/mcp-server-filesystem

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npm@agent-infra/mcp-server-filesystemlatest

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

文件系统 MCP 服务

NPM Downloads

Install MCP Server 在 VS Code 中安装 在 VS Code Insiders 中安装

一个提供文件系统操作的模型上下文协议(MCP)服务。

README 配图

要求
  • Node.js 18 或更高版本
  • VS Code、Cursor、Windsurf、Claude Desktop 或任何其他 MCP 客户端
快速开始
本地(Stdio)

首先,使用你的客户端安装文件系统 MCP 服务。典型配置如下:

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "@agent-infra/mcp-server-filesystem@latest"
      ]
    }
  }
}
在 VS Code 中安装

你也可以使用 VS Code CLI 安装文件系统 MCP 服务:

# For VS Code
code --add-mcp '{"name":"filesystem","command":"npx","args":["@agent-infra/mcp-server-filesystem@latest"]}'

安装后,即可在 VS Code 中将文件系统 MCP 服务与 GitHub Copilot Agent 搭配使用。

在 Cursor 中安装

前往 Cursor Settings -> MCP -> Add new MCP Server。名称可自行设置,选择 command 类型,并使用命令 npx @agent-infra/mcp-server-filesystem。你也可以点击 Edit 来检查配置或添加类似命令的参数。

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "@agent-infra/mcp-server-filesystem@latest",
        "--allowed-directories /tmp"
      ]
    }
  }
}
在 Windsurf 中安装

请参阅 Windsuff MCP 文档。使用以下配置:

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "@agent-infra/mcp-server-filesystem@latest",
        "--allowed-directories /tmp"
      ]
    }
  }
}
在 Claude Desktop 中安装

请参阅 MCP 安装指南,并使用以下配置:

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "@agent-infra/mcp-server-filesystem@latest",
        "--allowed-directories /tmp"
      ]
    }
  }
}
远程(SSE / Streamable HTTP)

同时,使用 --port $your_port 参数启动浏览器 MCP,即可将其转换为 SSE 和 Streamable HTTP 服务。

# normal run remote mcp server
npx @agent-infra/mcp-server-filesystem --port 8089 --allowed-directories <dir>

你可以使用以下两个 MCP 服务远程端点之一:

  • Streamable HTTP(推荐):http://127.0.0.1::8089/mcp
  • SSE:http://127.0.0.1::8089/sse

然后,在 MCP 客户端配置中,将 url 设置为 SSE 端点:

{
  "mcpServers": {
    "filesystem": {
      "url": "http://127.0.0.1::8089/sse"
    }
  }
}

url 设置为 Streamable HTTP:

{
  "mcpServers": {
    "filesystem": {
      "type": "streamable-http", // If there is MCP Client support
      "url": "http://127.0.0.1::8089/mcp"
    }
  }
}
内存中调用

如果你的 MCP 客户端基于 JavaScript / TypeScript 开发,可以直接使用进程内调用,避免要求用户安装命令行界面才能使用文件系统 MCP。

import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';

// type: module project usage
import { createServer } from '@agent-infra/mcp-server-filesystem';
// commonjs project usage
// const { createServer } = await import('@agent-infra/mcp-server-filesystem')

const client = new Client(
  {
    name: 'test filesystem client',
    version: '1.0',
  },
  {
    capabilities: {},
  },
);

const server = createServer();
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();

await Promise.all([
  client.connect(clientTransport),
  server.connect(serverTransport),
]);

// list tools
const result = await client.listTools();
console.log(result);

// call tool
const toolResult = await client.callTool({
  name: 'list_directory',
  arguments: {
    path: '~/your_computer'
  },
});
console.log(toolResult);
开发

访问 http://127.0.0.1:6274/:

npm run dev

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。