Skip to main content
Glama
borysttk

auth-vault

by borysttk
README.md
# @mcp/auth-vault

> **🧩 Branch template** β€” czysta wersja do klonowania i adaptacji.  
> Brak testΓ³w specyficznych dla Q-ekosystemu, brak danych wraΕΌliwych.  
> WΕ‚asne serwisy konfigurujesz przez `add_service` β€” wystarczΔ… selektory CSS.

**MCP server** for secure credential management, browser-based login automation, SSH key vault, TOTP/2FA auto-solving, and audit logging.

```
Status:  active    |    License: MIT    |    Version: 0.2.0
```

---

## Overview

Auth Vault stores encrypted credentials, secrets, and SSH keys (AES-256-GCM), automates browser login flows via Playwright, auto-solves TOTP-based 2FA challenges, and tracks sensitive actions via an audit log. It provides both an **MCP interface** (for AI clients) and a **Web UI dashboard** (for manual management).

| Interface | Port | URL |
|-----------|------|-----|
| Web UI Dashboard | `5600` | `http://<tailscale-ip>:5600/` |
| MCP SSE | `5501` | `http://<tailscale-ip>:5501/sse` |
| MCP Health | `5501` | `http://<tailscale-ip>:5501/health` |

---

## Features

- **Encrypted vault** β€” credentials, secrets, and SSH keys stored with AES-256-GCM
- **SSH Key Vault** β€” generate, store, retrieve, and export SSH keys (Ed25519, RSA-2048/4096)
- **SSH Config generation** β€” export SSH config fragments and key files
- **Browser automation** β€” Playwright-based login with form filling
- **CAPTCHA detection** β€” automatic detection of CAPTCHA challenges during login
- **Trusted devices** β€” device fingerprinting with trusted device management
- **TOTP/2FA auto-solve** β€” RFC 6238 implementation, generates and submits 2FA codes
- **TOTP rotation detection** β€” suggests code refresh when window is near expiry
- **QR code support** β€” generate QR for Google Authenticator setup
- **Secrets management** β€” API keys, bearer tokens, access/refresh tokens
- **Password generator** β€” strong random passwords and diceware passphrases (OpenSSL-backed)
- **Audit logging** β€” JSONL audit log with auto-rotation for sensitive actions
- **Vault health monitoring** β€” integrity checks (credentials, secrets, ssh indexes)
- **Discovery API** β€” metadata overview of all vault contents without decryption
- **Tailscale-only access** β€” binds to Tailscale IP by default, blocks external traffic
- **Two service modes** β€” STDIO (MCP standard) and SSE (HTTP for persistent connections)

---

## Quick Start

### Prerequisites

- Node.js 22+
- Playwright Chromium (installed via `postinstall`)
- Tailscale (recommended for SSE mode)

### Setup

```bash
# Install dependencies
npm install

# Build TypeScript
npm run build

# Configure environment
cp .env.example .env
# Edit .env: set VAULT_ENCRYPTION_KEY (64 hex chars) or leave empty for auto-generated
```

### Configuration

All configuration via `.env` file or environment variables:

| Variable | Default | Description |
|----------|---------|-------------|
| `VAULT_ROOT` | `./vault` | Storage directory for encrypted vault files |
| `VAULT_ENCRYPTION_KEY` | `auto-generated` | AES-256 key (64 hex chars, persist for data survival) |
| `AUTH_SSE_PORT` | β€” | Enable SSE mode on given port (empty = STDIO mode) |
| `AUTH_BIND_ADDRESS` | auto (Tailscale) | Explicit bind address for SSE mode |
| `BROWSER_HEADLESS` | `true` | Run Playwright in headless mode |
| `BROWSER_TIMEOUT` | `30000` | Browser operation timeout (ms) |
| `AUDIT_LOG_MAX_BYTES` | `10485760` | Audit log rotation threshold (10 MB) |
| `LOG_LEVEL` | `info` | Logging level: debug, info, warn, error |

---

## Usage

### STDIO Mode (default for MCP clients)

```bash
node dist/index.js
```

### SSE Mode (HTTP server for persistent connections)

```bash
# Set AUTH_SSE_PORT=5501 in .env, then:
node dist/index.js
```

### Web UI Dashboard

```bash
node dist/web/server.js
# Dashboard at http://<tailscale-ip>:5600/
```

### CLI Commands

```bash
npm run add-creds     # Add credentials interactively
npm run add-secret    # Add a secret interactively
npm run list-creds    # List stored credentials
npm run list-secrets  # List stored secrets
npm run get-creds     # Get credential details

# SSH keys
npm run add-ssh-key       # Add an existing SSH key interactively
npm run generate-ssh-key  # Generate a new SSH key pair and store it
npm run list-ssh-keys     # List stored SSH keys
npm run get-ssh-key       # Get SSH key details
```

---

## REST API

### Credentials
| Method | Path | Description |
|--------|------|-------------|
| `GET` | `/api/credentials?includePassword=true` | List credentials (optionally with passwords) |
| `GET` | `/api/credentials/:id` | Get credential details (password hidden by default) |
| `POST` | `/api/credentials` | Create a credential |
| `DELETE` | `/api/credentials/:id` | Delete a credential |

### Secrets
| Method | Path | Description |
|--------|------|-------------|
| `GET` | `/api/secrets` | List secrets (metadata only) |
| `POST` | `/api/secrets` | Create a secret |
| `DELETE` | `/api/secrets/:id` | Delete a secret |
| `GET` | `/api/secrets/:id/detail` | Get decrypted secret value |

### SSH Keys
| Method | Path | Description |
|--------|------|-------------|
| `GET` | `/api/ssh/:id/config` | Get `~/.ssh/config` fragment for a key |
| `GET` | `/api/ssh/:id/file` | Download the private key file |

### Audit & Health
| Method | Path | Description |
|--------|------|-------------|
| `GET` | `/api/audit?limit=50` | Read recent audit log entries |
| `POST` | `/api/audit` | Manually record an audit action |
| `GET` | `/api/health` | Vault health summary (integrity + storage + audit stats) |
| `GET` | `/api/discovery` | Metadata overview of vault contents (no decryption) |
| `GET` | `/api/password/generate?length=16&symbols=true` | Generate strong password(s) |

---

## MCP Tools

Tools are exposed under the `mcp_auth_vault_*` namespace:

- **Credentials:** `store_credentials`, `get_credentials`, `list_credentials`, `delete_credentials`, `get_credentials_for_service`, `attach_totp`, `generate_totp`, `generate_totp_by_service`, `totp_qr`
- **Secrets:** `store_secret`, `get_secret`, `list_secrets`, `delete_secret`, `update_secret`, `audit_secret_expiry`
- **SSH:** `store_ssh_key`, `get_ssh_key`, `list_ssh_keys`, `delete_ssh_key`, `generate_ssh_key`, `export_ssh_config`, `export_ssh_key_file`, `get_ssh_fingerprint`, `extract_ssh_public_key`, `update_ssh_key`
- **Services:** `get_service`, `list_services`, `add_service`
- **Login:** `auth_login`, `login_status`, `submit_totp`, `logout`
- **Audit:** `list_audit_actions`, `log_audit_action`, `vault_integrity_check`, `vault_health_summary`

---

## Systemd Services

```bash
# MCP SSE server (port 5501)
systemctl status mcp-auth-vault

# Web UI dashboard (port 5500)
systemctl status mcp-auth-vault-web
```

Both services restart automatically on failure and enable at boot.

---

## Security

- **AES-256-GCM** encryption for all stored credentials and secrets
- **Tailscope-restricted** β€” SSE mode blocks non-Tailscale connections
- **Encryption key** persisted in `.env` β€” if lost, data cannot be recovered
- **Headless browser** β€” no visible UI during automated logins

---

## Project Structure

```
src/
β”œβ”€β”€ index.ts              # MCP server entry (STDIO + SSE)
β”œβ”€β”€ config.ts             # Zod-validated configuration
β”œβ”€β”€ credentials/
β”‚   β”œβ”€β”€ totp.ts           # TOTP (RFC 6238) implementation
β”‚   β”œβ”€β”€ qr.ts             # QR code generation + TOTP secret generator
β”‚   β”œβ”€β”€ vault.ts          # Encrypted credential store
β”‚   └── types.ts          # Credential type definitions
β”œβ”€β”€ secrets/
β”‚   β”œβ”€β”€ manager.ts        # Encrypted secrets store
β”‚   └── types.ts          # Secret type definitions
β”œβ”€β”€ browser/
β”‚   └── manager.ts        # Playwright session management
β”œβ”€β”€ services/
β”‚   └── definitions.ts    # Login templates (Google, etc.)
β”œβ”€β”€ web/
β”‚   β”œβ”€β”€ server.ts         # Web UI HTTP server + REST API
β”‚   └── dashboard.ts      # HTML dashboard template
β”œβ”€β”€ tools/
β”‚   β”œβ”€β”€ credentials.ts    # MCP tool definitions for credentials
β”‚   β”œβ”€β”€ secrets.ts        # MCP tool definitions for secrets
β”‚   β”œβ”€β”€ services.ts       # MCP tool definitions for services
β”‚   └── login.ts          # MCP tool definitions for login
└── cli/
    β”œβ”€β”€ add-credentials.ts
    └── add-secret.ts
```

---

## Tech Stack

- **Runtime:** Node.js 24, TypeScript ESM
- **MCP:** @modelcontextprotocol/sdk v1.16
- **Encryption:** Node.js crypto (AES-256-GCM)
- **Browser:** Playwright (Chromium)
- **Config:** Zod validation
- **UI:** Vanilla JS (no framework)
- **QR:** qrcode npm package

---

## License

MIT

TDQS

B3.2/5.0

Scored across 32 tools

Disambiguation4/5

Most tools have distinct purposes (credential management, browser automation, captcha/2FA, testing), but some overlap exists between test_* tools and session checks (e.g., test_session_integrity vs check_session), causing minor confusion.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern using snake_case, with clear prefixes (browser_, test_, get_, store_, etc.), making the set predictable and easy to navigate.

Tool Count2/5

With 32 tools, the server is over-scoped. Many testing and health tools could be consolidated, and the core authentication/secret operations could be separated into a smaller, focused set.

Completeness3/5

Core operations for credentials and secrets are present (store, retrieve, delete), but missing update functionality means agents cannot modify existing entries, creating a workflow gap.

Maintenance

ActivityMaintained
ResponsivenessNo issues