> ## Documentation Index
> Fetch the complete documentation index at: https://docs.skybridge.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# mcpAuthMetadataRouter

> Advertise your authorization server for client discovery

When a client reaches your server without a token, it needs to know where the user signs in. `mcpAuthMetadataRouter` advertises that, so clients can discover your authorization server on their own.

## Example

The server publishes where to authorize, so a client hitting a 401 can find the authorization server on its own.

```ts server.ts highlight={4-13} theme={null}
import { Skybridge, mcpAuthMetadataRouter } from "skybridge/server";

export const app = new Skybridge({ name: "shop", version: "1.0", handler }).use(
  mcpAuthMetadataRouter({
    oauthMetadata: {
      issuer: "https://auth.example.com",
      authorization_endpoint: "https://auth.example.com/authorize",
      token_endpoint: "https://auth.example.com/token",
      response_types_supported: ["code"],
    },
    resourceServerUrl: new URL("https://api.example.com/mcp"),
    scopesSupported: ["shop.read"],
  }),
);
```

## Signature

```ts theme={null}
mcpAuthMetadataRouter(options: AuthMetadataOptions): Router;
```

## Parameters

### `options`

```ts theme={null}
type AuthMetadataOptions = {
  oauthMetadata: OAuthMetadata;
  resourceServerUrl: URL;
  scopesSupported?: string[];
  serviceDocumentationUrl?: URL;
  resourceName?: string;
};
```

| Field | Purpose |
| - | - |
| `oauthMetadata` | Your authorization server's [RFC 8414](https://datatracker.ietf.org/doc/html/rfc8414) metadata. At minimum the `issuer`, `authorization_endpoint`, `token_endpoint`, and `response_types_supported`. |
| `resourceServerUrl` | This MCP server's URL. Published in the protected-resource metadata so clients map this server to its authorization server. |
| `scopesSupported` | The scopes this server recognizes. |
| `serviceDocumentationUrl` | Link to human-readable docs for this server. |
| `resourceName` | Display name for this resource in the metadata. |

> [!NOTE]
>
> Check your OAuth provider's docs for the metadata values it expects.

## Returns

An [Express `Router`](https://expressjs.com/en/5x/api/router/) to pass to [`server.use`](https://docs.skybridge.tech/api-reference/mcp-server#use). It serves your OAuth 2.0 [Protected Resource Metadata](https://datatracker.ietf.org/doc/html/rfc9728) at `/.well-known/oauth-protected-resource`.

> [card] [requireBearerAuth](https://docs.skybridge.tech/api-reference/require-bearer-auth.md)
>
> Require a token on every request

> [card] [optionalBearerAuth](https://docs.skybridge.tech/api-reference/optional-bearer-auth.md)
>
> Accept a token when present, allow anonymous otherwise

> [card] [Authenticate Users](https://docs.skybridge.tech/build/auth.md)
>
> Add sign-in to your app end to end


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.