Resolved

MiddlewareContext object has no attribute params error in FastMCP 2.0

Python
API
Middleware
FastMCP
Migration
Backend
Debugging
Versioning

FastMCP middleware fails with AttributeError after upgrade from 1.x to 2.0 | MiddlewareContext API changed from `context.params` to `context.message` structure

Issue

Middleware components in the FastMCP pipeline failed during tool execution with the error: 'MiddlewareContext' object has no attribute 'params'. This occurred when attempting to fetch URLs via call_tool('fetch_url', {'url': source}), causing all middleware processing to halt. The issue affected the entire automated video generation pipeline, leading to failed tool invocations.

Culprit

The root cause was a breaking API change in FastMCP 2.0, where the MiddlewareContext object structure was redesigned. The middleware components were hardcoded to use the deprecated FastMCP 1.x API, which accessed tool metadata via context.params.name and context.params.arguments. In FastMCP 2.0, all metadata was moved to context.message, following MCP protocol standards. This mismatch caused the middleware components to fail, as they were unable to access the updated context structure.

Solution

Updated all middleware components (LoggingMiddleware, TimingMiddleware, and ErrorHandlingMiddleware) to use the FastMCP 2.0 MiddlewareContext API. This involved replacing all references to context.params with context.message, ensuring compatibility with the new API structure. The updated implementation provides additional context via context.message and maintains backward compatibility for optional arguments.

This transformation resolved the tool execution failures and ensured seamless integration with the FastMCP 2.0 pipeline, while preserving existing middleware functionality.