mirror of
https://github.com/mcp-use/mcp-use.git
synced 2026-09-14 18:06:01 +08:00
ad42b4bb3e
The searchable: false approach on the API Reference tab was inert on visible tabs. Switch to per-page noindex: true frontmatter, which keeps pages in the sidebar but excludes them from search indexing (search engines, internal docs search, and AI context) so generic queries like "CLI" surface curated guides instead of the generated reference. Applied to all 73 existing reference pages and emitted by the generator on every regeneration. Closes MCP-2398
105 lines
2.5 KiB
Plaintext
105 lines
2.5 KiB
Plaintext
---
|
|
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"
|
|
noindex: true
|
|
---
|
|
|
|
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>
|