Skip to content

Commit 42b3359

Browse files
jonathanhefnerclaudefelixweinberger
authored
Add code reference links and backticks to JSDoc comments (modelcontextprotocol#1484)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Felix Weinberger <3823880+felixweinberger@users.noreply.github.com>
1 parent 91f6a27 commit 42b3359

File tree

38 files changed

+400
-400
lines changed

38 files changed

+400
-400
lines changed

packages/client/src/client/auth.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export type AddClientAuthentication = (
4444
export interface OAuthClientProvider {
4545
/**
4646
* The URL to redirect the user agent to after authorization.
47-
* Return undefined for non-interactive flows that don't require user interaction
48-
* (e.g., client_credentials, jwt-bearer).
47+
* Return `undefined` for non-interactive flows that don't require user interaction
48+
* (e.g., `client_credentials`, `jwt-bearer`).
4949
*/
5050
get redirectUrl(): string | URL | undefined;
5151

@@ -74,7 +74,7 @@ export interface OAuthClientProvider {
7474
/**
7575
* If implemented, this permits the OAuth client to dynamically register with
7676
* the server. Client information saved this way should later be read via
77-
* `clientInformation()`.
77+
* {@linkcode OAuthClientProvider.clientInformation | clientInformation()}.
7878
*
7979
* This method is not required to be implemented if client information is
8080
* statically known (e.g., pre-registered).
@@ -154,11 +154,11 @@ export interface OAuthClientProvider {
154154
* any grant-specific parameters needed for the token exchange.
155155
*
156156
* If not implemented, the default behavior depends on the flow:
157-
* - For authorization code flow: uses code, code_verifier, and redirect_uri
158-
* - For client_credentials: detected via grant_types in clientMetadata
157+
* - For authorization code flow: uses `code`, `code_verifier`, and `redirect_uri`
158+
* - For `client_credentials`: detected via `grant_types` in {@linkcode OAuthClientProvider.clientMetadata | clientMetadata}
159159
*
160160
* @param scope - Optional scope to request
161-
* @returns Grant type and parameters, or undefined to use default behavior
161+
* @returns Grant type and parameters, or `undefined` to use default behavior
162162
*
163163
* @example
164164
* // For client_credentials grant:
@@ -206,9 +206,9 @@ const AUTHORIZATION_CODE_CHALLENGE_METHOD = 'S256';
206206
* Determines the best client authentication method to use based on server support and client configuration.
207207
*
208208
* Priority order (highest to lowest):
209-
* 1. client_secret_basic (if client secret is available)
210-
* 2. client_secret_post (if client secret is available)
211-
* 3. none (for public clients)
209+
* 1. `client_secret_basic` (if client secret is available)
210+
* 2. `client_secret_post` (if client secret is available)
211+
* 3. `none` (for public clients)
212212
*
213213
* @param clientInformation - OAuth client information containing credentials
214214
* @param supportedMethods - Authentication methods supported by the authorization server
@@ -253,9 +253,9 @@ export function selectClientAuthMethod(clientInformation: OAuthClientInformation
253253
* Applies client authentication to the request based on the specified method.
254254
*
255255
* Implements OAuth 2.1 client authentication methods:
256-
* - client_secret_basic: HTTP Basic authentication (RFC 6749 Section 2.3.1)
257-
* - client_secret_post: Credentials in request body (RFC 6749 Section 2.3.1)
258-
* - none: Public client authentication (RFC 6749 Section 2.1)
256+
* - `client_secret_basic`: HTTP Basic authentication (RFC 6749 Section 2.3.1)
257+
* - `client_secret_post`: Credentials in request body (RFC 6749 Section 2.3.1)
258+
* - `none`: Public client authentication (RFC 6749 Section 2.1)
259259
*
260260
* @param method - The authentication method to use
261261
* @param clientInformation - OAuth client information containing credentials
@@ -323,12 +323,12 @@ function applyPublicAuth(clientId: string, params: URLSearchParams): void {
323323
* Parses an OAuth error response from a string or Response object.
324324
*
325325
* If the input is a standard OAuth2.0 error response, it will be parsed according to the spec
326-
* and an OAuthError will be returned with the appropriate error code.
327-
* If parsing fails, it falls back to a generic ServerError that includes
326+
* and an {@linkcode OAuthError} will be returned with the appropriate error code.
327+
* If parsing fails, it falls back to a generic {@linkcode OAuthErrorCode.ServerError | ServerError} that includes
328328
* the response status (if available) and original content.
329329
*
330330
* @param input - A Response object or string containing the error response
331-
* @returns A Promise that resolves to an OAuthError instance
331+
* @returns A Promise that resolves to an {@linkcode OAuthError} instance
332332
*/
333333
export async function parseErrorResponse(input: Response | string): Promise<OAuthError> {
334334
const statusCode = input instanceof Response ? input.status : undefined;
@@ -526,7 +526,7 @@ async function authInternal(
526526

527527
/**
528528
* SEP-991: URL-based Client IDs
529-
* Validate that the client_id is a valid URL with https scheme
529+
* Validate that the `client_id` is a valid URL with `https` scheme
530530
*/
531531
export function isHttpsUrl(value?: string): boolean {
532532
if (!value) return false;
@@ -564,7 +564,7 @@ export async function selectResourceURL(
564564
}
565565

566566
/**
567-
* Extract resource_metadata, scope, and error from WWW-Authenticate header.
567+
* Extract `resource_metadata`, `scope`, and `error` from `WWW-Authenticate` header.
568568
*/
569569
export function extractWWWAuthenticateParams(res: Response): { resourceMetadataUrl?: URL; scope?: string; error?: string } {
570570
const authenticateHeader = res.headers.get('WWW-Authenticate');
@@ -599,10 +599,10 @@ export function extractWWWAuthenticateParams(res: Response): { resourceMetadataU
599599
}
600600

601601
/**
602-
* Extracts a specific field's value from the WWW-Authenticate header string.
602+
* Extracts a specific field's value from the `WWW-Authenticate` header string.
603603
*
604604
* @param response The HTTP response object containing the headers.
605-
* @param fieldName The name of the field to extract (e.g., "realm", "nonce").
605+
* @param fieldName The name of the field to extract (e.g., `"realm"`, `"nonce"`).
606606
* @returns The field value
607607
*/
608608
function extractFieldFromWwwAuth(response: Response, fieldName: string): string | null {
@@ -626,8 +626,8 @@ function extractFieldFromWwwAuth(response: Response, fieldName: string): string
626626
}
627627

628628
/**
629-
* Extract resource_metadata from response header.
630-
* @deprecated Use `extractWWWAuthenticateParams` instead.
629+
* Extract `resource_metadata` from response header.
630+
* @deprecated Use {@linkcode extractWWWAuthenticateParams} instead.
631631
*/
632632
export function extractResourceMetadataUrl(res: Response): URL | undefined {
633633
const authenticateHeader = res.headers.get('WWW-Authenticate');
@@ -770,7 +770,7 @@ async function discoverMetadataWithFallback(
770770
* If the server returns a 404 for the well-known endpoint, this function will
771771
* return `undefined`. Any other errors will be thrown as exceptions.
772772
*
773-
* @deprecated This function is deprecated in favor of `discoverAuthorizationServerMetadata`.
773+
* @deprecated This function is deprecated in favor of {@linkcode discoverAuthorizationServerMetadata}.
774774
*/
775775
export async function discoverOAuthMetadata(
776776
issuer: string | URL,
@@ -888,7 +888,7 @@ export function buildDiscoveryUrls(authorizationServerUrl: string | URL): { url:
888888
* metadata was not found.
889889
* @param options - Configuration options
890890
* @param options.fetchFn - Optional fetch function for making HTTP requests, defaults to global fetch
891-
* @param options.protocolVersion - MCP protocol version to use, defaults to LATEST_PROTOCOL_VERSION
891+
* @param options.protocolVersion - MCP protocol version to use, defaults to {@linkcode LATEST_PROTOCOL_VERSION}
892892
* @returns Promise resolving to authorization server metadata, or undefined if discovery fails
893893
*/
894894
export async function discoverAuthorizationServerMetadata(
@@ -1016,13 +1016,13 @@ export async function startAuthorization(
10161016
/**
10171017
* Prepares token request parameters for an authorization code exchange.
10181018
*
1019-
* This is the default implementation used by fetchToken when the provider
1020-
* doesn't implement prepareTokenRequest.
1019+
* This is the default implementation used by {@linkcode fetchToken} when the provider
1020+
* doesn't implement {@linkcode OAuthClientProvider.prepareTokenRequest | prepareTokenRequest}.
10211021
*
10221022
* @param authorizationCode - The authorization code received from the authorization endpoint
10231023
* @param codeVerifier - The PKCE code verifier
10241024
* @param redirectUri - The redirect URI used in the authorization request
1025-
* @returns URLSearchParams for the authorization_code grant
1025+
* @returns URLSearchParams for the `authorization_code` grant
10261026
*/
10271027
export function prepareAuthorizationCodeRequest(
10281028
authorizationCode: string,
@@ -1039,7 +1039,7 @@ export function prepareAuthorizationCodeRequest(
10391039

10401040
/**
10411041
* Internal helper to execute a token request with the given parameters.
1042-
* Used by exchangeAuthorization, refreshAuthorization, and fetchToken.
1042+
* Used by {@linkcode exchangeAuthorization}, {@linkcode refreshAuthorization}, and {@linkcode fetchToken}.
10431043
*/
10441044
async function executeTokenRequest(
10451045
authorizationServerUrl: string | URL,
@@ -1157,7 +1157,7 @@ export async function exchangeAuthorization(
11571157
*
11581158
* @param authorizationServerUrl - The authorization server's base URL
11591159
* @param options - Configuration object containing client info, refresh token, etc.
1160-
* @returns Promise resolving to OAuth tokens (preserves original refresh_token if not replaced)
1160+
* @returns Promise resolving to OAuth tokens (preserves original `refresh_token` if not replaced)
11611161
* @throws {Error} When token refresh fails or authentication is invalid
11621162
*/
11631163
export async function refreshAuthorization(
@@ -1197,17 +1197,17 @@ export async function refreshAuthorization(
11971197
}
11981198

11991199
/**
1200-
* Unified token fetching that works with any grant type via provider.prepareTokenRequest().
1200+
* Unified token fetching that works with any grant type via {@linkcode OAuthClientProvider.prepareTokenRequest | prepareTokenRequest()}.
12011201
*
12021202
* This function provides a single entry point for obtaining tokens regardless of the
1203-
* OAuth grant type. The provider's prepareTokenRequest() method determines which grant
1203+
* OAuth grant type. The provider's `prepareTokenRequest()` method determines which grant
12041204
* to use and supplies the grant-specific parameters.
12051205
*
1206-
* @param provider - OAuth client provider that implements prepareTokenRequest()
1206+
* @param provider - OAuth client provider that implements `prepareTokenRequest()`
12071207
* @param authorizationServerUrl - The authorization server's base URL
12081208
* @param options - Configuration for the token request
12091209
* @returns Promise resolving to OAuth tokens
1210-
* @throws {Error} When provider doesn't implement prepareTokenRequest or token fetch fails
1210+
* @throws {Error} When provider doesn't implement `prepareTokenRequest` or token fetch fails
12111211
*
12121212
* @example
12131213
* ```typescript
@@ -1235,7 +1235,7 @@ export async function fetchToken(
12351235
}: {
12361236
metadata?: AuthorizationServerMetadata;
12371237
resource?: URL;
1238-
/** Authorization code for the default authorization_code grant flow */
1238+
/** Authorization code for the default `authorization_code` grant flow */
12391239
authorizationCode?: string;
12401240
fetchFn?: FetchLike;
12411241
} = {}

packages/client/src/client/authExtensions.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* OAuth provider extensions for specialized authentication flows.
33
*
4-
* This module provides ready-to-use OAuthClientProvider implementations
4+
* This module provides ready-to-use {@linkcode OAuthClientProvider} implementations
55
* for common machine-to-machine authentication scenarios.
66
*/
77

@@ -11,7 +11,7 @@ import type { CryptoKey, JWK } from 'jose';
1111
import type { AddClientAuthentication, OAuthClientProvider } from './auth.js';
1212

1313
/**
14-
* Helper to produce a private_key_jwt client authentication function.
14+
* Helper to produce a `private_key_jwt` client authentication function.
1515
*
1616
* @example
1717
* ```typescript
@@ -90,16 +90,16 @@ export function createPrivateKeyJwtAuth(options: {
9090
}
9191

9292
/**
93-
* Options for creating a ClientCredentialsProvider.
93+
* Options for creating a {@linkcode ClientCredentialsProvider}.
9494
*/
9595
export interface ClientCredentialsProviderOptions {
9696
/**
97-
* The client_id for this OAuth client.
97+
* The `client_id` for this OAuth client.
9898
*/
9999
clientId: string;
100100

101101
/**
102-
* The client_secret for client_secret_basic authentication.
102+
* The `client_secret` for `client_secret_basic` authentication.
103103
*/
104104
clientSecret: string;
105105

@@ -110,10 +110,10 @@ export interface ClientCredentialsProviderOptions {
110110
}
111111

112112
/**
113-
* OAuth provider for client_credentials grant with client_secret_basic authentication.
113+
* OAuth provider for `client_credentials` grant with `client_secret_basic` authentication.
114114
*
115115
* This provider is designed for machine-to-machine authentication where
116-
* the client authenticates using a client_id and client_secret.
116+
* the client authenticates using a `client_id` and `client_secret`.
117117
*
118118
* @example
119119
* ```typescript
@@ -189,11 +189,11 @@ export class ClientCredentialsProvider implements OAuthClientProvider {
189189
}
190190

191191
/**
192-
* Options for creating a PrivateKeyJwtProvider.
192+
* Options for creating a {@linkcode PrivateKeyJwtProvider}.
193193
*/
194194
export interface PrivateKeyJwtProviderOptions {
195195
/**
196-
* The client_id for this OAuth client.
196+
* The `client_id` for this OAuth client.
197197
*/
198198
clientId: string;
199199

@@ -220,7 +220,7 @@ export interface PrivateKeyJwtProviderOptions {
220220
}
221221

222222
/**
223-
* OAuth provider for client_credentials grant with private_key_jwt authentication.
223+
* OAuth provider for `client_credentials` grant with `private_key_jwt` authentication.
224224
*
225225
* This provider is designed for machine-to-machine authentication where
226226
* the client authenticates using a signed JWT assertion
@@ -308,19 +308,19 @@ export class PrivateKeyJwtProvider implements OAuthClientProvider {
308308
}
309309

310310
/**
311-
* Options for creating a StaticPrivateKeyJwtProvider.
311+
* Options for creating a {@linkcode StaticPrivateKeyJwtProvider}.
312312
*/
313313
export interface StaticPrivateKeyJwtProviderOptions {
314314
/**
315-
* The client_id for this OAuth client.
315+
* The `client_id` for this OAuth client.
316316
*/
317317
clientId: string;
318318

319319
/**
320320
* A pre-built JWT client assertion to use for authentication.
321321
*
322322
* This token should already contain the appropriate claims
323-
* (iss, sub, aud, exp, etc.) and be signed by the client's key.
323+
* (`iss`, `sub`, `aud`, `exp`, etc.) and be signed by the client's key.
324324
*/
325325
jwtBearerAssertion: string;
326326

@@ -331,9 +331,9 @@ export interface StaticPrivateKeyJwtProviderOptions {
331331
}
332332

333333
/**
334-
* OAuth provider for client_credentials grant with a static private_key_jwt assertion.
334+
* OAuth provider for `client_credentials` grant with a static `private_key_jwt` assertion.
335335
*
336-
* This provider mirrors {@link PrivateKeyJwtProvider} but instead of constructing and
336+
* This provider mirrors {@linkcode PrivateKeyJwtProvider} but instead of constructing and
337337
* signing a JWT on each request, it accepts a pre-built JWT assertion string and
338338
* uses it directly for authentication.
339339
*/

packages/client/src/client/client.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import {
6868
import { ExperimentalClientTasks } from '../experimental/tasks/client.js';
6969

7070
/**
71-
* Elicitation default application helper. Applies defaults to the data based on the schema.
71+
* Elicitation default application helper. Applies defaults to the `data` based on the `schema`.
7272
*
7373
* @param schema - The schema to apply defaults to.
7474
* @param data - The data to apply defaults to.
@@ -153,7 +153,7 @@ export type ClientOptions = ProtocolOptions & {
153153
* The validator is used to validate structured content returned by tools
154154
* against their declared output schemas.
155155
*
156-
* @default DefaultJsonSchemaValidator (AjvJsonSchemaValidator on Node.js, CfWorkerJsonSchemaValidator on Cloudflare Workers)
156+
* @default {@linkcode DefaultJsonSchemaValidator} ({@linkcode index.AjvJsonSchemaValidator | AjvJsonSchemaValidator} on Node.js, {@linkcode index.CfWorkerJsonSchemaValidator | CfWorkerJsonSchemaValidator} on Cloudflare Workers)
157157
*/
158158
jsonSchemaValidator?: jsonSchemaValidator;
159159

@@ -189,7 +189,7 @@ export type ClientOptions = ProtocolOptions & {
189189
/**
190190
* An MCP client on top of a pluggable transport.
191191
*
192-
* The client will automatically begin the initialization flow with the server when connect() is called.
192+
* The client will automatically begin the initialization flow with the server when {@linkcode connect} is called.
193193
*
194194
*/
195195
export class Client extends Protocol<ClientContext> {
@@ -713,9 +713,9 @@ export class Client extends Protocol<ClientContext> {
713713
}
714714

715715
/**
716-
* Calls a tool and waits for the result. Automatically validates structured output if the tool has an outputSchema.
716+
* Calls a tool and waits for the result. Automatically validates structured output if the tool has an `outputSchema`.
717717
*
718-
* For task-based execution with streaming behavior, use client.experimental.tasks.callToolStream() instead.
718+
* For task-based execution with streaming behavior, use {@linkcode ExperimentalClientTasks.callToolStream | client.experimental.tasks.callToolStream()} instead.
719719
*/
720720
async callTool(
721721
params: CallToolRequest['params'],
@@ -780,15 +780,15 @@ export class Client extends Protocol<ClientContext> {
780780

781781
/**
782782
* Check if a tool requires task-based execution.
783-
* Unlike isToolTask which includes 'optional' tools, this only checks for 'required'.
783+
* Unlike {@linkcode isToolTask} which includes `'optional'` tools, this only checks for `'required'`.
784784
*/
785785
private isToolTaskRequired(toolName: string): boolean {
786786
return this._cachedRequiredTaskTools.has(toolName);
787787
}
788788

789789
/**
790790
* Cache validators for tool output schemas.
791-
* Called after listTools() to pre-compile validators for better performance.
791+
* Called after {@linkcode listTools | listTools()} to pre-compile validators for better performance.
792792
*/
793793
private cacheToolMetadata(tools: Tool[]): void {
794794
this._cachedToolOutputValidators.clear();

0 commit comments

Comments
 (0)