π The fast, Pythonic way to build MCP servers and clients.
Add version badge to on_initialize docs (#2029)
Jeremiah Lowin9cb47e12ddc6
diff --git a/docs/servers/middleware.mdx b/docs/servers/middleware.mdxindex a57882016..66ebe638c 100644--- a/docs/servers/middleware.mdx+++ b/docs/servers/middleware.mdx@@ -89,11 +89,12 @@ Note that the MCP SDK may perform additional operations like listing tools for cThis hierarchy allows you to target your middleware logic with the right level of specificity. Use `on_message` for broad concerns like logging, `on_request` for authentication, and `on_call_tool` for tool-specific logic like performance monitoring.### Available Hooks+<VersionBadge version="2.9.0" />- `on_message`: Called for all MCP messages (requests and notifications)- `on_request`: Called specifically for MCP requests (that expect responses)- `on_notification`: Called specifically for MCP notifications (fire-and-forget)-- `on_initialize`: Called when a client connects and initializes the session (returns `None`)+- `on_call_tool`: Called when tools are being executed- `on_read_resource`: Called when resources are being read- `on_get_prompt`: Called when prompts are being retrieved@@ -101,7 +102,8 @@ This hierarchy allows you to target your middleware logic with the right level o- `on_list_resources`: Called when listing available resources- `on_list_resource_templates`: Called when listing resource templates- `on_list_prompts`: Called when listing available prompts-+<VersionBadge version="2.13.0" />+- `on_initialize`: Called when a client connects and initializes the session (returns `None`)<Note>The `on_initialize` hook receives the client's initialization request but **returns `None`** rather than a result. The initialization response is handled internally by the MCP protocol and cannot be modified by middleware. This hook is useful for client detection, logging connections, or initializing session state, but not for modifying the initialization handshake itself.</Note>