bws-secret-delivery-mcp

bws-secret-delivery-mcp

Enables secure delivery of Bitwarden Secrets Manager secrets to approved local files without exposing secret values to the MCP client or model. It provides metadata-only secret discovery and atomic file writes for single secrets or raw env files.

Category
访问服务器

README

bws-secret-delivery-mcp

A deliberately narrow Model Context Protocol server for Bitwarden Secrets Manager. It uses Bitwarden's official bws CLI to resolve secrets and deliver them directly to approved local files without returning secret values to the MCP client or model.

This community project is not affiliated with or endorsed by Bitwarden, Inc.

Why this exists

General-purpose Bitwarden/BWS MCP servers are useful when an agent genuinely needs to see or manage secrets. Infrastructure automation often needs a different boundary: the agent should be able to select a credential profile and say which secret goes to which approved consumer file without receiving the secret itself.

bws-secret-delivery-mcp intentionally does less:

  • metadata-only project and secret discovery;
  • one or more named Machine Account credential profiles;
  • optional expected-project scope checks per profile;
  • direct secret-to-file delivery;
  • complete raw env-file generation from selected secrets;
  • per-profile output-directory allowlists;
  • no plaintext secret retrieval;
  • no arbitrary command execution;
  • no creation, editing or deletion of Bitwarden secrets or projects.

Tool surface

Tool Behavior
bws_status Verify configuration and authenticated BSM access for one or all profiles.
bws_project_list List project metadata for one or all profiles.
bws_secret_list List secret metadata; values and notes are omitted.
bws_secret_write_file Atomically write one secret value to an approved file.
bws_secret_write_raw_env_file Atomically write a complete raw KEY=value env file from selected secrets.

There is intentionally no get_secret, run, create, edit, or delete tool.

Every tool accepts an optional profile. Read tools query every configured profile when it is omitted. Write tools require an explicit profile whenever more than one profile is configured.

Requirements

  • Python 3.12+
  • Bitwarden Secrets Manager CLI (bws)
  • Dedicated Bitwarden Machine Account access tokens with only the required project access
  • An MCP client that supports stdio servers

Install bws using Bitwarden's official installation instructions.

Configuration

Named profiles

For central administrative control planes, set BWS_PROFILES_FILE to an absolute path containing non-secret JSON configuration. Machine Account tokens remain in separate private files.

{
  "profiles": {
    "app-a": {
      "access_token_file": "/run/secrets/app-a-bws-token",
      "server_url": "https://vault.bitwarden.eu",
      "expected_project_names": ["App A Runtime"],
      "allowed_output_directories": ["/srv/app-a/.secrets"]
    },
    "metadata-only": {
      "access_token_file": "/run/secrets/metadata-bws-token",
      "server_url": "https://vault.bitwarden.eu",
      "expected_project_names": ["Metadata Runtime"]
    }
  }
}

Profile fields:

Field Required Meaning
access_token_file yes Absolute private file containing one Machine Account token. No group/other permissions are allowed.
server_url no Explicit Bitwarden server URL for EU or self-hosted deployments.
expected_project_names no Exact accessible project-name set expected for this credential. Secret operations fail closed on a mismatch.
allowed_output_directories no Existing local directories that this profile may write below. Omit for metadata-only/read-only delivery behavior.
default_file_mode no Octal mode for newly created files, otherwise the global default.

Global environment variables:

Variable Required Default Meaning
BWS_PROFILES_FILE for multi-profile mode - Absolute non-symlink JSON profile configuration file.
BWS_BIN no bws Path or command name for the official bws executable.
BWS_TIMEOUT_SECONDS no 30 CLI timeout, maximum 120 seconds.
BWS_DEFAULT_FILE_MODE no 0600 Mode for new output files. Execute/world permissions are rejected. Existing file mode and ownership are preserved.

Example MCP registration:

{
  "mcpServers": {
    "bws-secret-delivery": {
      "command": "uv",
      "args": [
        "run",
        "--frozen",
        "--directory",
        "/opt/bws-secret-delivery-mcp",
        "bws-secret-delivery-mcp"
      ],
      "env": {
        "BWS_PROFILES_FILE": "/etc/bws-secret-delivery/profiles.json",
        "BWS_BIN": "/usr/local/bin/bws"
      }
    }
  }
}

Keep output roots narrow. A dedicated consumer secret directory is safer than allowing an entire application or stack tree.

Legacy single-profile mode

Version 0.2 retains the original environment-only configuration for simple deployments:

Variable Required Default Meaning
BWS_ACCESS_TOKEN_FILE yes - Private Machine Account token file.
BWS_ALLOWED_OUTPUT_DIRS yes - os.pathsep-separated existing output roots.
BWS_SERVER_URL no Bitwarden default Server URL for the single profile.

Do not set BWS_ACCESS_TOKEN_FILE together with BWS_PROFILES_FILE.

Project-scope guard

If expected_project_names is configured, secret discovery and delivery first verify that the Machine Account can see exactly that project-name set. This makes accidental future privilege expansion fail closed instead of silently broadening the MCP's authority.

bws_project_list remains available to inspect accessible project metadata when diagnosing a scope mismatch.

Raw env files

bws_secret_write_raw_env_file writes one complete file in deterministic key order. Values are emitted exactly after KEY=. Values containing NUL, LF or CR are rejected because the format is intentionally line-oriented.

For Docker Compose 2.30+ use the file with format: raw so Compose does not interpret $, quotes or other characters in secret values:

env_file:
  - path: ./.secrets/runtime.env
    format: raw

Example tool input in multi-profile mode:

{
  "profile": "app-a",
  "target_path": "/srv/app-a/.secrets/runtime.env",
  "secrets": {
    "DATABASE_PASSWORD": "database-password",
    "API_TOKEN": "2e71f52b-0000-0000-0000-000000000000"
  }
}

Each mapping value is either an exact Bitwarden secret key or a secret UUID. If a key is ambiguous within a profile, supply project_id or use a UUID.

File-safety behavior

  • Token files and the profiles file must be regular non-symlink files.
  • Token files must grant no group or other permissions.
  • target_path must be absolute.
  • Its resolved parent must remain inside the selected profile's configured output roots.
  • Existing symlinks and non-regular target files are rejected.
  • Existing targets with permissions for other are rejected.
  • Writes use a temporary file in the same directory, fsync, atomic os.replace(), then a parent-directory fsync.
  • Existing mode and ownership are preserved when possible.
  • MCP responses contain profile, target and secret metadata, never secret values or value lengths.
  • Provider stdout from secret operations and provider stderr from failures are never echoed into MCP errors.

Development

python -m venv .venv
. .venv/bin/activate
pip install -e '.[test]'
pytest

Scope

This server is for interactive/operator-driven secret delivery and bounded central administration. It is not intended to replace declarative secret renderers, deployment orchestration, Kubernetes secret operators, or a full Bitwarden administration client.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选