mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-09 15:19:10 +02:00
105 lines
3.6 KiB
Text
105 lines
3.6 KiB
Text
---
|
|
title: timing
|
|
sidebarTitle: timing
|
|
---
|
|
|
|
# `fastmcp.server.middleware.timing`
|
|
|
|
|
|
Timing middleware for measuring and logging request performance.
|
|
|
|
## Classes
|
|
|
|
### `TimingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L10" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
|
|
Middleware that logs the execution time of requests.
|
|
|
|
Only measures and logs timing for request messages (not notifications).
|
|
Provides insights into performance characteristics of your MCP server.
|
|
|
|
|
|
**Methods:**
|
|
|
|
#### `on_request` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L39" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
on_request(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
|
```
|
|
|
|
Time request execution and log the results.
|
|
|
|
|
|
### `DetailedTimingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L60" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
|
|
Enhanced timing middleware with per-operation breakdowns.
|
|
|
|
Provides detailed timing information for different types of MCP operations,
|
|
allowing you to identify performance bottlenecks in specific operations.
|
|
|
|
|
|
**Methods:**
|
|
|
|
#### `on_call_tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L111" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
on_call_tool(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
|
```
|
|
|
|
Time tool execution.
|
|
|
|
|
|
#### `on_read_resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L118" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
on_read_resource(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
|
```
|
|
|
|
Time resource reading.
|
|
|
|
|
|
#### `on_get_prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L127" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
on_get_prompt(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
|
```
|
|
|
|
Time prompt retrieval.
|
|
|
|
|
|
#### `on_list_tools` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L134" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
on_list_tools(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
|
```
|
|
|
|
Time tool listing.
|
|
|
|
|
|
#### `on_list_resources` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L140" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
on_list_resources(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
|
```
|
|
|
|
Time resource listing.
|
|
|
|
|
|
#### `on_list_resource_templates` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L146" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
on_list_resource_templates(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
|
```
|
|
|
|
Time resource template listing.
|
|
|
|
|
|
#### `on_list_prompts` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/timing.py#L152" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
on_list_prompts(self, context: MiddlewareContext, call_next: CallNext) -> Any
|
|
```
|
|
|
|
Time prompt listing.
|
|
|