# find_oauth_challenge

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/mcp_auth/find_oauth_challenge)

Return the `resource_metadata` URL of a 401 OAuth challenge in `exc`.

Per the MCP authorization spec (RFC 9728), a server requiring OAuth
answers an unauthenticated request with HTTP 401 plus a Bearer
`WWW-Authenticate` challenge pointing at its protected-resource metadata.
The MCP client surfaces that as an `httpx.HTTPStatusError`. Walks
`exceptions` (for `ExceptionGroup`), then `__cause__`/`__context__`,
tracking visited nodes to terminate on cyclic chains.

## Signature

```python
find_oauth_challenge(
    exc: BaseException,
) -> str | None
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `exc` | `BaseException` | Yes | Root exception to inspect. |

## Returns

`str | None`

The `resource_metadata` URL when a 401 response carrying a Bearer
challenge is found, else `None`.

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/e14e0adcbe78565ed3650e7f24b2a775d5437d25/libs/code/deepagents_code/mcp_auth.py#L2048)