Currently Available: Need a skilled Software Developer for your next project?
Categories
Coding Agents

How to Build a Multi-User Remote MCP Server With Each User’s API Credentials

A remote MCP server lets an MCP client call tools hosted over a network. The Model Context Protocol (MCP) defines how those clients and servers exchange tool requests. When multiple people share the same server, each caller needs to use their own account with the external service behind the tools, such as a calendar, CRM, or issue tracker.

To support that, you build two separate authorization steps. First, your server authenticates the caller and checks what they are allowed to do. Second, your server uses that verified identity to look up the API credential that person linked to the external provider. Separating those two steps stops one user from sharing another user’s provider access, and it keeps the server from treating an MCP login token as a credential for an unrelated service.

Authenticate the MCP caller first

Before running any tool, your MCP server needs to verify the incoming request. For remote HTTP servers, MCP’s authorization model treats the server as a resource server. That means the server checks access tokens issued by an authorization server. That token identifies the caller and grants access to the MCP server, though it does not grant access to a third-party API. The MCP authorization specification covers this server-side model and discovery flow in detail.

Once your server validates a token, it reads the trusted claims inside that token to identify the caller. Claims are the fields that state who the token represents and what permissions it grants. A reliable way to build an identity key is to combine the token’s issuer and subject, or to map those claims to an internal account ID. Never use a user_id or email address passed in a tool argument to pick whose credentials the server will use. A caller can pass an argument to name a record they want to read, while the server still checks that the authenticated caller has permission to access it.

Your token verifier needs to check several things before accepting a request:

  • The token came from a trusted issuer and names this MCP server as its intended audience or resource.
  • The token has not expired and carries a valid signature (or, if your verifier checks with the issuer instead, the issuer confirms the token is active).
  • The token grants the scopes, or permissions, required for the request.

An access token issued for another service is invalid for your MCP server even if it belongs to the same person. The OAuth resource indicator standard explains how OAuth clients name the specific service they want a token to access.

MCP authorization protects access to the server itself. Your server still needs application-level checks for every tool and every requested record, because a valid login does not mean a user can run every action or read another tenant’s data.

Link each user’s provider account

After your MCP server identifies the caller, it needs a separate way to connect that person to the downstream provider. You can either have each user authorize the integration through OAuth or let each user supply an API key, depending on what the provider supports.

How you connect the user When to choose it What your server must manage
Have the user authorize via provider OAuth The provider supports delegated access and user consent Consent flows, provider scopes, token refresh, expiration, and revocation
Let the user enter an API key The provider supports keys but lacks suitable per-user OAuth Protecting the key, replacing or rotating it, and limiting its provider-side permissions

When you use per-user OAuth, each person authorizes the integration directly at the provider, and your server stores the resulting credentials against their authenticated account. When a tool runs, your server retrieves that person’s credential and follows the provider’s documented refresh or reauthorization flow if the token has expired. Request only the provider scopes the tool needs. OAuth security guidance requires Proof Key for Code Exchange (PKCE) for public clients and recommends it for confidential clients; the OAuth 2.0 security best current practice explains these protections.

When you accept a user-supplied API key, build a separate account-settings flow where the signed-in user enters the key, then save it in a protected credential store tied to their account. Do not ask the model to collect an API key through ordinary tool arguments, because doing so puts the secret into the text and data the model sees while handling the request. The MCP elicitation guidance explains how to keep sensitive credential entry outside that context.

MCP does not require one universal method for linking a user’s account to a downstream provider. Check the provider’s documentation to see which OAuth grants, scopes, refresh behaviors, and revocation endpoints it supports.

Select credentials from request identity

Every time a tool runs, your server must use the verified caller identity from that specific request to look up the caller’s provider connection. If User A and User B call the same tool at the same time, each request resolves its own credentials independently. Never store a mutable “current user” or provider token in a shared handler, static variable, or connection object, or one request can leak into another.

Constrain every credential lookup by both the authenticated owner and the provider. If a caller passes a secret name or provider account ID, your server must never let that input select another person’s credential. Tie each account link to a stable issuer-and-subject identity or an internal account ID rather than an email address, since email addresses can change or be reassigned to someone else.

Before your server calls the downstream API, it should verify all of the following:

  • The MCP token is valid for this server.
  • The authenticated caller is allowed to run the requested tool.
  • The linked provider credential belongs to that caller and grants the access the operation requires.
  • The caller has permission to access the requested record or perform the action.

Keep MCP tokens separate from provider credentials

Do not forward an incoming MCP bearer token to a downstream API. The authorization server issued that token for your MCP server, whereas the downstream provider expects a credential meant for its own service. Under the MCP authorization model, your server validates tokens for its own protected resource and does not repurpose them for other services.

Instead, your server should call the downstream API with the user’s stored provider credential. If both the provider and your authorization server support an on-behalf-of exchange or another token-exchange flow, use it only after you verify its audience, permissions, and provider-specific requirements. A shared service credential fits only when your product intentionally acts as a service account, and even then your MCP server must enforce each caller’s permissions.

Protect credentials throughout their life cycle

Store provider access tokens, refresh tokens, and API keys in a secrets manager or another dedicated credential store. Restrict your server so it can read only the credentials it needs, encrypt secrets both in storage and in transit, and audit access and changes. Google Cloud’s Secret Manager guidance details least-privilege access, secret-level controls, and data-access logging. The storage product, retention period, and rotation schedule you choose will depend on your deployment and the provider.

Keep secrets out of source code, ordinary configuration files, prompts, tool results, logs, traces, and error messages. When a user disconnects an account, your server should delete the local credential link and revoke the grant at the provider if the provider supports revocation. When credentials expire, a refresh fails, a user revokes access, or a provider hits rate limits or outages, return an error that tells the user what to do next without exposing any secret values.

Match behavior to the MCP version you deploy

MCP clients, servers, and SDKs do not all support the same protocol revision. Check which revision your client and server SDK support before you copy version-specific authorization or session behavior. The MCP specification changelog tracks changes across revisions, including updates to protocol-level session behavior.

Follow your chosen SDK’s documented HTTP responses for authentication failures. For example, the TypeScript SDK v2 authorization documentation returns 401 for missing, malformed, or expired tokens, and 403 for insufficient scopes. Other SDK versions may behave differently, so check the docs for the version you deploy. If your implementation uses sessions, bind each session to its authenticated principal so one user’s session can never serve another user.

For more detail on the MCP login flow, see how to add OAuth authorization to a remote MCP server. If your API lacks a read-only OAuth scope, a read-only MCP server design can show how your server can enforce limits beyond what the provider’s scopes offer.

Test cross-user isolation

Before you launch, send concurrent requests from different user accounts and confirm that each request uses only its own provider credential. Try to make a caller switch identities by passing another user’s ID, email address, provider account ID, or secret identifier, and verify that the server rejects the attempt. Confirm that invalid, expired, wrong-audience, and insufficient-scope MCP tokens fail before any tool calls the downstream provider.

Test the failure paths for provider connections as well. Refreshing or revoking a credential for one user must not affect anyone else. Once a user disconnects a credential, it must stop working immediately, and your logs and tool outputs must stay free of tokens, keys, and secret-store payloads. Finally, check that provider timeouts, authorization failures, rate limits, and outages return safe, clear errors.

What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Email updates

Usually a new article and a few links I found interesting.

No spam. Unsubscribe with one click.

Leave a Reply

Your email address will not be published. Required fields are marked *