Feedback

Chat Icon

Practical MCP with FastMCP & LangChain

Engineering the Agentic Experience

FastMCP Middleware
73%

Hooks: Choosing the Right Level

FastMCP provides hooks at three levels of specificity, and multiple hooks fire for a single request in a chain from general to specific. When a client calls a tool, FastMCP processes on_message first, then on_request, then on_call_tool. Each hook in the chain calls call_next to reach the next one, so if you override both on_message and on_call_tool in the same middleware, both will run.

HookFires when…Typical use case
on_messageAny MCP message arrivesObservability, broad logging
on_requestA request expecting a response arrivesAuthentication, authorization
on_notificationA fire-and-forget notification arrivesAsync side effects, event logging
on_initializeA client connects and initialises

Practical MCP with FastMCP & LangChain

Engineering the Agentic Experience

Enroll now to unlock current content and receive all future updates for free. Your purchase supports the author and fuels the creation of more exciting content. Act fast, as the price will rise as the course nears completion!