How to Connect AI Agents to Company Apps Without Sharing API Keys

Last updated ·Reviewed by Karim Rahme·Read as Markdown
Answer

Connect AI agents to company apps through a gateway that signs each person in to each app with their own account using OAuth, stores and refreshes the tokens, and gives the agent a single MCP URL. No API key is written to a config file, each agent acts with its own user's permissions, and access ends when the account does. Metorial works this way: people connect apps in a portal, and their Magic MCP URL carries only what they are allowed to use.

Most MCP servers were written for one developer on one laptop, so they ask for an API key in a config file. That is fine for a test. For a company, it means keys with too much access, copied between people, with no record of who used them.

If the app supports
Connect it with
OAuth
Per-user sign-in, so each person uses their own account
Only API keys
A shared connection stored centrally by an admin
Your own OAuth app
Custom OAuth credentials you manage
Jobs with no person behind them
A service account with its own identity

What goes wrong with shared API keys?

A key usually carries the permissions of whoever created it, often an admin. Everyone using it inherits those permissions, including people who should see far less. It sits in plain text on each laptop that has the config file. And because the calls all look the same, nobody can tell afterwards who asked the agent to do what.

How does per-user sign-in fix it?

Each person connects each app with their own account through OAuth, the standard sign-in flow apps like Google, Salesforce, and GitHub already use. The gateway stores the token, refreshes it, and adds it to each call. The agent can reach exactly what that person can reach in the app, because the app enforces its own permissions.

How do you set it up?

1. Add the integration. In Metorial, add the app from the catalog. If you need to control the OAuth app yourself, add custom OAuth credentials and choose the permissions.

2. Make it user-configured. Publish it in a portal as a user-configured listing, so each person connects with their own account.

3. People connect in the portal. Each person clicks connect, signs in to the app, and approves. Nothing is written to their machine.

4. Use one URL. Each person adds their Magic MCP URL to their assistant. It carries their connections and only the tools they are allowed.

5. Check the record. In Tracing, each call should show the person's identity, not a shared connection.

What about apps that only take API keys?

Publish them as pre-configured listings. An admin stores the key once in Metorial, it never reaches a laptop, and calls are still logged per person. Scope the key as narrowly as the app allows.

What about agents with no person behind them?

Give them a service account. It has its own identity and scope, runs under the same access rules, and is logged like everyone else. See also tokenless auth.

Frequently asked questions

What is wrong with API keys in an MCP config file?

The key sits in plain text on a laptop, it often has more permissions than the person using it, it gets copied to teammates, and nothing records which person used it for what.

What if an app only supports API keys?

An admin can store the key centrally as a shared, pre-configured connection. The key then never reaches a laptop, and every call is still logged with the person who made it.

Can we use our own OAuth app instead of the vendor's?

Yes. In Metorial you can connect custom OAuth credentials that you manage and choose the permissions they request.

Does this work for agents that run without a person, such as a nightly job?

Use a service account for those. It gets its own identity, is scoped to what it needs, and is logged like everyone else, instead of borrowing a person's credentials.

What happens when someone leaves?

Their access follows their identity. Offboarding them in the identity provider, or removing their groups, removes the agent's access, with no key to rotate.

Sources

  1. Metorial documentation: Create custom OAuth credentials
  2. Metorial documentation: OAuth with the SDK
  3. Model Context Protocol authorization

Ready to build with Metorial?

Connect any AI agent to any tool or data source. Govern every action.