mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-09 15:19:10 +02:00
* Update repository references from jlowin/fastmcp to prefecthq/fastmcp * Retrigger CI after repo transfer * chore: Update SDK documentation * Only run deep triage on bug issues for jlowin --------- Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
60 lines
2 KiB
Text
60 lines
2 KiB
Text
---
|
|
title: error_handling
|
|
sidebarTitle: error_handling
|
|
---
|
|
|
|
# `fastmcp.server.middleware.error_handling`
|
|
|
|
|
|
Error handling middleware for consistent error responses and tracking.
|
|
|
|
## Classes
|
|
|
|
### `ErrorHandlingMiddleware` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/middleware/error_handling.py#L18" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
|
|
Middleware that provides consistent error handling and logging.
|
|
|
|
Catches exceptions, logs them appropriately, and converts them to
|
|
proper MCP error responses. Also tracks error patterns for monitoring.
|
|
|
|
|
|
**Methods:**
|
|
|
|
#### `on_message` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/middleware/error_handling.py#L120" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
on_message(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
|
```
|
|
|
|
Handle errors for all messages.
|
|
|
|
|
|
#### `get_error_stats` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/middleware/error_handling.py#L131" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
get_error_stats(self) -> dict[str, int]
|
|
```
|
|
|
|
Get error statistics for monitoring.
|
|
|
|
|
|
### `RetryMiddleware` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/middleware/error_handling.py#L136" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
|
|
Middleware that implements automatic retry logic for failed requests.
|
|
|
|
Retries requests that fail with transient errors, using exponential
|
|
backoff to avoid overwhelming the server or external dependencies.
|
|
|
|
|
|
**Methods:**
|
|
|
|
#### `on_request` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/middleware/error_handling.py#L192" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
on_request(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
|
```
|
|
|
|
Implement retry logic for requests.
|
|
|