Vault秘密管理服务器

一个容器化的模型上下文协议(MCP)服务器,用于与HashiCorp Vault交互,提供读取、写入、列出和删除Vault中的秘密的工具。

  • by kelleyblackmore
  • PowerShell
  • 本地部署
  • 更新于
在 GitHub 查看 kelleyblackmore/vault-mcp

使用说明

保险库mcp

用于与HashiCorp Vault交互的容器化模型上下文协议(MCP)服务器。此服务器提供MCP工具,用于读取、写入、列出和删除Vault中的机密。

特性

  • vault_read:在指定路径上从Vault读取机密
  • vault_write:将机密写入指定路径的Vault
  • vault_list:列出Vault中指定路径的机密
  • vault_delete:从指定路径的Vault中删除机密

先决条件

  • Docker和Docker Compose
  • 启用MCP工具包的Docker Desktop 4.42.0+(用于Docker桌面集成)
  • HashiCorp Vault实例(可以使用附带的开发服务器)
  • 用于身份验证的保险库令牌

快速开始

选项1:Docker桌面MCP工具包(推荐)

运行安装脚本以安装和配置服务器:

Windows(PowerShell):

.\setup.ps1

macOS/Linux(Bash):

./setup.sh

安装脚本的作用:

  • 根据需要构建Docker镜像
  • 启动Vault开发服务器
  • 在Docker桌面中创建MCP目录
  • 添加并启用vault mcp服务器

使用的配置:

  • 目录文件: configs/vault-catalog.yaml
  • 保险库地址: http://host.docker.internal:8200
  • 保险库令牌: myroot (开发模式)

运行安装脚本后,重新启动Docker Desktop,在“我的服务器”部分看到服务器。

看 docs/INSTALL_DOCKER_DESKTOP.md 了解详细的安装说明。

选项2:Docker编写

启动Vault和MCP服务器:

# Build and start services
docker-compose up -d

# Check logs
docker-compose logs -f vault-mcp

这将开始:

  • Vault开发服务器位于 http://localhost:8200 带有根令牌 myroot
  • 连接到vault实例的vault mcp服务器

MCP客户端设置

光标IDE

步骤1:复制配置

复制 configs/mcp_config.json 到您的Cursor MCP配置文件:

窗户:

# Create directory if it doesn't exist
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.cursor"

# Copy the config file
Copy-Item -Path "configs\mcp_config.json" -Destination "$env:USERPROFILE\.cursor\mcp.json"

macOS/Linux:

# Create directory if it doesn't exist
mkdir -p ~/.cursor

# Copy the config file
cp configs/mcp_config.json ~/.cursor/mcp.json

步骤2:更新配置 (如果需要)

编辑 ~/.cursor/mcp.json (或 %USERPROFILE%\.cursor\mcp.json 在Windows上)并更新:

  • VAULT_ADDR:您的Vault服务器地址
  • VAULT_TOKEN:您的保险库令牌
  • 图片名称:使用 vault-mcp-vault-mcp:latest 如果在当地建造

步骤3:重新启动游标

完全退出并重新启动Cursor以使更改生效。

第四步:测试

在Cursor中,尝试询问:

Use vault_read to read the secret at path secret/data/test

看 docs/TEST_CURSOR_MCP.md 了解更多测试说明。

克劳德桌面

从以下位置复制配置 configs/mcp_config.json 到您的Claude Desktop配置:

窗户:

# Location: %APPDATA%\Claude\claude_desktop_config.json
Copy-Item -Path "configs\mcp_config.json" -Destination "$env:APPDATA\Claude\claude_desktop_config.json"

macOS:

# Location: ~/Library/Application Support/Claude/claude_desktop_config.json
cp configs/mcp_config.json ~/Library/Application\ Support/Claude/claude_desktop_config.json

Linux:

# Location: ~/.config/claude-desktop/claude_desktop_config.json
cp configs/mcp_config.json ~/.config/claude-desktop/claude_desktop_config.json

然后重新启动Claude Desktop。

构建Docker镜像

使用GitHub容器注册表中的预构建映像

预构建的容器映像会自动发布到GitHub容器注册表:

# Pull the latest image
docker pull ghcr.io/kelleyblackmore/vault-mcp:latest

# Pull a specific version
docker pull ghcr.io/kelleyblackmore/vault-mcp:v1.0.0

这些图像是为多个平台自动构建的:

  • linux/amd64 (x86_64)
  • linux/arm64 (ARM64/aarch64)

在当地建设

docker-compose build vault-mcp
# Or
docker build -t vault-mcp-vault-mcp:latest .

运行容器

使用Docker运行

docker run -it --rm \
  -e VAULT_ADDR=http://host.docker.internal:8200 \
  -e VAULT_TOKEN=myroot \
  vault-mcp-vault-mcp:latest

使用Docker Compose

编辑 docker-compose.yml 配置Vault连接的文件:

environment:
  VAULT_ADDR: http://vault:8200
  VAULT_TOKEN: your-token

然后运行:

docker-compose up vault-mcp

配置

服务器是通过环境变量配置的:

  • VAULT_ADDR:Vault服务器地址(默认值: http://127.0.0.1:8200)
  • VAULT_TOKEN:Vault身份验证令牌(必需)

配置文件位于 configs/ 目录:

  • configs/vault-catalog.yaml -Docker桌面MCP工具包目录配置
  • configs/mcp_config.json -MCP客户端配置(光标、克劳德桌面)

可用工具

vault_read

从Vault中读取一个秘密。

参数:

  • path (string,必填):从中读取秘密的路径(例如。, secret/data/myapp)

例子:

{
  "path": "secret/data/myapp"
}

vault_write

给Vault写个秘密。

参数:

  • path (string,必填):将秘密写入的路径(例如。, secret/data/myapp)
  • data (object,必填):作为JSON对象写入的秘密数据

例子:

{
  "path": "secret/data/myapp",
  "data": {
    "username": "admin",
    "password": "secret123"
  }
}

vault_list

在Vault中的路径上列出秘密。

参数:

  • path (string,必填):列出机密的路径(例如。, secret/metadata)

例子:

{
  "path": "secret/metadata"
}

vault_delete

从Vault中删除秘密。

参数:

  • path (string,必填):从中删除秘密的路径(例如。, secret/data/myapp)

例子:

{
  "path": "secret/data/myapp"
}

发展

地方发展设置

# Install dependencies
npm install

# Build the project
npm run build

# Run locally (requires Vault server)
VAULT_ADDR=http://localhost:8200 VAULT_TOKEN=myroot npm start

项目结构

vault-mcp/
├── .github/
│   └── workflows/
│       └── docker-build-publish.yml  # CI/CD workflow for container builds
├── configs/              # MCP configuration files
│   ├── mcp_config.json   # MCP client configuration (Cursor, Claude Desktop)
│   └── vault-catalog.yaml # Docker Desktop MCP Toolkit catalog
├── docs/                 # Documentation files
├── src/
│   └── index.ts          # Main MCP server implementation
├── dist/                 # Compiled JavaScript (generated)
├── Dockerfile           # Container definition
├── docker-compose.yml   # Docker Compose configuration
├── package.json         # Node.js dependencies
├── setup.ps1            # Setup script for Windows (PowerShell)
├── setup.sh             # Setup script for macOS/Linux (Bash)
├── tsconfig.json        # TypeScript configuration
└── README.md           # This file

CI/CD

该项目使用GitHub Actions自动构建和发布Docker镜像:

  • 在推到main:构建并发布 latest 标签和基于SHA的标签
  • 根据pull请求:生成映像以验证其是否编译(不发布)
  • 在版本标签上 (例如。, v1.0.0):构建并发布特定于版本的标签(例如。, v1.0.0, v1.0, v1)

图片发布到GitHub容器注册表 ghcr.io/kelleyblackmore/vault-mcp.

安全考虑

  • 切勿在配置文件中硬编码Vault令牌
  • 使用适当的Vault策略限制MCP服务器权限
  • 对于生产使用,请用正确配置的生产实例替换dev-Vault服务器
  • 考虑使用Vault AppRole或Kubernetes身份验证,而不是基于令牌的身份验证
  • 使用秘密管理工具注入 VAULT_TOKEN 在运行时

许可证

麻省理工学院