From 9cb47e12ddc62ed1d7962426e12e5fa3e75caba9 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Wed, 8 Oct 2025 20:10:12 -0400 Subject: [PATCH] Add version badge to on_initialize docs (#2029) --- docs/servers/middleware.mdx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/servers/middleware.mdx b/docs/servers/middleware.mdx index 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 c This 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 + - `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 - + +- `on_initialize`: Called when a client connects and initializes the session (returns `None`) 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.