Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
05967b7
1
Parent(s): 5800457
Remove production-ready language from middleware docs
Browse files
docs/servers/middleware.mdx
CHANGED
|
@@ -331,11 +331,11 @@ When a client calls "child_tool", the request will flow through the parent's aut
|
|
| 331 |
|
| 332 |
## Built-in Middleware Examples
|
| 333 |
|
| 334 |
-
FastMCP includes several
|
| 335 |
|
| 336 |
### Timing Middleware
|
| 337 |
|
| 338 |
-
Performance monitoring is essential for understanding your server's behavior and identifying bottlenecks. FastMCP includes
|
| 339 |
|
| 340 |
Here's an example of how it works:
|
| 341 |
|
|
@@ -358,7 +358,7 @@ class SimpleTimingMiddleware(Middleware):
|
|
| 358 |
raise
|
| 359 |
```
|
| 360 |
|
| 361 |
-
To use the full
|
| 362 |
|
| 363 |
```python
|
| 364 |
from fastmcp.server.middleware.timing import (
|
|
@@ -397,7 +397,7 @@ class SimpleLoggingMiddleware(Middleware):
|
|
| 397 |
raise
|
| 398 |
```
|
| 399 |
|
| 400 |
-
To use the full
|
| 401 |
|
| 402 |
```python
|
| 403 |
from fastmcp.server.middleware.logging import (
|
|
@@ -415,7 +415,7 @@ mcp.add_middleware(LoggingMiddleware(
|
|
| 415 |
mcp.add_middleware(StructuredLoggingMiddleware(include_payloads=True))
|
| 416 |
```
|
| 417 |
|
| 418 |
-
The
|
| 419 |
|
| 420 |
### Rate Limiting Middleware
|
| 421 |
|
|
@@ -453,7 +453,7 @@ class SimpleRateLimitMiddleware(Middleware):
|
|
| 453 |
return await call_next(context)
|
| 454 |
```
|
| 455 |
|
| 456 |
-
To use the full
|
| 457 |
|
| 458 |
```python
|
| 459 |
from fastmcp.server.middleware.rate_limiting import (
|
|
@@ -474,7 +474,7 @@ mcp.add_middleware(SlidingWindowRateLimitingMiddleware(
|
|
| 474 |
))
|
| 475 |
```
|
| 476 |
|
| 477 |
-
The
|
| 478 |
|
| 479 |
### Error Handling Middleware
|
| 480 |
|
|
@@ -503,7 +503,7 @@ class SimpleErrorHandlingMiddleware(Middleware):
|
|
| 503 |
raise
|
| 504 |
```
|
| 505 |
|
| 506 |
-
To use the full
|
| 507 |
|
| 508 |
```python
|
| 509 |
from fastmcp.server.middleware.error_handling import (
|
|
@@ -525,7 +525,7 @@ mcp.add_middleware(RetryMiddleware(
|
|
| 525 |
))
|
| 526 |
```
|
| 527 |
|
| 528 |
-
The
|
| 529 |
|
| 530 |
### Combining Middleware
|
| 531 |
|
|
|
|
| 331 |
|
| 332 |
## Built-in Middleware Examples
|
| 333 |
|
| 334 |
+
FastMCP includes several middleware implementations that demonstrate best practices and provide immediately useful functionality. Let's explore how each type works by building simplified versions, then see how to use the full implementations.
|
| 335 |
|
| 336 |
### Timing Middleware
|
| 337 |
|
| 338 |
+
Performance monitoring is essential for understanding your server's behavior and identifying bottlenecks. FastMCP includes timing middleware at `fastmcp.server.middleware.timing`.
|
| 339 |
|
| 340 |
Here's an example of how it works:
|
| 341 |
|
|
|
|
| 358 |
raise
|
| 359 |
```
|
| 360 |
|
| 361 |
+
To use the full version with proper logging and configuration:
|
| 362 |
|
| 363 |
```python
|
| 364 |
from fastmcp.server.middleware.timing import (
|
|
|
|
| 397 |
raise
|
| 398 |
```
|
| 399 |
|
| 400 |
+
To use the full versions with advanced features:
|
| 401 |
|
| 402 |
```python
|
| 403 |
from fastmcp.server.middleware.logging import (
|
|
|
|
| 415 |
mcp.add_middleware(StructuredLoggingMiddleware(include_payloads=True))
|
| 416 |
```
|
| 417 |
|
| 418 |
+
The built-in versions include payload logging, structured JSON output, custom logger support, payload size limits, and operation-specific hooks for granular control.
|
| 419 |
|
| 420 |
### Rate Limiting Middleware
|
| 421 |
|
|
|
|
| 453 |
return await call_next(context)
|
| 454 |
```
|
| 455 |
|
| 456 |
+
To use the full versions with advanced algorithms:
|
| 457 |
|
| 458 |
```python
|
| 459 |
from fastmcp.server.middleware.rate_limiting import (
|
|
|
|
| 474 |
))
|
| 475 |
```
|
| 476 |
|
| 477 |
+
The built-in versions include token bucket algorithms, per-client identification, global rate limiting, and async-safe implementations with configurable client identification functions.
|
| 478 |
|
| 479 |
### Error Handling Middleware
|
| 480 |
|
|
|
|
| 503 |
raise
|
| 504 |
```
|
| 505 |
|
| 506 |
+
To use the full versions with advanced features:
|
| 507 |
|
| 508 |
```python
|
| 509 |
from fastmcp.server.middleware.error_handling import (
|
|
|
|
| 525 |
))
|
| 526 |
```
|
| 527 |
|
| 528 |
+
The built-in versions include error transformation, custom callbacks, configurable retry logic, and proper MCP error formatting.
|
| 529 |
|
| 530 |
### Combining Middleware
|
| 531 |
|