Skip to main content

MCP server for HashiCorp Vault secret management via claude-vault

Project description

MCP-Vault

Model Context Protocol (MCP) server for HashiCorp Vault secret management via claude-vault.

This MCP server exposes Vault operations as tools that Claude Code can use for AI-assisted secret management, while maintaining the existing security model with human confirmation for write operations.

Features

  • โœ… 7 MCP Tools: Complete Vault operations (login, status, logout, list, get, set, inject)
  • ๐Ÿ” Security-First: Human confirmation required for write operations
  • ๐Ÿ“ Audit Logging: All operations logged to .claude-vault-audit.log
  • โฑ๏ธ Session-Based: 60-minute token expiry, no persistent credentials
  • ๐Ÿ›ก๏ธ Input Validation: Prevents injection attacks and path traversal
  • ๐Ÿ” Pattern Detection: Scans for dangerous patterns in secret values

Architecture

User authenticates โ†’ VAULT_TOKEN exported โ†’ MCP server reads env โ†’ Claude uses tools

Security Model:

  1. Human authenticates via OIDC + MFA (source claude-vault login)
  2. Token stored in environment variables (memory only, 60 min TTL)
  3. MCP server reads token from environment
  4. Write operations require human to type "yes"
  5. All operations audited

Quick Start

1. Installation

cd /path/to/claude-vault/packages/mcp-server

# Install in development mode
pip install -e .

# Or install from PyPI (when published)
pip install claude-vault-mcp

2. Configure MCP Server (One-time)

Option 1: Use .mcp.json (Project Scope - Recommended)

Copy the example configuration:

# Copy example to your project root
cp .mcp.json.example /your/project/.mcp.json

# Edit to set your Vault address
vim /your/project/.mcp.json

Edit .mcp.json to point to your claude-vault installation:

{
  "mcpServers": {
    "claude-vault": {
      "type": "stdio",
      "command": "uvx",
      "args": [
        "--from",
        "/path/to/claude-vault/packages/mcp-server",
        "claude-vault-mcp"
      ],
      "env": {
        "VAULT_ADDR": "https://vault.example.com"
      }
    }
  }
}

Option 2: Add via Claude CLI

# Add MCP server with project scope
claude mcp add --transport stdio claude-vault --scope project \
  --env VAULT_ADDR=https://vault.example.com \
  -- uvx --from /path/to/claude-vault/packages/mcp-server claude-vault-mcp

Verify Configuration:

# Check MCP server status
claude mcp get claude-vault

# Should show: Status: โœ“ Connected

3. Authenticate to Vault (Daily)

# Authenticate (opens browser for OIDC + MFA)
source claude-vault login

# Verify session (shows token expiry time)
claude-vault status

Session Management:

  • Sessions are valid for 60 minutes
  • VAULT_TOKEN is stored in environment variables (memory only)
  • Claude Code inherits the token from your current shell
  • If session expires: Re-authenticate with source claude-vault login

4. Use Vault Tools in Claude Code

The MCP server exposes 7 tools that Claude can use automatically:

# Ask Claude to interact with Vault:
Claude, list all services in Vault
Claude, get the wifi_ssid secret for esphome
Claude, register DB credentials for myapp: DB_USER="admin" DB_PASS="secret"
Claude, inject esphome secrets to .env file

Available via /mcp command:

  • Type /mcp in Claude Code to see all available MCP servers and tools
  • Tools appear automatically in Claude's context when relevant

Available Tools

Authentication

vault_login - Guide user through OIDC authentication

  • Provides instructions for source claude-vault login
  • Cannot directly update environment (requires MCP restart)

vault_status - Check session validity

  • Shows user, policies, time remaining
  • Validates token with Vault

vault_logout - Revoke token

  • Invalidates session in Vault
  • Provides cleanup instructions

Read Operations

vault_list - List services or secrets

  • No arguments: Lists all services
  • With service: Lists secret keys (names only)

vault_get - Retrieve secret values

  • Required: service
  • Optional: key (specific secret)
  • โš ๏ธ Returns actual secret values

Write Operations

vault_set - Create or update secrets

  • Required: service, secrets (dict)
  • Optional: dry_run (boolean)
  • Requires human confirmation (must type "yes")
  • Validates inputs, detects dangerous patterns
  • Logs to audit file

Injection

vault_inject - Generate .env or secrets.yaml

  • Required: service
  • Optional: format (auto/env/yaml)
  • Backs up existing files
  • Calls existing inject-secrets.sh script

Security Features

Input Validation

  • Service names: ^[a-zA-Z0-9_-]{1,64}$
  • Key names: ^[a-zA-Z0-9_-]{1,128}$
  • Value size: Max 8KB
  • No path traversal: Rejects .., /

Dangerous Pattern Detection

Scans secret values for:

  • Command substitution: $(...), backticks
  • Shell operators: &&, ||, ;
  • Variable expansion: ${...}
  • Control characters: newlines, carriage returns

Confirmation Checkpoint

For vault_set, displays:

โš ๏ธ  SECURITY CHECKPOINT - MANUAL VALIDATION REQUIRED

You are about to write secrets to Vault:
  Service: myapp
  Action: CREATE
  Path: secret/proxmox-services/myapp

Secrets to be written:
  + DB_PASSWORD
  + API_KEY

Type 'yes' to proceed, or anything else to abort:

Claude MUST wait for human response - cannot automatically confirm.

Audit Logging

Format: [timestamp] USER=mcp-server ACTION=X SERVICE=Y DETAILS=Z

Logged actions:

  • CONFIRMATION_REQUIRED - Waiting for user
  • CONFIRMED - User typed "yes"
  • ABORTED - User declined
  • SUCCESS - Write succeeded
  • FAILED - Write failed
  • VALIDATION_FAILED - Input rejected

Daily Workflow

Morning Setup

# Authenticate (opens browser for OIDC + MFA)
source claude-vault login

# Verify session
claude-vault status

# Start working with Claude Code (MCP server auto-connects)

During Work

  • Session valid for 60 minutes
  • Claude Code automatically uses vault tools when relevant
  • Write operations pause for confirmation (you must type "yes")
  • Check available tools: Type /mcp in Claude Code
  • If session expires: Re-authenticate with source claude-vault login

End of Day

# Optional: Explicitly logout
source claude-vault logout

# Or: Session auto-expires after 60 minutes

Example Usage

List all services

Claude: "List all services in Vault"
โ†’ vault_list (no arguments)
โ†’ Shows: esphome, authentik, bitwarden, ...

Get secrets for a service

Claude: "Get the wifi_ssid secret for esphome"
โ†’ vault_get(service="esphome", key="wifi_ssid")
โ†’ Returns: "MyHomeWiFi"

Register new secrets

Claude: "Register DB credentials for myapp"
โ†’ vault_set(service="myapp", secrets={"DB_USER": "admin", "DB_PASS": "secret"})
โ†’ Displays confirmation prompt
โ†’ User types "yes"
โ†’ Writes to Vault

Inject to .env

Claude: "Inject esphome secrets to .env file"
โ†’ vault_inject(service="esphome", format="env")
โ†’ Creates esphome/.env with all secrets

Troubleshooting

"No Vault session found"

Cause: VAULT_TOKEN not in environment

Solution:

source claude-vault login
# Restart MCP server

"Session expired"

Cause: 60-minute TTL exceeded

Solution:

source claude-vault login
# MCP server will automatically reconnect with new token

"Permission denied" (HTTP 403)

Cause: Token lacks required policies

Solution:

  • Verify policies in Vault UI
  • Ensure token has homelab-services policy
  • Re-authenticate if needed

Tools not appearing in Claude Code

Cause: MCP server not started or misconfigured

Solution:

  1. Verify MCP server is configured: claude mcp get claude-vault
  2. Check connection status (should show "โœ“ Connected")
  3. Type /mcp in Claude Code to see all available tools
  4. If not working, try: claude mcp remove claude-vault -s project then re-add
  5. Check you're in the /workspace/proxmox-services directory (where .mcp.json exists)

Development

Project Structure

claude-vault-mcp/
โ”œโ”€โ”€ pyproject.toml          # Package config
โ”œโ”€โ”€ README.md               # This file
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ claude_vault_mcp/
โ”‚       โ”œโ”€โ”€ __init__.py     # Entry point with main()
โ”‚       โ”œโ”€โ”€ server.py       # MCP server setup
โ”‚       โ”œโ”€โ”€ session.py      # Env-based auth
โ”‚       โ”œโ”€โ”€ vault_client.py # HTTP API client
โ”‚       โ”œโ”€โ”€ security.py     # Validation & audit
โ”‚       โ””โ”€โ”€ tools/
โ”‚           โ”œโ”€โ”€ read.py     # status, list, get
โ”‚           โ”œโ”€โ”€ write.py    # set (with confirmation)
โ”‚           โ”œโ”€โ”€ auth.py     # login, logout
โ”‚           โ””โ”€โ”€ inject.py   # inject

Testing

# Install with dev dependencies
pip install -e ".[dev]"

# Run MCP Inspector for debugging
npx @modelcontextprotocol/inspector claude-vault-mcp

# Manual test
claude-vault-mcp
# (Starts stdio server, send JSON-RPC requests)

Adding a New Tool

  1. Create tool handler in appropriate file (read/write/auth/inject)
  2. Inherit from ToolHandler base class
  3. Implement get_tool_description() and run_tool()
  4. Register in server.py TOOL_HANDLERS dict

Security Considerations

DO:

  • โœ… Always require human confirmation for writes
  • โœ… Validate all inputs
  • โœ… Log all operations
  • โœ… Use environment variables for tokens (memory only)
  • โœ… Set short TTL (60 minutes)

DON'T:

  • โŒ Store tokens in files
  • โŒ Skip confirmation prompts
  • โŒ Allow Claude to auto-confirm writes
  • โŒ Disable input validation
  • โŒ Ignore dangerous patterns

License

MIT

Contributing

  1. Fork the repository
  2. Create feature branch
  3. Add tests
  4. Submit pull request

Support

For issues or questions:

  • Check troubleshooting section
  • Review audit logs: .claude-vault-audit.log
  • Verify Vault session: claude-vault status
  • Check Claude logs for MCP errors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claude_vault_mcp-1.4.0.tar.gz (111.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claude_vault_mcp-1.4.0-py3-none-any.whl (60.4 kB view details)

Uploaded Python 3

File details

Details for the file claude_vault_mcp-1.4.0.tar.gz.

File metadata

  • Download URL: claude_vault_mcp-1.4.0.tar.gz
  • Upload date:
  • Size: 111.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for claude_vault_mcp-1.4.0.tar.gz
Algorithm Hash digest
SHA256 8d02772cd411a8a5eef4bb11262a4340fcfe55198c4cdd7d26deeb44d62a5d28
MD5 a0890f16ff5df3bbfed657b878975f47
BLAKE2b-256 19aec00c12f1a91b5f99d298f5918de8dc2c8476b19d4745e0a27ab976725f15

See more details on using hashes here.

File details

Details for the file claude_vault_mcp-1.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for claude_vault_mcp-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ed526224ea54e70bb216ee71d126b02241c15fae4016657f39651cf5ef8cee2
MD5 7f62863f4728d58d566d1d76b3037d5d
BLAKE2b-256 f8a23736ed718303fd87e5da8114585645013557083c8583062fb8477e379f5f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page