MCPcopy Index your code
hub / github.com/modelcontextprotocol/typescript-sdk / registerClient

Function registerClient

src/client/auth.ts:1436–1478  ·  view source on GitHub ↗
(
    authorizationServerUrl: string | URL,
    {
        metadata,
        clientMetadata,
        scope,
        fetchFn
    }: {
        metadata?: AuthorizationServerMetadata;
        clientMetadata: OAuthClientMetadata;
        scope?: string;
        fetchFn?: FetchLike;
    }
)

Source from the content-addressed store, hash-verified

1434 * consistently across both DCR and the subsequent authorization request.
1435 */
1436export async function registerClient(
1437 authorizationServerUrl: string | URL,
1438 {
1439 metadata,
1440 clientMetadata,
1441 scope,
1442 fetchFn
1443 }: {
1444 metadata?: AuthorizationServerMetadata;
1445 clientMetadata: OAuthClientMetadata;
1446 scope?: string;
1447 fetchFn?: FetchLike;
1448 }
1449): Promise<OAuthClientInformationFull> {
1450 let registrationUrl: URL;
1451
1452 if (metadata) {
1453 if (!metadata.registration_endpoint) {
1454 throw new Error('Incompatible auth server: does not support dynamic client registration');
1455 }
1456
1457 registrationUrl = new URL(metadata.registration_endpoint);
1458 } else {
1459 registrationUrl = new URL('/register', authorizationServerUrl);
1460 }
1461
1462 const response = await (fetchFn ?? fetch)(registrationUrl, {
1463 method: 'POST',
1464 headers: {
1465 'Content-Type': 'application/json'
1466 },
1467 body: JSON.stringify({
1468 ...clientMetadata,
1469 ...(scope !== undefined ? { scope } : {})
1470 })
1471 });
1472
1473 if (!response.ok) {
1474 throw await parseErrorResponse(response);
1475 }
1476
1477 return OAuthClientInformationFullSchema.parse(await response.json());
1478}

Callers 1

authInternalFunction · 0.70

Calls 2

parseErrorResponseFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…