Pular para o conteúdo principal

Function: fetchServerConfig()

function fetchServerConfig(issuer: string, config: ServerMetadataConfig): Promise<ResolvedAuthServerConfig>;

Fetches the server configuration according to the issuer and authorization server type.

This function automatically determines the well-known URL based on the server type, as OAuth and OpenID Connect servers have different conventions for their metadata endpoints. It also validates that the issuer field in the fetched metadata matches the expected issuer, as required by RFC 8414 and OpenID Connect Discovery.

Parameters

issuer

string

The issuer URL of the authorization server.

config

ServerMetadataConfig

The configuration object containing the server type and optional transpile function.

Returns

Promise<ResolvedAuthServerConfig>

A promise that resolves to the resolved server configuration with fetched metadata.

See

Example

import { fetchServerConfig } from 'mcp-auth';

// Fetching OAuth server configuration
// This fetches the metadata from `https://auth.logto.io/.well-known/oauth-authorization-server/oauth`
const oauthConfig = await fetchServerConfig('https://auth.logto.io/oauth', { type: 'oauth' });

// Fetching OpenID Connect server configuration
// This fetches the metadata from `https://auth.logto.io/oidc/.well-known/openid-configuration`
const oidcConfig = await fetchServerConfig('https://auth.logto.io/oidc', { type: 'oidc' });

Throws

if the fetch operation fails.

Throws

if the server metadata is invalid, does not match the MCP specification, or its issuer does not match the expected issuer.