AI agents (Claude Desktop, Cursor, VS Code extensions, your own bots) increasingly work with real projects — which means they need real keys: OpenAI, Stripe, databases, staging environments. And then the familiar mess starts: .env in the project folder, a key pasted into a prompt, a secret copied into the terminal, a cloud secret manager that feels like overkill for a personal project.

Below is how to solve this locally: don't give the agent permanent access — issue a secret on confirmation, for a limited time, with a log. I'll go into the things that usually stay out of demos: the protocol, error codes, policies, and the threat model.

What MCP gives you and what it doesn't

MCP (Model Context Protocol) is the standard where a client launches a server and talks to it over JSON-RPC on stdio. Typical methods: initialize, tools/list, tools/call.

What the protocol does not have:

  • per-secret access control (the server either knows a value or it doesn't);
  • human confirmation;
  • a log of who asked for what and when;
  • time and count limits on issuance.

So "give the agent secrets via MCP" is not a single config line — it's at least four subsystems around the protocol.

Architecture

Three components:

  1. Local broker — a process that owns the vault (in our case a GUI server, but any daemon works). The master password lives only here.
  2. MCP server (stdio) — the thing the client launches. It does not know the master password.
  3. Bridge — HTTP on localhost with a token stored in a file next to the vault.

Request flow:

Agent → tools/call get_secret("STRIPE_SECRET") │ ▼ MCP server (stdio, JSON-RPC) │ HTTP + bridge token ▼ local broker │ ├─ policy check (category, limits, TTL, parent process) ├─ if confirmation is needed → -32003 confirmation required │ the human clicks "Allow for 1 hour" ├─ return the value + write to the encrypted audit log ▼ response to the agent 

The point: the MCP server never stores the master password; if the broker isn't running, there's no access.

The protocol: a state, not an error

The most useful part is how issuance looks from the agent's side. A request that needs confirmation returns a state, not a value:

{"jsonrpc": "2.0", "id": 2, "error": {"code": -32003, "message": "confirmation required: request req-1795624573-1"}} 

The agent must not treat this as a fatal error: the right reaction is to tell the user that confirmation is needed and retry later. After confirmation, the same call returns the value:

{"jsonrpc": "2.0", "id": 2, "result": {"content": [{"type": "text", "text": "sk_test_..."}]}} 

Error codes we use (all inside the implementation-defined -32000..-32099 range):

Code Meaning What the agent should do
-32002 secret not found check the record name
-32003 confirmation required: request <id> tell the user, retry after approval
-32004 denied by user, retry in <N>s don't spam, wait for the cooldown
-32005 daily limit exceeded (used/limit) report the limit
-32006 process check / other reason show the text to the human
-32008 record is not available to agents (flag or category) the record isn't shared — this is policy, not a bug
-32601 unknown tool / method client error

A note on -32008: it comes back when the record doesn't have the "Available to agents" flag or its category is denied by policy. That's an important signal — the agent should not retry, it should tell the human "this record is not issued to agents".

Policies: where "no" lives

Issuance is governed by a set of rules applied before any response:

  • Categories. API keys — allowed, website passwords — denied by default, records with notes — separately.
  • Lease TTL (ttl_secs, 3600 by default): the value handed out lives for a limited time.
  • Max leases per secret (max_leases_per_secret): one key can't be issued an infinite number of times.
  • Daily request limit (daily_limit): protection from an agent asking 500 times in a loop.
  • Cooldown after denial (deny_cooldown_secs): the human said no — retry after N seconds, not immediately.
  • Parent process check (process_check: off / warn / strict plus allowed_processes): in strict mode only an agent launched by an allowed process gets access. On Linux the parent is read from /proc/<pid>/stat and /proc/<pid>/exe; on Windows from the ToolHelp API.
  • Auto-grant (auto_allow): records issued without confirmation, for those who consciously trust an agent.

Audit: always written, only locally readable

Every event goes to a separate file next to the vault (vault.agents-audit.enc):

  • granted, pending_confirmation, category_denied, process_denied, rate_limited, denied_by_user.

The log is encrypted, and the key is derived from three things: the user, the machine name, and the vault path. Practical consequence: copy the log file to another computer and you can't read it — it only decrypts where it was created.

One detail that's easy to miss: on Windows "user" and "machine" are USERNAME and COMPUTERNAME; Linux doesn't have them. Without fallbacks (USER, HOSTNAME, /etc/hostname) the key degenerates to unknown|unknown|<path>, and logs from different machines with the same path become readable with one key. That was a real porting bug we hit while building for Linux.

Threat model: what is actually protected and what isn't

Protected:

  • secret values never leave the machine;
  • the agent only sees records explicitly allowed for it;
  • without confirmation (or auto-grant) it gets nothing;
  • access is bounded in time and count;
  • the master password is never passed to the MCP server;
  • the log is encrypted and bound to the machine.

Not protected (honestly):

  • if the agent is already compromised and has received a value, it can use it until the lease expires;
  • prompt injection can make the agent ask for a secret — but it still hits human confirmation;
  • if an attacker has root/admin on the machine, they can read process memory;
  • code signing and mobile confirmation are separate problems that the bridge architecture doesn't solve.

This is not a silver bullet; it's a reduction of attack surface: the agent has no permanent access, and the human has a log.

What designing to the protocol (instead of to a demo) gave us

  1. States instead of silence. The -32003 code forced agents to behave correctly: not treat it as a crash, but ask for confirmation.
  2. Policies outside the code. Categories, TTL, limits, process checks are configuration, not branches in a handler. Porting to Linux required replacing exactly one function (parent process detection); everything else moved as is.
  3. Audit as a separate subsystem. Once events became encrypted and machine-bound, it became possible to honestly say "the log exists, but it cannot be exported" — which is the answer to "prove the agent didn't rummage around".

Takeaways

If you're going to give AI agents secrets, start not with a prompt and not with .env, but with three questions:

  • how will the agent ask (protocol and state codes);
  • under what rules will you say no (categories, limits, time, process);
  • where the trace will remain (the log: who asked for what and when).

The rest is implementation detail. Ours fit into a few hundred lines of Rust plus a local bridge.

Project: TenVault · AgentVault — secret access for AI agents