Skip to content

@codesoul-co/hypha-mcp / oauth

Using this module

Use the Oauth module for using the public contracts and operations for this capability boundary. It exports 1 class, 2 functions, 5 interfaces.

Import from the package entrypoint

ts
import {
  MCPOAuth21Client,
  mcpProtectedResourceMetadataUrlFromChallenge,
  redactMCPOAuthSecrets,
} from '@codesoul-co/hypha-mcp';

import type {
  MCPAuthorizationServerMetadata,
  MCPOAuth21ClientOptions,
  MCPOAuthAuthorizationRequest,
  MCPOAuthTokenSet,
  MCPProtectedResourceMetadata,
} from '@codesoul-co/hypha-mcp';

Usage patterns

  • Use the 5 type/interface exports as static contracts in application code, adapters, or tests. Import them with import type; they do not exist at runtime.
  • The module exposes 1 class as constructable runtime implementations. Each symbol entry lists its constructor and public methods.
  • The module exposes 2 functions as direct operation entrypoints. Every overload, required/optional parameter, and return type is documented below.

Public exports

SymbolKindSignatureDescription
MCPOAuth21Clientclassnew MCPOAuth21Client(options: MCPOAuth21ClientOptions): MCPOAuth21ClientMCPO Auth21 Client class with 7 public constructor or member entries; its exact declarations are listed below.
mcpProtectedResourceMetadataUrlFromChallengefunctionmcpProtectedResourceMetadataUrlFromChallenge(wwwAuthenticate: string | null | undefined): string | undefinedExtracts RFC 9728 metadata discovery from an MCP Bearer challenge.
redactMCPOAuthSecretsfunctionredactMCPOAuthSecrets<T>(value: T): TRedact MCPO Auth Secrets function with 1 public call signature; parameters and return types are listed below.
MCPAuthorizationServerMetadatainterfaceinterface MCPAuthorizationServerMetadataMCP Authorization Server Metadata interface with 5 public fields or methods.
MCPOAuth21ClientOptionsinterfaceinterface MCPOAuth21ClientOptionsMCPO Auth21 Client Options interface with 10 public fields or methods.
MCPOAuthAuthorizationRequestinterfaceinterface MCPOAuthAuthorizationRequestMCPO Auth Authorization Request interface with 3 public fields or methods.
MCPOAuthTokenSetinterfaceinterface MCPOAuthTokenSetMCPO Auth Token Set interface with 6 public fields or methods.
MCPProtectedResourceMetadatainterfaceinterface MCPProtectedResourceMetadataMCP Protected Resource Metadata interface with 3 public fields or methods.

MCPOAuth21Client

MCPO Auth21 Client class with 7 public constructor or member entries; its exact declarations are listed below.

  • Kind: class
  • Import: import { MCPOAuth21Client } from '@codesoul-co/hypha-mcp';
  • Source module: oauth

Declaration

text
export declare class MCPOAuth21Client {
    constructor(options: MCPOAuth21ClientOptions);
    discover(): Promise<{
            protectedResource: MCPProtectedResourceMetadata;
            authorizationServer: MCPAuthorizationServerMetadata;
        }>;
    createAuthorizationRequest(state?: string): Promise<MCPOAuthAuthorizationRequest>;
    exchangeAuthorizationCode(input: {
            code: string;
            codeVerifier: string;
            state: string;
            expectedState: string;
        }): Promise<MCPOAuthTokenSet>;
    refresh(): Promise<MCPOAuthTokenSet>;
    authorizationHeader(minimumValidityMs?: number): Promise<string>;
    clear(): void;
}

Public members

MemberKindSignatureDescription
authorizationHeadermethodauthorizationHeader(minimumValidityMs?: number): Promise<string>Public method; parameters and return type are shown in the signature.
clearmethodclear(): voidPublic method; parameters and return type are shown in the signature.
constructorconstructor(options: MCPOAuth21ClientOptions): MCPOAuth21ClientCreates an instance of this class.
createAuthorizationRequestmethodcreateAuthorizationRequest(state?: string): Promise<MCPOAuthAuthorizationRequest>Public method; parameters and return type are shown in the signature.
discovermethoddiscover(): Promise<{ protectedResource: MCPProtectedResourceMetadata; authorizationServer: MCPAuthorizationServerMetadata; }>Public method; parameters and return type are shown in the signature.
exchangeAuthorizationCodemethodexchangeAuthorizationCode(input: { code: string; codeVerifier: string; state: string; expectedState: string; }): Promise<MCPOAuthTokenSet>Public method; parameters and return type are shown in the signature.
refreshmethodrefresh(): Promise<MCPOAuthTokenSet>Public method; parameters and return type are shown in the signature.

mcpProtectedResourceMetadataUrlFromChallenge

Extracts RFC 9728 metadata discovery from an MCP Bearer challenge.

  • Kind: function
  • Import: import { mcpProtectedResourceMetadataUrlFromChallenge } from '@codesoul-co/hypha-mcp';
  • Source module: oauth

Declaration

text
export declare function mcpProtectedResourceMetadataUrlFromChallenge(wwwAuthenticate: string | null | undefined): string | undefined;

Call signature

text
mcpProtectedResourceMetadataUrlFromChallenge(wwwAuthenticate: string | null | undefined): string | undefined

Extracts RFC 9728 metadata discovery from an MCP Bearer challenge.

Parameters

ParameterTypeRequiredDescription
wwwAuthenticatestringYesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: string
  • Description: The return contract is defined by the type shown above.

redactMCPOAuthSecrets

Redact MCPO Auth Secrets function with 1 public call signature; parameters and return types are listed below.

  • Kind: function
  • Import: import { redactMCPOAuthSecrets } from '@codesoul-co/hypha-mcp';
  • Source module: oauth

Declaration

text
export declare function redactMCPOAuthSecrets<T>(value: T): T;

Call signature

text
redactMCPOAuthSecrets<T>(value: T): T

Parameters

ParameterTypeRequiredDescription
valueTYesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: T
  • Description: The return contract is defined by the type shown above.

MCPAuthorizationServerMetadata

MCP Authorization Server Metadata interface with 5 public fields or methods.

  • Kind: interface
  • Import: import type { MCPAuthorizationServerMetadata } from '@codesoul-co/hypha-mcp';
  • Source module: oauth

Declaration

text
export interface MCPAuthorizationServerMetadata {
    issuer: string;
    authorization_endpoint: string;
    token_endpoint: string;
    code_challenge_methods_supported: string[];
    grant_types_supported?: string[];
}

Contract members

MemberKindSignatureDescription
authorization_endpointpropertyauthorization_endpoint: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
code_challenge_methods_supportedpropertycode_challenge_methods_supported: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
grant_types_supportedpropertygrant_types_supported?: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
issuerpropertyissuer: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
token_endpointpropertytoken_endpoint: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

MCPOAuth21ClientOptions

MCPO Auth21 Client Options interface with 10 public fields or methods.

  • Kind: interface
  • Import: import type { MCPOAuth21ClientOptions } from '@codesoul-co/hypha-mcp';
  • Source module: oauth

Declaration

text
export interface MCPOAuth21ClientOptions {
    resource: string;
    clientId: string;
    redirectUri: string;
    fetch?: typeof fetch;
    metadataUrl?: string;
    /** Selects one server advertised by RFC 9728 metadata; defaults to the first. */
    authorizationServer?: string;
    timeoutMs?: number;
    now?: () => number;
    randomBytes?: (size: number) => Uint8Array;
    /**
     * Intended only for an in-process acceptance server. Production callers
     * must leave this disabled so OAuth metadata and token traffic require TLS.
     */
    allowInsecureLoopbackForAcceptance?: boolean;
}

Contract members

MemberKindSignatureDescription
allowInsecureLoopbackForAcceptancepropertyallowInsecureLoopbackForAcceptance?: booleanIntended only for an in-process acceptance server. Production callers must leave this disabled so OAuth metadata and token traffic require TLS.
authorizationServerpropertyauthorizationServer?: stringSelects one server advertised by RFC 9728 metadata; defaults to the first.
clientIdpropertyclientId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
fetchmethodfetch?(input: RequestInfo | URL, init?: RequestInit): Promise<Response> | fetch?(input: string | URL | Request, init?: RequestInit): Promise<Response>Public method; parameters and return type are shown in the signature.
metadataUrlpropertymetadataUrl?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
nowmethodnow?(): numberPublic method; parameters and return type are shown in the signature.
randomBytesmethodrandomBytes?(size: number): Uint8ArrayPublic method; parameters and return type are shown in the signature.
redirectUripropertyredirectUri: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
resourcepropertyresource: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
timeoutMspropertytimeoutMs?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.

MCPOAuthAuthorizationRequest

MCPO Auth Authorization Request interface with 3 public fields or methods.

  • Kind: interface
  • Import: import type { MCPOAuthAuthorizationRequest } from '@codesoul-co/hypha-mcp';
  • Source module: oauth

Declaration

text
export interface MCPOAuthAuthorizationRequest {
    url: string;
    state: string;
    codeVerifier: string;
}

Contract members

MemberKindSignatureDescription
codeVerifierpropertycodeVerifier: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
statepropertystate: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
urlpropertyurl: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

MCPOAuthTokenSet

MCPO Auth Token Set interface with 6 public fields or methods.

  • Kind: interface
  • Import: import type { MCPOAuthTokenSet } from '@codesoul-co/hypha-mcp';
  • Source module: oauth

Declaration

text
export interface MCPOAuthTokenSet {
    accessToken: string;
    refreshToken?: string;
    tokenType: 'Bearer';
    expiresAt: number;
    scope?: string;
    resource: string;
}

Contract members

MemberKindSignatureDescription
accessTokenpropertyaccessToken: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
expiresAtpropertyexpiresAt: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
refreshTokenpropertyrefreshToken?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
resourcepropertyresource: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
scopepropertyscope?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
tokenTypepropertytokenType: "Bearer"Public property; its type, readonly modifier and optionality are shown in the signature.

MCPProtectedResourceMetadata

MCP Protected Resource Metadata interface with 3 public fields or methods.

  • Kind: interface
  • Import: import type { MCPProtectedResourceMetadata } from '@codesoul-co/hypha-mcp';
  • Source module: oauth

Declaration

text
export interface MCPProtectedResourceMetadata {
    resource: string;
    authorization_servers: string[];
    bearer_methods_supported?: string[];
}

Contract members

MemberKindSignatureDescription
authorization_serverspropertyauthorization_servers: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
bearer_methods_supportedpropertybearer_methods_supported?: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
resourcepropertyresource: stringPublic property; its type, readonly modifier and optionality are shown in the signature.