Something went wrong. Try again.
mirror of github.com/PrefectHQ/fastmcp
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354---title: tool_injectionsidebarTitle: tool_injection---
# `fastmcp.server.middleware.tool_injection`
A middleware for injecting tools into the MCP server context.
## Classes
### `ToolInjectionMiddleware` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/middleware/tool_injection.py#L13" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
A middleware for injecting tools into the context.
The server this middleware is added to lists and calls the injected toolsalongside its own. They are resolved by the server's tool lookup, so atool's `auth` check and every middleware in the chain, including`AuthMiddleware`, apply to them as they do to registered tools, whereverthis middleware sits in the chain. Server and session visibility settingsdo 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 samename, and the registered tool is no longer listed. When several injectionmiddleware provide the same name, the one added first takes precedence.Injected tools follow their task configuration as registered tools do.
**Methods:**
#### `injected_tools` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/middleware/tool_injection.py#L38" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythoninjected_tools(self) -> Sequence[Tool]```
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` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/server/middleware/tool_injection.py#L46" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_injected_tool(self, name: str) -> Tool | None```
Return the injected tool with this name, if there is one.