{"record":{"id":"32dacb0e746927d6","repo":"PrefectHQ/fastmcp","slug":"proxyinitializemiddleware-is-deprecated-and-will","errorCode":null,"errorMessage":"`ProxyInitializeMiddleware` is deprecated and will be removed in a future release. `FastMCPProxy` now installs `ProxyMetadataMiddleware` automatically.","messagePattern":"`ProxyInitializeMiddleware` is deprecated and will be removed in a future release\\. `FastMCPProxy` now installs `ProxyMetadataMiddleware` automatically\\.","errorType":"console","errorClass":"FastMCPDeprecationWarning","httpStatus":null,"severity":"warning","filePath":"fastmcp_slim/fastmcp/server/providers/proxy.py","lineNumber":272,"sourceCode":"    handler's ``get_context()`` would otherwise resolve to the backend context\n    and the server-initiated request would hang until timeout.\n\n    We stash a ``(RequestContext, weakref[FastMCP])`` tuple — never a ``Context``\n    instance — because ``Context`` properties are themselves ContextVar-dependent\n    and would resolve stale values in the receive loop.\n    \"\"\"\n    if isinstance(client, ProxyClient):\n        client._proxy_rc_ref[0] = (\n            ctx.request_context,\n            ctx._fastmcp,  # weakref to FastMCP, not the Context\n        )\n\n\nclass ProxyInitializeMiddleware(Middleware):\n    \"\"\"Deprecated middleware for forwarding instructions during initialization.\"\"\"\n\n    def __init__(self, proxy: FastMCPProxy) -> None:\n        warnings.warn(\n            \"`ProxyInitializeMiddleware` is deprecated and will be removed in a \"\n            \"future release. `FastMCPProxy` now installs \"\n            \"`ProxyMetadataMiddleware` automatically.\",\n            FastMCPDeprecationWarning,\n            stacklevel=2,\n        )\n        self.proxy = proxy\n\n    async def on_initialize(\n        self,\n        context: MiddlewareContext[mcp_types.InitializeRequest],\n        call_next: CallNext[\n            mcp_types.InitializeRequest,\n            mcp_types.InitializeResult | None,\n        ],\n    ) -> mcp_types.InitializeResult | None:\n        client = await self.proxy._get_client()\n        upstream_instructions: str | None = None","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/server/providers/proxy.py#L254-L290","documentation":"`ProxyInitializeMiddleware` was a middleware for forwarding server instructions during proxy initialization. `FastMCPProxy` now installs `ProxyMetadataMiddleware` automatically, so instantiating this class is deprecated and raises `FastMCPDeprecationWarning`; it will be removed.","triggerScenarios":"Constructing `ProxyInitializeMiddleware(proxy)` directly, or explicitly passing it into a `FastMCP(middleware=[...])` / proxy server's middleware list.","commonSituations":"Proxy configs copied from pre-`ProxyMetadataMiddleware` examples; manual middleware stacks where instructions forwarding was set up by hand.","solutions":["Delete the `ProxyInitializeMiddleware` usage — `FastMCPProxy` handles metadata/instructions automatically now.","If you need custom instructions, configure them on the proxy itself rather than via this middleware.","Remove imports of `ProxyInitializeMiddleware` to avoid breakage when it is removed.","Test the proxy init handshake after removal to confirm instructions still arrive."],"exampleFix":"// before\nserver = FastMCPProxy(client=client, middleware=[ProxyInitializeMiddleware(proxy)])\n// after\nserver = FastMCPProxy(client=client)  # ProxyMetadataMiddleware installed automatically","handlingStrategy":"try-catch","validationCode":"# do not reference ProxyInitializeMiddleware anywhere in middleware lists\nassert \"ProxyInitializeMiddleware\" not in {type(m).__name__ for m in server.middleware}\n","typeGuard":null,"tryCatchPattern":"import warnings\nfrom fastmcp.exceptions import FastMCPDeprecationWarning\nwith warnings.catch_warnings(record=True) as caught:\n    warnings.simplefilter(\"always\", FastMCPDeprecationWarning)\n    mw = ProxyInitializeMiddleware(proxy)\nif any(\"ProxyInitializeMiddleware\" in str(w.message) for w in caught):\n    mw = None  # rely on FastMCPProxy's automatic ProxyMetadataMiddleware","preventionTips":["Remove ProxyInitializeMiddleware from all middleware lists","Rely on FastMCPProxy's automatic ProxyMetadataMiddleware","Enable FastMCPDeprecationWarning-as-error in test suites"],"tags":["python","deprecation","proxy","middleware"],"backgroundTag":"deprecated-middleware","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}