article
README
🚀 MCP本地文件服务器
MCP本地文件服务器允许用户借助MCP(管理控制面板)对本地文件进行访问与操作,为文件管理提供便利。
🚀 快速开始
本服务器的使用步骤如下:
- 克隆仓库:
git clone https://github.com/fmorus/mcp-local-file-server.git
cd mcp-local-file-server
- 安装依赖项:
npm install
- 启动服务器:
npm start
服务器将在 http://localhost:3000 运行。
📚 详细文档
📄 API 接口
列出文件
- GET
/files?dir={directory} - 列出指定目录中的所有文件
- 参数
dir是可选的(默认:当前目录)
读取文件
- GET
/file?path={file_path} - 读取文件内容
文件上传
- POST
/file - 上传文件
- 使用
multipart/form-data格式,字段名为file
更新文件
- PUT
/file - 更新文件内容
- 请求体:
{ "path": "file_path", "content": "new_content" }
删除文件
- DELETE
/file?path={file_path} - 删除文件或目录
💻 使用示例
基础用法
// 列出文件
fetch('http://localhost:3000/files')
.then(response => response.json())
.then(files => console.log(files));
// 读取文件
fetch('http://localhost:3000/file?path=/caminho/do/arquivo.txt')
.then(response => response.json())
.then(data => console.log(data.content));
// 文件上传
const formData = new FormData();
formData.append('file', arquivoParaUpload);
fetch('http://localhost:3000/file', {
method: 'POST',
body: formData
});
// 更新文件
fetch('http://localhost:3000/file', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
path: '/caminho/do/arquivo.txt',
content: 'Novo conteúdo'
})
});
// 删除文件
fetch('http://localhost:3000/file?path=/caminho/do/arquivo.txt', {
method: 'DELETE'
});
⚠️ 重要提示
⚠️ 重要提示
此服务器对系统文件有完全访问权限。请仅在安全可靠的环境中使用。
Scan to contact