MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / probe

Function probe

packages/core/sdk/src/oauth-service.ts:2531–2576  ·  view source on GitHub ↗
(
    input: OAuthProbeInput,
  )

Source from the content-addressed store, hash-verified

2529 // probe — RFC 8414 / OIDC discovery for onboarding pre-fill.
2530 // -----------------------------------------------------------------------
2531 const probe = (
2532 input: OAuthProbeInput,
2533 ): Effect.Effect<OAuthProbeResult, OAuthProbeError | StorageFailure> =>
2534 Effect.gen(function* () {
2535 const options = { endpointUrlPolicy: deps.endpointUrlPolicy };
2536 // Try protected-resource metadata first (RFC 9728), then the AS issuer.
2537 const resource = yield* discoverProtectedResourceMetadata(input.url, options).pipe(
2538 Effect.catch(() => Effect.succeed(null)),
2539 );
2540 // EXPLICIT discovery order: when the protected-resource metadata advertises
2541 // an authorization server, probe that; otherwise probe the input endpoint
2542 // itself as a last resort. This is a documented probe order, not a silent
2543 // guess — a probe that finds no AS metadata fails loudly below.
2544 const issuerCandidate = resource?.metadata.authorization_servers?.[0] ?? input.url;
2545 const as = yield* discoverAuthorizationServerMetadata(issuerCandidate, options).pipe(
2546 Effect.mapError(
2547 (cause) =>
2548 new OAuthProbeError({
2549 // oxlint-disable-next-line executor/no-unknown-error-message -- boundary: OAuthDiscoveryError carries a typed `message` field
2550 message: `OAuth discovery failed: ${cause.message}`,
2551 }),
2552 ),
2553 );
2554 if (!as) {
2555 return yield* new OAuthProbeError({
2556 message: `No OAuth authorization-server metadata found at ${input.url}`,
2557 });
2558 }
2559 return {
2560 issuer: as.metadata.issuer,
2561 authorizationUrl: as.metadata.authorization_endpoint,
2562 tokenUrl: as.metadata.token_endpoint,
2563 resource: resource?.metadata.resource ?? null,
2564 // Prefer the resource's own RFC 9728 scopes (authoritative, even when
2565 // empty); fall back to the authorization server's list only when PRM is
2566 // silent. For a spec-compliant MCP server (one that publishes PRM) this
2567 // matches what `oauth.start` discovers. The AS fallback is a best-effort
2568 // hint for the registration form on servers that omit PRM — where
2569 // `oauth.start` requests none — so the two can differ for those.
2570 scopesSupported: resource?.metadata.scopes_supported ?? as.metadata.scopes_supported,
2571 registrationEndpoint: as.metadata.registration_endpoint ?? null,
2572 tokenEndpointAuthMethodsSupported: as.metadata.token_endpoint_auth_methods_supported,
2573 clientIdMetadataDocumentSupported:
2574 as.metadata.client_id_metadata_document_supported === true,
2575 } satisfies OAuthProbeResult;
2576 }).pipe(Effect.provide(httpClientLayer));
2577
2578 return {
2579 createClient,

Callers

nothing calls this directly

Tested by

no test coverage detected