---
title: "Dependencies"
description: "Context helpers for accessing authentication in tools API Documentation"
icon: "code"
github: "https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/server/auth/dependencies.py"
---

import {RandomGradientBackground} from "/snippets/gradient.jsx"

<Callout type="info" title="Source Code">
View the source code for this module on GitHub: <a href='https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/server/auth/dependencies.py' target='_blank' rel='noopener noreferrer'>https://github.com/mcp-use/mcp-use/blob/main/libraries/python/mcp_use/server/auth/dependencies.py</a>
</Callout>

Context helpers for accessing authentication in tools.


## get_access_token
<Card type="info">
### `function` get_access_token

Get the current authenticated user's access token.

    Returns None if the request is not authenticated.

    Example:
        ```python
        from mcp_use.server.auth import get_access_token

        @server.tool()
        def whoami() -> str:
            token = get_access_token()
            if not token:
                return "Not authenticated"
            return f"Hello \{token.claims.get('email')\}"
        ```

```python
from mcp_use.server.auth.dependencies import get_access_token
```

**Returns**
><ResponseField name="returns" type="AccessToken | None" />

**Signature**
```python wrap
def get_access_token():
```

</Card>


## require_auth
<Card type="info">
### `function` require_auth

Get the access token or raise AuthenticationError if not authenticated.

    Example:
        ```python
        from mcp_use.server.auth import require_auth

        @server.tool()
        def admin_action() -> str:
            token = require_auth()  # Raises if not authenticated
            if "admin" not in token.scopes:
                return "Admin scope required"
            return "Admin action performed"
        ```

```python
from mcp_use.server.auth.dependencies import require_auth
```

**Returns**
><ResponseField name="returns" type="AccessToken" />

**Signature**
```python wrap
def require_auth():
```

</Card>


## set_access_token
<Card type="info">
### `function` set_access_token

Set the current access token (called by AuthMiddleware).

```python
from mcp_use.server.auth.dependencies import set_access_token
```

**Parameters**
><ParamField body="token" type="AccessToken | None" required="True" >   Parameter value </ParamField>

**Signature**
```python wrap
def set_access_token(token: AccessToken | None):
```

</Card>
