FastestMCP.Middleware (fastest_mcp v0.1.2)

Copy Markdown View Source

Built-in middleware constructors.

Middleware in FastestMCP wraps the shared operation pipeline used by local dispatch, HTTP, and stdio. This module is the public constructor surface for the built-in middleware implementations under FastestMCP.Middleware.*.

What Middleware Can Do

Middleware can:

  • observe or log requests
  • enforce limits
  • rewrite metadata
  • cache results
  • inject synthetic tools
  • catch and normalize failures

Usage

Add middleware while building a server:

server =
  FastestMCP.server("docs")
  |> FastestMCP.add_middleware(FastestMCP.Middleware.logging())
  |> FastestMCP.add_middleware(FastestMCP.Middleware.error_handling())

Each function in this module returns the concrete middleware object expected by FastestMCP.add_middleware/2.

Summary

Functions

Builds middleware that expands local $ref pointers in JSON Schemas.

Builds detailed-timing middleware with per-operation labels.

Builds error-handling middleware with logging and counters.

Builds request-logging middleware.

Runs a ping request.

Builds middleware that exposes prompts as synthetic tools.

Builds token-bucket rate-limiting middleware.

Builds the synthetic resource-tool set used by tool injection.

Builds response-caching middleware.

Builds middleware that truncates oversized responses.

Builds retry middleware for transient failures.

Builds sliding-window rate-limiting middleware.

Builds request-logging middleware with structured output enabled.

Builds timing middleware that records total request duration.

Builds middleware that injects synthetic tools into the runtime.

Functions

dereference_refs(opts \\ [])

Builds middleware that expands local $ref pointers in JSON Schemas.

detailed_timing(opts \\ [])

Builds detailed-timing middleware with per-operation labels.

error_handling(opts \\ [])

Builds error-handling middleware with logging and counters.

logging(opts \\ [])

Builds request-logging middleware.

ping(opts \\ [])

Runs a ping request.

prompt_tools(opts \\ [])

Builds middleware that exposes prompts as synthetic tools.

rate_limiting(opts \\ [])

Builds token-bucket rate-limiting middleware.

resource_tools(opts \\ [])

Builds the synthetic resource-tool set used by tool injection.

response_caching(opts \\ [])

Builds response-caching middleware.

response_limiting(opts \\ [])

Builds middleware that truncates oversized responses.

retry(opts \\ [])

Builds retry middleware for transient failures.

sliding_window_rate_limiting(opts)

Builds sliding-window rate-limiting middleware.

structured_logging(opts \\ [])

Builds request-logging middleware with structured output enabled.

timing(opts \\ [])

Builds timing middleware that records total request duration.

tool_injection(tools, opts \\ [])

Builds middleware that injects synthetic tools into the runtime.