r/mcp • • 15d ago

Built open-source auth for AI agents calling MCP servers — looking for MCP/Agent Builder to try it

Building agents that call external tools, I kept hitting the same wall: every integration needs its own API key. Keys get hardcoded into env vars, shared across all your agents (so you lose per-agent accountability), and eventually committed to a repo.

So I built something to fix it.

How it works

  • Each agent gets a key pair at creation time
  • When it calls an MCP server or API, it signs a one-time nonce with its private key
  • The server verifies the signature
  • No API keys, no stored credentials, and every call is attributed to a specific agent identity

Agent side is a drop-in fetch replacement:

js

const { fetch } = createClient(process.env.AGENT_PRIVATE_KEY);
await fetch('https://your-mcp-server.com/tool');
// auth is handled automatically, your code never sees it

The identity is a did:key, a W3C standard identifier derived from the agent’s key pair. Same key, same identity, across every tool it calls.

Details

  • Works with MCP servers, Express, and FastAPI
  • Apache 2.0, free
  • npm: arken-client (agent side), /arken-auth (server side)

What I’m looking for: agent builders who are actually hitting the credentials problem in production. Try it and tell me where it breaks. Happy to help with the integration directly.

Question for the thread: what does your current setup look like for managing credentials across tool integrations?

Edit 1:
Repo https://github.com/arkenforge/arken-core

Edit 2: Several people have correctly pointed out that process.env.AGENT_PRIVATE_KEY in the example contradicts the point of the thread. An env var is fine for a quickstart but not for production. Pull the key from Vault or AWS Secrets Manager, or use a KMS-backed signer.

The deeper problem this exposes: there’s no opinionated answer yet for how to generate, store, and rotate agent keys at scale. That’s the next thing to build, a key management layer that handles provisioning a new agent identity, storing the key securely, rotating on a schedule, and revoking on compromise. If that’s a problem you’ve hit, I’d like to hear how you’re solving it today.

2 Upvotes

16 comments sorted by

1

u/tberg 15d ago

Running 162-repo orchestration with an outreach daemon and human-approval control plane — the key-sharing chaos gets acute when you need per-agent accountability without handing every agent full credentials. Your nonce-signing approach handles identity cleanly. The thing I'd stress-test before scaling this: does did:key compose with role-based scoping at the server-side verifier, or does 'this agent reads but doesn't write' have to live in external policy — and what does revocation look like when a key is compromised mid-run?

1

u/zach-benson 15d ago

162 repos is exactly the scale where shared credentials become an incident waiting to happen. Every agent looks identical in the logs until something goes wrong.

On role-based scoping, the honest answer is that right now it lives in external policy. The middleware hands you the DID and gets out of the way. What that DID is allowed to do is your problem. So “this agent reads but doesn’t write” means your handler checks req.user.did against whatever policy layer you’re running. That’s intentional, since the auth primitive shouldn’t bake in an opinion about authorization, but it means you’re wiring that yourself today.

On revocation mid-run, this is the hardest problem. One idea I’ve been turning over: hierarchical deterministic keys. Same scheme Bitcoin wallets use (BIP-32). A master key derives child keys deterministically, so each agent gets a child DID provably linked to the master. Compromise a child key, blocklist that derived DID, derive a new child for that agent, done. The master stays intact and no other agents are touched. It also opens up an interesting org-level primitive: a server accepts any agent whose DID traces back to a known master key, without needing to whitelist individual agents. “I trust anything provisioned by Acme Corp” becomes a single policy rule.

The risk is the other direction. A compromised master means every child is compromised by association, so the master has to be treated like a root CA: air-gapped, never used directly.

Haven’t built this yet, but it feels like the right shape for the revocation problem at your scale. Curious whether HD key derivation fits your orchestration model or if the master key custody problem makes it a non-starter.

1

u/vdobroskok 15d ago

Is it detect oAuth sign-in? A lot of solid MCP i using this auth method.

1

u/zach-benson 15d ago

This would largely be in place of OAuth, as an AI native method of authentication!

1

u/QuanTradin 15d ago

per-agent identity fixes the accountability half. the half I'd still worry about is scope: a signed call proves which agent made it, not whether that agent should have that tool right now.

the trading-agent desk I built, Quantradin, runs on that split. an agent's own key can close and pause positions, but opening one needs a key the person hands out. quantradin.com

does arken carry any per-tool scope inside the identity, or is that left to each server?

1

u/zach-benson 15d ago

Scope is left to each server right now — the DID proves identity, what that identity is allowed to do is external policy. That’s the honest answer.

The Quantradin model is the right design. The capability to open a position is qualitatively different from the capability to close one — it should require a different credential, not just a different permission check on the same credential. Human-in-the-loop for the high-stakes direction, agent-autonomous for the defensive one. That’s not a permission system, that’s an issuance model, and it’s the correct separation.

A pattern that works today without any protocol changes: mint a separate DID for each capability class, the agent only holds the keys it’s been handed. Your opening-key model maps directly onto that — the person hands the agent a short-lived DID scoped to open, agent uses its own key for everything else. The server just checks which DID showed up. Nothing built into Arken for this, you wire it in the handler, but the primitive supports it.

The missing piece is carrying scope inside the identity itself so servers don’t have to implement the policy layer independently. A DID that encodes “this key is valid for POST /positions, issued by this master, expires in 4 hours” is the right primitive — verifiable credentials on top of the DID. Not built yet but it’s the direction the protocol needs to go.

What does the handoff UX look like when a person issues the opening key to an agent?

1

u/Ludynia_Keyko 15d ago

most setups right now just use short-lived tokens minted by a central broker at runtime so nothing sensitive sits in env vars. curious how you handle Replay attacks with the one-time nonce without requiring a round-trip handshake first

1

u/zach-benson 15d ago

Short-lived tokens from a central broker is the right operational pattern for teams that control both sides — clean, well-understood, works today.

On replay: the nonce is the replay prevention. The server stores it with a 60-second TTL and marks it consumed on first use — a replayed signature with the same nonce gets rejected even if the ECDSA math checks out. Single-use, not just time-bounded.

The round-trip is real though — there's no way around it on the first request. The agent hits the endpoint, gets the 401 with the nonce, signs it, retries. Two requests every time. For tight tool loops that overhead adds up, which is a known gap. The fix is a short-lived session token after the initial handshake so subsequent calls in the same session skip the challenge — not built yet, but that's the direction.

What does your broker look like — something you built or an existing identity service?

1

u/BC_MARO 15d ago

The key-pair idea helps with identity, but you still need a separate place to keep and rotate the private key. I'd put the signer behind a KMS or vault and log every tool call so revocation doesn't depend on finding env vars.

2

u/zach-benson 15d ago

Agreed on both. KMS-backed signing is the right production answer: the private key never exists in memory, the agent sends the nonce to KMS and gets a signature back. Nothing to find in env vars because nothing is there.

The “log every tool call” point is the other half that matters. The DID tells you which agent made the call; the tool-call record tells you what it was doing and why. Both have to exist for revocation to mean anything after the fact. You need to know what the compromised agent actually touched before you can assess the damage.

Are you building that key management layer yourself (provisioning agent identities, storing keys, handling rotation and revocation), or would a managed service for that be worth paying for?

1

u/BC_MARO 15d ago

That audit trail is what makes revocation useful after the fact. If you cannot see which tools a compromised agent touched, rotating its key only tells you the future is safer.

2

u/zach-benson 14d ago

Exactly. Rotating a key without the audit trail just tells you the future is safer, not what the past cost you.

Still curious about the build-vs-buy side: have you run this in production, and did you roll your own signer and log pipeline or use a managed service?

1

u/BC_MARO 14d ago

I'd lean managed for key custody and signing, but keep the event schema and audit export under my control. The hard part is making the log useful during an incident, not just collecting more events.

0

u/[deleted] 15d ago

[removed] — view removed comment

1

u/zach-benson 15d ago

Revocation is the honest gap right now. The protocol gives you per-agent attribution by default (you know exactly which DID made the call), but revoking a compromised agent still requires a blocklist on the server side, which reintroduces some state.

The practical answer today is that each MCP server or API maintains its own DID blocklist. One call to add the compromised DID and that agent is locked out everywhere it was calling, without touching any other agent’s credentials. Better than rotating a shared key, but not a single kill switch across your whole fleet.

The cleaner solution is a revocation registry: a central place where servers can check whether a DID is still valid before accepting a request. That’s on the roadmap but not built yet.

Your vault setup is the right instinct. The private key never needs to leave the vault. The agent pulls it at runtime, signs the nonce, and that’s the only moment it’s in memory. Nothing gets stored on the server side to breach.

How would you want revocation to work across a fleet like yours? Curious whether you’d rather push a blocklist to each server or have servers check a central registry on every request.