Vault MCP Bridge

Vault MCP Bridge

Enables secure management of agent-scoped secrets in HashiCorp Vault through MCP protocol. Provides per-agent namespacing, multiple authentication methods (API key, JWT, mTLS), and optional encryption/decryption capabilities with built-in rate limiting.

Category
访问服务器

README

Vault MCP Bridge

Overview

  • FastAPI-based MCP server that manages agent-scoped secrets in HashiCorp Vault.
  • Authentication options: API Key, JWT (HS256), and mTLS via reverse-proxy headers.
  • Per-agent namespacing under KV v2; optional Transit encrypt/decrypt.
  • Optional per-request child token issuance bound to per-agent policies.
  • Simple in-memory rate limiting per agent.

Run

  • Install deps:
    • python3 -m venv .venv && source .venv/bin/activate
    • python -m pip install -r requirements.txt
  • Easiest (no uvicorn target syntax): python main.py
    • Optional env: HOST=0.0.0.0 PORT=8089 RELOAD=true LOG_LEVEL=debug python main.py
  • Or with uvicorn explicitly:
    • python -m uvicorn main:app --reload
    • python -m uvicorn vault_mcp.app:create_app --factory --reload

Configuration (env)

  • Vault:
    • VAULT_ADDR (default: http://localhost:8200)
    • VAULT_NAMESPACE (Enterprise only)
    • VAULT_TOKEN or VAULT_ROLE_ID + VAULT_SECRET_ID
    • KV_MOUNT (default: secret)
    • DEFAULT_PREFIX (default: mcp)
  • Auth enable flags:
    • AUTH_API_KEY_ENABLED (default: true)
    • AUTH_JWT_ENABLED (default: true)
    • AUTH_MTLS_ENABLED (default: false)
  • API Keys:
    • API_KEYS_JSON JSON map: { "<api-key>": "<agent-id>" }
  • JWT (HS256 by default):
    • JWT_HS256_SECRET, JWT_ISSUER, JWT_AUDIENCE
  • mTLS via proxy headers:
    • MTLS_IDENTITY_HEADER (default: x-ssl-client-s-dn)
    • MTLS_VERIFY_HEADER (default: x-ssl-client-verify)
    • MTLS_SUBJECT_CN_PREFIX (default: CN=)
  • Child token issuance:
    • CHILD_TOKEN_ENABLED (default: false)
    • CHILD_TOKEN_TTL (default: 90s)
    • CHILD_TOKEN_POLICY_PREFIX (default: mcp-agent-)
  • Rate limiting:
    • RATE_LIMIT_ENABLED (default: true)
    • RATE_LIMIT_REQUESTS (default: 60)
    • RATE_LIMIT_WINDOW_SECONDS (default: 60)

Auth Modes

  • API Key: send X-API-Key: <key>. Map keys to agents via API_KEYS_JSON.
  • JWT: send Authorization: Bearer <token> with claims sub and optional scopes.
  • mTLS: terminate TLS at proxy and pass DN with X-SSL-Client-S-DN; CN is extracted as subject.

Agent Path Namespace

  • Secrets are stored under: {KV_MOUNT}/data/{DEFAULT_PREFIX}/{subject}/... (KV v2)
  • The server enforces a safe relative path under the agent prefix.

Child Token Issuance

  • When CHILD_TOKEN_ENABLED=true, the server mints a child token per request bound to a per-agent policy named {CHILD_TOKEN_POLICY_PREFIX}{subject} with TTL CHILD_TOKEN_TTL and uses it for Vault operations.
  • Ensure the policy exists in Vault (see Policy section) and the parent token has capability to create child tokens.

Policy

  • Generate HCL for an agent:
    • python scripts/gen_policy.py --agent alice --mount secret --prefix mcp > alice.hcl
    • Suggested policy name: mcp-agent-alice
  • Example HCL (what the script prints):
    • Grants create/read/update/delete/list on data/{prefix}/{agent}/*
    • Grants read/list on metadata/{prefix}/{agent}/*
    • Grants update on delete/, undelete/, destroy/ endpoints for versioned ops
  • Apply the policy (manual steps using Vault CLI):
    • vault policy write mcp-agent-alice alice.hcl

Endpoints

  • KV v2:
    • PUT /secrets/{path} — write (scope: write)
    • GET /secrets/{path} — read (scope: read) [optional version]
    • DELETE /secrets/{path} — delete latest version (scope: delete)
    • GET /secrets?prefix=... — list keys under prefix (scope: list)
    • POST /secrets/{path}:undelete — body { "versions": [1,2] } (scope: write)
    • POST /secrets/{path}:destroy — body { "versions": [1,2] } (scope: write)
  • Transit:
    • POST /transit/encrypt{ "key": "k", "plaintext": "<b64>" } (scope: write)
    • POST /transit/decrypt{ "key": "k", "ciphertext": "..." } (scope: read)
  • Health/Debug:
    • GET /healthz, GET /whoami, GET /echo-headers
  • MCP:
    • Mounted at /mcp via fastapi_mcp if available

Security Notes

  • Enable TLS end-to-end; for mTLS, terminate at a trusted proxy and pass identity headers.
  • Do not log secret values; add structured logs with redaction if you extend logging.
  • Prefer JWT or mTLS in production; use API keys for dev only.
  • Consider enabling Vault audit devices and minimal TTLs for tokens.

Troubleshooting

  • Import errors (e.g., No module named fastapi): ensure you run uvicorn with the same Python that installed deps:
    • python -m uvicorn main:app --reload (uses current venv interpreter)
  • Can’t import main: use the full target format <module>:<attribute> — e.g., main:app.
  • Bind to a different port/host if needed: python -m uvicorn main:app --reload --port 8090 --host 0.0.0.0.
  • Increase logs: add --log-level debug --access-log.

Dev helpers

  • Start server with sensible dev env: bash scripts/run_dev.sh
  • Smoke test (requires server + local Vault dev): bash scripts/smoke.sh
  • Auth tests (by agent):
    • API key (agent_api): bash scripts/test_agent_api.sh
    • JWT (agent_jwt via HS256): bash scripts/test_agent_jwt.sh (or generate token with scripts/gen_jwt.py)
    • JWT (agent_jwt via RS256/JWKS): bash scripts/test_agent_jwt_rs256.sh (serves JWKS locally on :9001)
    • mTLS headers (agent_mtls): bash scripts/test_agent_mtls.sh

Always enable all auth

  • Start server with all auth methods enabled, regardless of existing env:
    • bash scripts/run_all_auth.sh

Three-agent scenario (no restarts)

  • Provision Vault with policies for agent_api, agent_jwt, agent_mtls:
    • cd local-vault && AGENTS=agent_api,agent_jwt,agent_mtls docker compose up -d && cd ..
  • Start server with all auth enabled: bash scripts/run_all_auth.sh
  • Test each agent independently (in another terminal):
    • API key (agent_api): bash scripts/test_agent_api.sh
    • JWT (agent_jwt): bash scripts/test_agent_jwt.sh
    • mTLS headers (agent_mtls): bash scripts/test_agent_mtls.sh

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选