mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-11 16:19:10 +02:00
Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
54 lines
1.9 KiB
Text
54 lines
1.9 KiB
Text
---
|
|
title: dependencies
|
|
sidebarTitle: dependencies
|
|
---
|
|
|
|
# `fastmcp.server.dependencies`
|
|
|
|
## Functions
|
|
|
|
### `get_context` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/dependencies.py#L34" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
get_context() -> Context
|
|
```
|
|
|
|
### `get_http_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/dependencies.py#L46" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
get_http_request() -> Request
|
|
```
|
|
|
|
### `get_http_headers` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/dependencies.py#L62" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
get_http_headers(include_all: bool = False) -> dict[str, str]
|
|
```
|
|
|
|
|
|
Extract headers from the current HTTP request if available.
|
|
|
|
Never raises an exception, even if there is no active HTTP request (in which case
|
|
an empty dict is returned).
|
|
|
|
By default, strips problematic headers like `content-length` that cause issues if forwarded to downstream clients.
|
|
If `include_all` is True, all headers are returned.
|
|
|
|
|
|
### `get_access_token` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/dependencies.py#L111" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
get_access_token() -> AccessToken | None
|
|
```
|
|
|
|
|
|
Get the FastMCP access token from the current context.
|
|
|
|
This function first tries to get the token from the current HTTP request's scope,
|
|
which is more reliable for long-lived connections where the SDK's auth_context_var
|
|
may become stale after token refresh. Falls back to the SDK's context var if no
|
|
request is available.
|
|
|
|
**Returns:**
|
|
- The access token if an authenticated user is available, None otherwise.
|
|
|