Skip to main content

fastmcp.server.middleware.tool_injection

A middleware for injecting tools into the MCP server context.

Classes

ToolInjectionMiddleware

A middleware for injecting tools into the context. The server this middleware is added to lists and calls the injected tools alongside its own. They are resolved by the server’s tool lookup, so a tool’s auth check and every middleware in the chain, including AuthMiddleware, apply to them as they do to registered tools, wherever this middleware sits in the chain. Server and session visibility settings do not apply to injected tools. Injected tools are matched by name alone; a requested version is ignored. An injected tool takes precedence over a registered tool with the same name, and the registered tool is no longer listed. When several injection middleware provide the same name, the one added first takes precedence. Injected tools follow their task configuration as registered tools do. Methods:

injected_tools

The tools this middleware injects, one per name. If several given tools share a name, the last one is kept, matching get_injected_tool().

get_injected_tool

Return the injected tool with this name, if there is one.