Skip to content

ErrorHandlingMiddleware retains one error-stat key per unsupported method #5536

Description

@mikamikasuki

What happened?

When installed, ErrorHandlingMiddleware records failures under keys that include the JSON-RPC method name and keeps those counters in an in-memory dictionary for the middleware's lifetime. Unsupported methods reach the error handler, so requests with distinct method names create distinct retained keys.

In a local in-process reproduction, 500 requests with different unsupported method names each returned the expected method-not-found error, while get_error_stats() retained 500 separate keys. The retained state therefore grows with the number of distinct failing method strings. This applies only when ErrorHandlingMiddleware is installed; the default configuration is unaffected.

Could unknown method names be aggregated or the statistics map be bounded?

Example Code

Version Information

- FastMCP main: `5baeacfe20eca735cb949564b4915f93a622b916`
- Python: 3.12.15
- OS: macOS 15.0.1 arm64

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.serverRelated to FastMCP server implementation or server-side functionality.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions