mcpField
W
WebDAV MCP Server

WebDAV MCP Server

本地服务
github.com/LaubPlusCo文件与存储1984 周前更新

关于 WebDAV MCP Server

WebDAV MCP 服务是一个基于 Basic 认证的 MCP 服务,可对 WebDAV 端点执行文件与目录的增删改查操作。适用于希望让 Claude Desktop 等客户端通过自然语言管理远程 WebDAV 文件的用户。

主要功能

  1. 01对远程 WebDAV 文件和目录进行增删改查
  2. 02支持 stdio 与 HTTP/SSE 两种传输方式
  3. 03可选的 Basic 认证与 bcrypt 加密的服务密码
  4. 04连接池与 Zod 配置校验

适用场景

  1. 01通过自然语言在远程 WebDAV 上创建或修改文件
  2. 02在 WebDAV 中移动、复制或重命名文件
  3. 03列出远程目录内容

MCP 相关

该项目是一个 MCP 服务,将 WebDAV 文件操作以 MCP 资源和工具的形式暴露给客户端。资源包括目录列表、文件内容和文件信息,工具包括创建、读取、更新、删除、移动和复制等操作。

配置

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

mcp.json · 通用配置
{
"mcpServers": {
"mpc-webdav-server": {
"command": "npx",
"args": [
"-y",
"webdav-mcp-server"
]
}
}
}
启动命令npx -y webdav-mcp-server

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

安装包
npmwebdav-mcp-server

工具

8

收录的工具列表 · 更新于 3 周前

参数类型必填说明
pathstring是
contentstring是
overwriteboolean否

详细介绍

WebDAV MCP 服务

一个 Model Context Protocol(MCP)服务,可通过基本身份验证在 WebDAV 端点上执行 CRUD 操作。此服务可让 Claude Desktop 和其他 MCP 客户端通过自然语言命令与 WebDAV 文件系统交互。

功能

  • 连接到任意 WebDAV 服务,并可选择是否进行身份验证
  • 对文件和目录执行 CRUD 操作
  • 将文件操作公开为 MCP 资源和工具
  • 通过 stdio 传输(用于与 Claude Desktop 集成)或 HTTP/SSE 传输运行
  • 可选择使用基本身份验证来保护访问
  • 支持使用 bcrypt 加密的密码进行 MCP 服务身份验证(由于协议限制,WebDAV 密码必须为明文)
  • 通过连接池提升与 WebDAV 服务的通信性能
  • 使用 Zod 验证配置
  • 通过结构化日志提升故障排查效率

先决条件

  • Node.js 18 或更高版本
  • npm 或 yarn
  • WebDAV 服务(用于实际文件操作)

安装

选项 1:从 npm 包安装
# Global installation
npm install -g webdav-mcp-server

# Or with npx
npx webdav-mcp-server
选项 2:克隆并从源代码构建
# Clone repository
git clone https://github.com/yourusername/webdav-mcp-server.git
cd webdav-mcp-server

# Install dependencies
npm install

# Build the application
npm run build
选项 3:Docker
# Build the Docker image
docker build -t webdav-mcp-server .

# Run the container without authentication
docker run -p 3000:3000 \
  -e WEBDAV_ROOT_URL=http://your-webdav-server \
  -e WEBDAV_ROOT_PATH=/webdav \
  webdav-mcp-server
  
# Run the container with authentication for both WebDAV and MCP server
docker run -p 3000:3000 \
  -e WEBDAV_ROOT_URL=http://your-webdav-server \
  -e WEBDAV_ROOT_PATH=/webdav \
  -e WEBDAV_AUTH_ENABLED=true \
  -e WEBDAV_USERNAME=admin \
  -e WEBDAV_PASSWORD=password \
  -e AUTH_ENABLED=true \
  -e AUTH_USERNAME=user \
  -e AUTH_PASSWORD=pass \
  webdav-mcp-server

配置

在根目录中创建一个 .env 文件,并添加以下变量:

# WebDAV configuration
WEBDAV_ROOT_URL=http://localhost:4080
WEBDAV_ROOT_PATH=/webdav

# WebDAV authentication (optional)
WEBDAV_AUTH_ENABLED=true
WEBDAV_USERNAME=admin

# WebDAV password must be plain text (required when auth enabled)
# The WebDAV protocol requires sending the actual password to the server
WEBDAV_PASSWORD=password

# Server configuration (for HTTP mode)
SERVER_PORT=3000

# Authentication configuration for MCP server (optional)
AUTH_ENABLED=true
AUTH_USERNAME=user
AUTH_PASSWORD=pass
AUTH_REALM=MCP WebDAV Server

# Auth password for MCP server can be a bcrypt hash (unlike WebDAV passwords)
# AUTH_PASSWORD={bcrypt}$2y$10$CyLKnUwn9fqqKQFEbxpZFuE9mzWR/x8t6TE7.CgAN0oT8I/5jKJBy
用于 MCP 服务身份验证的加密密码

为了增强 MCP 服务的安全性(不涉及 WebDAV 连接),可以使用 bcrypt 加密的密码,而不是以明文形式存储:

  1. 生成 bcrypt 哈希值:

    # Using the built-in utility
    npm run generate-hash -- yourpassword
    
    # Or with npx
    npx webdav-mcp-generate-hash yourpassword
    
  2. 使用 {bcrypt} 前缀将哈希值添加到 .env 文件中:

    AUTH_PASSWORD={bcrypt}$2y$10$CyLKnUwn9fqqKQFEbxpZFuE9mzWR/x8t6TE7.CgAN0oT8I/5jKJBy
    

这样,MCP 服务密码就能得到安全存储。请注意,根据协议要求,WebDAV 密码必须始终为明文。

用法

使用 stdio 传输运行

此模式适合直接与 Claude Desktop 集成。

# If installed globally
webdav-mcp-server

# If using npx
npx webdav-mcp-server

# If built from source
node dist/index.js
使用 HTTP/SSE 传输运行

此模式支持通过 HTTP 访问服务,并使用 Server-Sent Events 进行实时通信。

# If installed globally
webdav-mcp-server --http

# If using npx
npx webdav-mcp-server --http

# If built from source
node dist/index.js --http

使用 Docker Compose 快速开始

要同时启动 WebDAV 服务和 MCP 服务,最简单的方法是使用 Docker Compose:

# Start both WebDAV and MCP servers
cd docker
docker-compose up -d

# This will start:
# - hacdias/webdav server on port 4080 (username: admin, password: admin)
# - MCP server on port 3000 (username: user, password: pass)

此设置使用 hacdias/webdav,这是一个使用 Go 编写的简单、独立的 WebDAV 服务。WebDAV 服务的配置存储在 webdav_config.yml 中,你可以修改该文件来调整权限、添加用户或更改其他设置。

WebDAV 服务会将所有文件存储在名为 webdav_data 的 Docker 卷中,该卷在容器重启后仍会保留数据。

WebDAV 服务配置

webdav_config.yml 文件用于配置 Docker Compose 设置中使用的 hacdias/webdav 服务。以下是可自定义的内容:

# Server address and port
address: 0.0.0.0
port: 6060

# Root data directory
directory: /data

# Enable/disable CORS
cors:
  enabled: true
  # Additional CORS settings...

# Default permissions (C=Create, R=Read, U=Update, D=Delete)
permissions: CRUD

# User definitions
users:
  - username: admin
    password: admin      # Plain text password
    permissions: CRUD    # Full permissions
  
  - username: reader
    password: reader
    permissions: R       # Read-only permissions
    
  # You can also use bcrypt-encrypted passwords
  - username: secure
    password: "{bcrypt}$2y$10$zEP6oofmXFeHaeMfBNLnP.DO8m.H.Mwhd24/TOX2MWLxAExXi4qgi"

如需了解更高级的配置选项,请参阅 hacdias/webdav 文档。

测试

运行测试:

npm test

与 Claude Desktop 集成

  1. 确保已在 Claude Desktop 中启用 MCP 功能
使用 npx 2. 打开 Claude Desktop 设置,然后点击编辑配置(`claude_desktop_config.json`) 3. 添加 ```json { "mcpServers": { "webdav": { "command": "npx", "args": [ "-y", "webdav-mcp-server" ], "env": { "WEBDAV_ROOT_URL": "", "WEBDAV_ROOT_PATH": "", "WEBDAV_USERNAME": "", "WEBDAV_PASSWORD": "", "WEBDAV_AUTH_ENABLED": "true|false" } } } } ```
使用 node 和本地构建 2. 克隆此仓库,并在 mac/linux 上运行 `setup.sh`,或在 windows 上运行 `setup.bat` 3. 打开 Claude Desktop 设置,然后点击编辑配置(`claude_desktop_config.json`) 4. 添加 ```json { "mcpServers": { "webdav": { "command": "node", "args": [ "/dist/index.js" ], "env": { "WEBDAV_ROOT_URL": "", "WEBDAV_ROOT_PATH": "", "WEBDAV_USERNAME": "", "WEBDAV_PASSWORD": "", "WEBDAV_AUTH_ENABLED": "true|false" } } } } ```

可用的 MCP 资源

  • webdav://{path}/list - 列出目录中的文件
  • webdav://{path}/content - 获取文件内容
  • webdav://{path}/info - 获取文件或目录信息

可用的 MCP 工具

  • webdav_create_remote_file - 在远程 WebDAV 服务上创建新文件
  • webdav_get_remote_file - 获取存储在远程 WebDAV 服务上的文件内容
  • webdav_update_remote_file - 更新远程 WebDAV 服务上的现有文件
  • webdav_delete_remote_item - 从远程 WebDAV 服务中删除文件或目录
  • webdav_create_remote_directory - 在远程 WebDAV 服务上创建新目录
  • webdav_move_remote_item - 移动或重命名远程 WebDAV 服务上的文件/目录
  • webdav_copy_remote_item - 将远程 WebDAV 服务上的文件/目录复制到新位置
  • webdav_list_remote_directory - 列出远程 WebDAV 服务上的文件和目录

可用的 MCP 提示词

  • webdav_create_remote_file - 用于在远程 WebDAV 服务上创建新文件的提示词
  • webdav_get_remote_file - 用于获取远程 WebDAV 文件内容的提示词
  • webdav_update_remote_file - 用于更新远程 WebDAV 服务上文件的提示词
  • webdav_delete_remote_item - 用于从远程 WebDAV 服务中删除文件/目录的提示词
  • webdav_list_remote_directory - 用于列出远程 WebDAV 服务上目录内容的提示词
  • webdav_create_remote_directory - 用于创建远程 WebDAV 服务上目录的提示词
  • webdav_move_remote_item - 用于移动/重命名远程 WebDAV 服务上文件/目录的提示词
  • webdav_copy_remote_item - 用于复制远程 WebDAV 服务上文件/目录的提示词

在 Claude 中的查询示例

连接 WebDAV MCP 服务后,你可以在 Claude Desktop 中使用以下查询示例:

  • “列出我的远程 WebDAV 服务上的文件”
  • “在我的远程 WebDAV 服务上创建一个名为 notes.txt 的新文本文件,内容如下:Hello World”
  • “获取我的远程 WebDAV 服务上 document.txt 的内容”
  • “使用此新配置更新我的远程 WebDAV 服务上的 config.json”
  • “在我的远程 WebDAV 服务上创建一个名为 projects 的目录”
  • “将 report.docx 复制到我的远程 WebDAV 服务上的备份位置”
  • “将我的远程 WebDAV 服务上的文件 old_name.txt 移动并重命名为 new_name.txt”
  • “从我的远程 WebDAV 服务中删除 temp.txt”

编程使用

你也可以在自己的项目中以编程方式使用此软件包:

import { startWebDAVServer } from 'webdav-mcp-server';

// For stdio transport without authentication
await startWebDAVServer({
  webdavConfig: {
    rootUrl: 'http://your-webdav-server',
    rootPath: '/webdav',
    authEnabled: false
  },
  useHttp: false
});

// For stdio transport with WebDAV authentication (password must be plain text)
await startWebDAVServer({
  webdavConfig: {
    rootUrl: 'http://your-webdav-server',
    rootPath: '/webdav',
    authEnabled: true,
    username: 'admin',
    password: 'password'
  },
  useHttp: false
});

// With bcrypt hash for MCP server password (HTTP auth only)
await startWebDAVServer({
  webdavConfig: {
    rootUrl: 'http://your-webdav-server',
    rootPath: '/webdav',
    authEnabled: true,
    username: 'admin',
    password: 'password' // WebDAV password must be plain text
  },
  useHttp: true,
  httpConfig: {
    port: 3000,
    auth: {
      enabled: true,
      username: 'user',
      password: '{bcrypt}$2y$10$CyLKnUwn9fqqKQFEbxpZFuE9mzWR/x8t6TE7.CgAN0oT8I/5jKJBy'
    }
  }
});

// For HTTP transport with MCP authentication
await startWebDAVServer({
  webdavConfig: {
    rootUrl: 'http://your-webdav-server',
    rootPath: '/webdav',
    authEnabled: true,
    username: 'admin',
    password: 'password'
  },
  useHttp: true,
  httpConfig: {
    port: 3000,
    auth: {
      enabled: true,
      username: 'user',
      password: 'pass',
      realm: 'MCP WebDAV Server'
    }
  }
});

// For HTTP transport without authentication
await startWebDAVServer({
  webdavConfig: {
    rootUrl: 'http://your-webdav-server',
    rootPath: '/webdav',
    authEnabled: false
  },
  useHttp: true,
  httpConfig: {
    port: 3000,
    auth: {
      enabled: false
    }
  }
});

许可证

MIT

评论

支持 Markdown

第一次接触 MCP?

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

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