Article

MCP and delegated access: agents that see only what the user can see

Connect an AI agent to GitHub, your tracker and wiki through MCP with each user's own OAuth token, small scopes, audit logs and approval for writes.

Published Updated 8 min read

This guide shows how to connect an AI agent to team tools through the Model Context Protocol (MCP), for example GitHub, the issue tracker, the wiki, observability, the CMS, search and design tools. The agent works with the access of the person who asks, so it sees only what that person can see. The guide is for platform teams that run an agent for more than one person, and it follows the MCP specification version 2026-07-28. The code uses @modelcontextprotocol/server 2.4.0 and zod 4.6.7, which are the current npm versions on 1 December 2026.

Why a shared service account leaks data

The quick setup gives the agent one service account per tool, so every user talks to the same account. That causes four problems:

  • The agent can read everything the account can read, so a user who asks a question can get data from a repository or wiki space they have no access to.
  • Text inside a document can steer the agent, and with a broad account, a hidden instruction in one page can make the agent fetch data from other places.
  • The tool’s audit log shows the service account and not the person, so you cannot see who asked for what.
  • If you revoke the account, the agent stops working for everyone.

Delegated access solves the first and third problems. The agent calls each tool with a token of the person who asks, and the tool then applies its own permission checks to that person. GitHub shows how this works for a GitHub App that acts for a user. The app can only reach resources that the user can access and that the app has permission for. GitHub attributes the request to the user, and the audit log lists the user as the actor with a note that a GitHub App user token made the request.

How MCP authorization works

Authorization in MCP is optional. When you use it over HTTP, the MCP server acts as an OAuth 2.1 resource server and the MCP client acts as the OAuth client. Local servers over stdio should not use this flow, but take their credentials from the environment instead.

The flow for a remote MCP server:

  1. The client calls the server without a token, and the server answers 401 with a WWW-Authenticate header.
  2. The header points to the server’s Protected Resource Metadata (RFC 9728), a document that lists the authorization servers.
  3. The client signs the user in with the authorization code flow and PKCE with S256.
  4. The client sends a resource parameter in the authorization and token requests (RFC 8707), with the URL of the MCP server as its value.
  5. The client sends the access token in the Authorization header on every request, and never in the query string.
  6. The server checks that the token was issued for itself as the audience, and an invalid or expired token gets 401.

The challenge and the metadata look like this:

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://mcp-tracker.example.com/.well-known/oauth-protected-resource/mcp",
                         scope="tracker:read"
{
  "resource": "https://mcp-tracker.example.com/mcp",
  "authorization_servers": ["https://idp.example.com"],
  "scopes_supported": ["tracker:read"],
  "bearer_methods_supported": ["header"]
}

For client registration, the specification prefers Client ID Metadata Documents, and Dynamic Client Registration is deprecated in version 2026-07-28.

One token per user and per tool

The token that the client sends is valid for one MCP server only. The specification states that “MCP servers MUST NOT accept or transit any other tokens”, so the server must not pass the client’s token on to an upstream API. For the upstream call, the MCP server acts as an OAuth client itself and uses a separate token.

You have two ways to get that separate token for the same user:

  • Token exchange. This works when the upstream API trusts the same identity provider. The MCP server exchanges the user’s token at the identity provider for a new token (RFC 8693), so the user’s token goes to the identity provider and not to the upstream API.
  • A per-user connection. Many SaaS tools have their own OAuth server, and each user connects the tool once. The MCP server stores that user’s token and refresh token, keyed by the user ID from the verified MCP token.

A token exchange request looks like this, where the line breaks and plain values are only there for readability. Send the body URL-encoded, and authenticate the MCP server as a client.

POST /oauth/token HTTP/1.1
Host: idp.example.com
Content-Type: application/x-www-form-urlencoded

grant_type=urn:ietf:params:oauth:grant-type:token-exchange
&subject_token=<access token that the MCP server received>
&subject_token_type=urn:ietf:params:oauth:token-type:access_token
&resource=https://wiki.example.com/api
&scope=wiki.read

For GitHub, a per-user connection uses a GitHub App user access token. With token expiry turned on, that token expires after eight hours and the refresh token expires after six months.

A server that checks the token first

This MCP server for an issue tracker checks the signature, expiry, audience and scope of each request before any tool runs. The tool then calls the tracker with the token of that user.

import {
  createMcpHandler,
  getOAuthProtectedResourceMetadataUrl,
  McpServer,
  requireBearerAuth,
  type OAuthTokenVerifier,
} from '@modelcontextprotocol/server';
import * as z from 'zod';

const serverUrl = new URL('https://mcp-tracker.example.com/mcp');

// Your code: validate the JWT (issuer, signature, exp) and set
// AuthInfo.resource from the aud claim and AuthInfo.extra.sub from sub.
declare const verifier: OAuthTokenVerifier;
// Your code: the tracker token that this user granted, from your token store.
declare function trackerTokenFor(userId: string): Promise<string>;
declare function audit(entry: Record<string, unknown>): void;

const handler = createMcpHandler(({ authInfo }) => {
  const userId = String(authInfo?.extra?.sub);
  const server = new McpServer({ name: 'tracker', version: '1.0.0' });

  server.registerTool(
    'search_issues',
    {
      description: 'Search issues that the current user can see',
      inputSchema: z.object({ query: z.string() }),
      annotations: { readOnlyHint: true },
    },
    async ({ query }) => {
      const token = await trackerTokenFor(userId);
      const res = await fetch(
        `https://tracker.example.com/api/search?q=${encodeURIComponent(query)}`,
        { headers: { Authorization: `Bearer ${token}` } },
      );
      audit({ userId, tool: 'search_issues', status: res.status });
      return { content: [{ type: 'text', text: await res.text() }] };
    },
  );
  return server;
});

const gate = requireBearerAuth({
  verifier,
  requiredScopes: ['tracker:read'],
  resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(serverUrl),
  expectedResource: serverUrl,
});

export async function fetchHandler(request: Request): Promise<Response> {
  const auth = await gate(request);
  if (auth instanceof Response) return auth;
  return handler.fetch(request, { authInfo: auth });
}

How the parts work together:

  • requireBearerAuth returns either the verified token data or a ready error response, such as 401 or 403.
  • expectedResource refuses tokens issued for another audience, so your verifier must fill AuthInfo.resource, for example from the aud claim.
  • A token without tracker:read gets 403 with insufficient_scope.
  • createMcpHandler builds a fresh server for each request and passes the verified token data to it. MCP 2026-07-28 has no protocol sessions, so each request carries its own user.
  • The SDK also has oauthMetadataResponse to serve the metadata document.

Specialist agents per system

One agent with tools for every system gets a long tool list and many tokens, so a split works better. A main agent receives the question and sends sub-questions to specialist agents, each of which works with one system, such as the tracker, the wiki or observability. The main agent then combines their answers.

Rules for the split:

  • Each specialist connects to one MCP server only.
  • Each specialist uses the asking user’s token for that system, while the main agent holds no tool tokens.
  • If the user has not connected a tool, the specialist says so instead of falling back to a service account.
  • A hidden instruction in a wiki page reaches only the wiki specialist, which has only read tools for the wiki.
  • The main agent passes a correlation ID to each specialist, so the logs connect.

Least-privilege scopes

The MCP security guide describes scope minimization:

  • Start with a small set of scopes for discovery and reading.
  • Ask for more only when a privileged operation runs. In this step-up flow, the server answers 403 with error="insufficient_scope" and the needed scope.
  • Avoid wildcard scopes such as *, all or full-access.
  • Do not publish every possible scope in scopes_supported.
  • Log each elevation, with the scope asked for and the scope granted.

Use separate scopes for reading and writing, such as tracker:read and tracker:write, and never give a write scope to read-only specialists. Keep access tokens short-lived, and have public clients rotate their refresh tokens.

Audit logging of tool calls

The MCP tools page asks clients to log tool usage for audit purposes, and with delegated access each log line can name the person.

{
  "time": "2026-12-01T09:14:03Z",
  "correlation_id": "q-7f3a",
  "user_id": "user-1842",
  "agent": "tracker-specialist",
  "mcp_server": "https://mcp-tracker.example.com/mcp",
  "tool": "search_issues",
  "arguments_sha256": "9c1e...",
  "scopes": ["tracker:read"],
  "approval_card": null,
  "result": "ok"
}

Take the user ID from the verified token and not from the prompt, and store a hash of the arguments if they can hold personal data. Never log tokens. The upstream tool keeps its own log as well, and with delegated tokens that log shows the same person.

Human approval for write actions

The MCP specification says there should always be a human in the loop who can deny tool calls. Clients should ask for confirmation on sensitive operations and show the tool inputs before the call.

Tool annotations help, but they are hints: readOnlyHint defaults to false and destructiveHint defaults to true. Clients must treat annotations as untrusted unless the server is trusted, so enforce approval with your own rule:

  • Read-only tools from servers you trust run without a prompt.
  • Every other tool call becomes a card that a person approves first.
  • The MCP server checks the write scope again on its side.

The card format and the review flow are in coding agents with human approval.

For organisations that want central control over MCP access, the stable MCP extension Enterprise-Managed Authorization builds on single sign-on through the company identity provider. It gives admins visibility and control over which MCP servers people can use, and users no longer connect each MCP server by hand.

In practice

For an international cosmetics retailer, an AI agent in an AI-first rebuild connects to the team’s tools through MCP. Specialist agents handle each system, and the main agent combines their answers.

The agent works with the access of the person who asks, so it only sees the data that this person can see. It shows each action on a card that a person approves first.

Checklist

  • Replace shared service accounts with per-user tokens.
  • Serve Protected Resource Metadata from each remote MCP server.
  • Check the audience of every token with expectedResource.
  • Never pass the client’s token on to an upstream API.
  • Use token exchange or a per-user connection for upstream calls.
  • Give each specialist agent one system and the user’s token for it.
  • Split read and write scopes, and use the step-up flow.
  • Log every tool call with the user ID and a correlation ID.
  • Route write actions through an approval card.

If you want help with the permissions and checks around agent work, see coding agent rollout or AI code review in CI, or get in touch. For what to document about agent use, see the EU AI Act guide for teams with coding agents.

Sources

Let's connect

Talk about your project

Tell us about your team and your problem. In 30 minutes we find out whether one of our offers fits, and if none does, we tell you.

Book a 30-minute call