credential-use-mcp
# credential-use-mcp
An [MCP](https://modelcontextprotocol.io) server that lets an AI agent manage and **use** passwords, tokens and
API keys, **with your approval at every step** and, whenever possible, **without seeing them**.
- Credentials live in a **KeePassXC / KeePass (KDBX) file** you can open and edit yourself.
- When a task needs a secret, the agent asks for it with `cred_add`: **you** type it in a form or a web page,
and it goes straight to the file. The agent only learns the name, kind, host and username.
- The agent can run the whole CRUD itself: what it proposes (even a secret it already has, such as a password
it generated) comes **prefilled** in the form, and you check or edit it before submitting. Reading a secret
(`cred_reveal`) needs your approval each time.
- To call an API, the agent opens a **local proxy** (`proxy_open`). You approve it for some minutes and/or a
number of requests; the agent sends requests to `http://127.0.0.1:<port>` and the proxy adds the
authentication. The secret never enters the conversation.
- An MCP event, `credentials.changed`, fires when a credential is added, updated or removed (also when you edit
the file in KeePassXC).
- The server tells the agent how to use it (MCP instructions) and ships a skill with worked examples.
It speaks stdio and both MCP protocol eras (2026-07-28 and 2025), so it works with OpenCode, Claude Code,
Hermes, VS Code and any client that supports **elicitation** (forms).
## Quick start
Requires Node 22 or later.
```jsonc
// OpenCode (opencode.json)
{
"mcp": {
"servers": {
"credential-use": {
"type": "local",
"command": ["npx", "-y", "credential-use-mcp"],
"environment": {
"CREDUSE_KDBX_PATH": "~/.config/credential-use/credentials.kdbx",
"CREDUSE_KDBX_PASSWORD_FILE": "~/.config/credential-use/password"
}
}
}
}
}
```
```sh
# Claude Code
claude mcp add credential-use -e CREDUSE_KDBX_PASSWORD_FILE=~/.config/credential-use/password -- npx -y credential-use-mcp
```
The file is created on first use if it does not exist. Put the master password in a file only you can read
(`chmod 600`), or pass it in `CREDUSE_KDBX_PASSWORD`.
Then ask the agent something like *"store my GitHub token and list my repos"*.
## Tools
| Tool | What it does |
| ------------- | ------------------------------------------------------------------------------------------------ |
| `cred_list` | Names, kinds, hosts and usernames of the stored credentials. Never a secret. |
| `cred_add` | A new credential, in a form prefilled with what the agent proposes (name, kind, URL, username, header, notes, and the secret only if it already has it). Without a proposed secret you type it. |
| `cred_edit` | Changes one: the form shows its public fields plus the agent's proposed changes. An empty secret keeps it. |
| `cred_remove` | Deletes one after you confirm. |
| `cred_reveal` | Gives the agent a secret's value, after you approve that one read (you see its reason). |
| `proxy_open` | Opens a local proxy to an HTTP credential's service, after your approval. |
| `proxy_list` | Open proxies and approvals still valid. |
| `proxy_close` | Closes a proxy and ends its approval. |
Credential kinds and what the proxy sends:
| Kind | Header |
| ------------- | ----------------------------------------------------------- |
| `http-bearer` | `Authorization: Bearer <secret>` |
| `http-basic` | `Authorization: Basic <username:secret>` |
| `api-key` | `<header>: <secret>` (header name defaults to `x-api-key`) |
| `generic` | bearer, or basic when it has a username |
| `ssh`, `database` | stored, but not proxied yet |
## How you are asked: form or page
| Mode | What you see | Secret while typing |
| ------ | ------------------------------------------------------------------ | ------------------- |
| `form` | A form inside your agent app | Visible |
| `url` | A link to a page served by this server, with a real password field | Hidden |
`CREDUSE_SECRET_INPUT` picks the one you prefer. If your client cannot show it (or the page cannot be served),
the other one is used. Pages live on `127.0.0.1`, use a random single-use link that expires in thirty minutes, and
the answer goes straight to this process. For an agent on another machine, `CREDUSE_URL_ACCESS=opentunnel`
(or `both`) also publishes the page on an [OpenTunnel](https://opentunnel.xyz) route.
## Approvals
Nothing is stored, changed, deleted or revealed until you submit the form or page. When the agent proposes a
secret, it is shown in clear (the agent already knows it) so you can check it; a secret you type stays hidden on
the page and is never shown to the agent. The answer tells the agent whether you kept its proposed secret, never
the value you typed instead.
`proxy_open` asks you, every time there is no valid approval for that credential:
- allow for some minutes, for a number of requests, or both;
- allow one request;
- deny.
While an approval lasts, `proxy_open` returns the same proxy without asking, and every request through the proxy
uses one. When it runs out the proxy answers `403` and the agent must call `proxy_open` again. Approvals and
proxies live in memory: they end with the server process (your agent session). A proxy also closes when its
credential is changed or removed.
The proxy only reaches the credential's own origin (scheme, host and port), drops the agent's `Authorization`,
`Cookie` and `Proxy-Authorization` headers, and replaces the secret with `[REDACTED]` if a text response
echoes it.
## Configuration
All settings are environment variables.
| Variable | Default | Meaning |
| ---------------------------- | ------------------------------------------- | ---------------------------------------------------------- |
| `CREDUSE_KDBX_PATH` | `~/.config/credential-use/credentials.kdbx` | The KDBX file |
| `CREDUSE_KDBX_PASSWORD` | | Master password |
| `CREDUSE_KDBX_PASSWORD_ENV` | | Name of another variable that holds the master password |
| `CREDUSE_KDBX_PASSWORD_FILE` | | File whose first line is the master password |
| `CREDUSE_KDBX_KEYFILE` | | KeePass key file (alone or with a password) |
| `CREDUSE_KDBX_GROUP` | `credential-use` | Group where new entries go |
| `CREDUSE_KDBX_CREATE` | `true` | Create the file when missing |
| `CREDUSE_MIN_SECRET_LENGTH` | `6` | Shorter secrets are refused |
| `CREDUSE_SECRET_INPUT` | `form` | Preferred way to ask: `form` or `url` |
| `CREDUSE_URL_ACCESS` | `loopback` | Where pages are offered: `loopback`, `opentunnel`, `both` |
| `CREDUSE_APPROVAL_MINUTES` | `15` | Minutes proposed when approving a proxy |
| `CREDUSE_APPROVAL_USES` | `0` | Requests proposed (0: propose a time limit only) |
One of the password, password file or key file is required; without it every tool explains what to set.
## Entries in the file
Each credential is an entry whose **title** is its name: username, password (the secret), URL and notes are the
standard fields. The kind is the custom field `apex:kind` and the API-key header the custom field `header`
(compatible with files created by [opencode-apex](https://github.com/aorizondo/opencode-apex)). You can edit
entries in KeePassXC; the server notices and emits `credentials.changed`.
## Events
With the MCP Events extension (protocol 2026-07-28) a client can subscribe to `credentials.changed`
(`events/stream`, arguments `{ action?, name? }`). In OpenCode it can trigger an automation:
```json
{ "type": "event", "server": "credential-use", "event": "credentials.changed", "args": { "action": "added" } }
```
## Security notes
- In **form** mode the secret is visible on screen while you type, and passes through your agent app's memory
(never the model). Use **url** mode to type it in a hidden field.
- The KDBX file is written atomically with mode `0600`. Keep its password out of config files and shell
history: prefer `CREDUSE_KDBX_PASSWORD_FILE`, or `CREDUSE_KDBX_PASSWORD_ENV` naming a variable your agent app
already has (local MCP servers inherit its environment).
- Anything that can reach `127.0.0.1` on your machine can use an open proxy while its approval lasts. Keep
approvals short on shared machines.
- Responses from the proxied API reach the agent as they are (except the secret itself, scrubbed).
## Development
```sh
npm install
npm test # end-to-end over stdio (Bun), build, smoke test of the build under Node
npm run typecheck
```
## License
MIT
TDQS
Scored across 8 tools
The set splits cleanly into two namespaced groups: cred_* for credential CRUD/reveal and proxy_* for proxy lifecycle. Within each group every tool targets a distinct action, and the descriptions explicitly resolve the only potential confusion (cred_reveal vs proxy_open) by stating when each should be used.
All eight tools follow a uniform snake_case prefix_verb pattern (cred_list, cred_add, cred_edit, cred_remove, cred_reveal, proxy_list, proxy_open, proxy_close). The two prefixes map predictably to the two resource families.
Eight tools is well-scoped for a credential vault plus proxy surface, with no redundant or filler tools. Each tool earns its place in a clear lifecycle.
Credential lifecycle (list/add/edit/remove/reveal) and proxy lifecycle (list/open/close) are both covered, with no dead ends for core workflows. Minor gaps exist, such as no standalone way to inspect or revoke a single approval beyond closing its proxy, but these are workaroundable.