How to stop sharing credentials with AI agents
Short answer: keep each secret where the agent cannot read it, and give the agent short-lived access instead. With swarmvia, each database, API, and MCP server is a source, and its credential stays in swarmvia. Agents connect over MCP and get a session key for one source that lasts about an hour; swarmvia adds the real credential at the edge.
Getting an agent to do real work usually means handing it a secret. A
database password goes in .env so the agent can run a query. An API token
goes in mcp.json so a server can call the vendor. A key gets pasted into
the chat "just this once". Each of those works, and each one leaves a
credential somewhere you no longer control.
This page shows the alternative: agents get access to your systems, not the credentials for them.
Where do AI agents leak credentials?
- Files the agent can read. An agent with file access reads
.env,config/*.yml, and shell history as readily as source code. Whatever it reads can end up in its context. - MCP config.
claude_desktop_config.json,.cursor/mcp.json, and.vscode/mcp.jsonhold connection strings and tokens in plaintext, one copy per laptop. - The chat. A pasted key lives in the transcript, and in every summary, log, or tool call that quotes it.
- The agent's output. Agents write code, commit messages, and debug output. A secret in context can be echoed into any of them.
Then there is the people problem. A shared password cannot be traced to the person who used it, and removing one person means rotating it for everyone.
How do you give an agent access without the credential?
With swarmvia, each system the agent needs is a source. Its secret stays in swarmvia, and the agent never sees it.
- You store the credential once: a database role, an API key, an OAuth connection, or an MCP server's token. The dashboard never shows it again.
- The agent connects to
https://swarmvia.com/mcpwith OAuth. On the approval screen you pick which sources it may use and whether it may write. - To do work, the agent starts a session: a short-lived key for one source that lasts an hour by default. It sends requests to the source, and swarmvia adds the real credential at the edge.
- When the work is done the key expires, or the agent ends the session early.
What the agent holds is a key that works on one source, for a limited time, within limits you set. What it never holds is the password.
By type of credential
Database passwords
swarmvia connects as a read-only role you create. The agent reads the schema and runs SQL through the source and never sees the password. See Connect a database to your AI agent.
MCP server tokens
swarmvia is the MCP server's client and owns its token or OAuth connection. Agents reach the server's tools through swarmvia, and you choose which tools they may call. See MCP gateway.
API keys and OAuth apps
On a managed source, swarmvia attaches the upstream credential for you: a bearer token, basic auth, an API key, OAuth 1.0, or OAuth 2 (client credentials or a refresh token). The agent sends requests to the source's endpoint with its session key, and the vendor's credential is added at the edge. Rotating the credential updates every source that uses it, with no change on the agent's side. See Credentials.
When the provider should see the person behind each call (GitHub or Linear permissions, for example), each member connects their own account and calls act as them.
Move the secrets you already have
Most projects already have keys in .env. Approve the agent with This agent
may move origin keys onto sources, and it can move one over without the key
ever entering the chat: it posts the key from the project straight to a
one-time intake URL, or gives you a dashboard link to paste it yourself. After
that, delete the key from the project.
For MCP servers already in your harness config, the migrate_mcp prompt adds
them as sources one at a time, and you add their tokens on the source page.
See Migrating MCP servers into swarmvia.
Offboarding and rotation
- Removing a person revokes the keys that act for them. Disconnect a single agent under Settings → Connected agents. Nobody else rotates anything.
- Rotating a secret happens once, in Credentials. Every source using it picks up the new secret within seconds.
- Auditing is the source's logs: each call records the key that made it and the person it acts for.
What this does not cover
- Local MCP servers. A server that runs as a local command (stdio) or on
localhoststays in the harness config, along with whatever it needs. - Pass-through sources. A source where the caller supplies the upstream credential itself does not hide that credential. Use a managed source for anything an agent touches.
- Permissions inside the system. swarmvia decides who reaches a system, for how long, and how often. The database role or API scope still decides what that access can do, so grant only what the agent needs.