MCPcopy
hub / github.com/codeaashu/claude-code / wrapFetchWithStepUpDetection

Function wrapFetchWithStepUpDetection

src/services/mcp/auth.ts:1354–1374  ·  view source on GitHub ↗
(
  baseFetch: FetchLike,
  provider: ClaudeAuthProvider,
)

Source from the content-addressed store, hash-verified

1352 * to the PKCE flow. See github.com/anthropics/claude-code/issues/28258.
1353 */
1354export function wrapFetchWithStepUpDetection(
1355 baseFetch: FetchLike,
1356 provider: ClaudeAuthProvider,
1357): FetchLike {
1358 return async (url, init) => {
1359 const response = await baseFetch(url, init)
1360 if (response.status === 403) {
1361 const wwwAuth = response.headers.get('WWW-Authenticate')
1362 if (wwwAuth?.includes('insufficient_scope')) {
1363 // Match both quoted and unquoted values (RFC 6750 §3 allows either).
1364 // Same pattern as the SDK's extractFieldFromWwwAuth.
1365 const match = wwwAuth.match(/scope=(?:"([^"]+)"|([^\s,]+))/)
1366 const scope = match?.[1] ?? match?.[2]
1367 if (scope) {
1368 provider.markStepUpPending(scope)
1369 }
1370 }
1371 }
1372 return response
1373 }
1374}
1375
1376export class ClaudeAuthProvider implements OAuthClientProvider {
1377 private serverName: string

Callers 1

client.tsFile · 0.85

Calls 2

markStepUpPendingMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected