Skip to main content

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.

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 static server configuration with fetched metadata.

See​

Example​

import { fetchServerConfig } from 'mcp-auth';
// Fetching OAuth server configuration
// This will fetch 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 will fetch 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 or does not match the MCP specification.