Something went wrong. Try again.
mirror of github.com/PrefectHQ/fastmcp
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293---title: aggregatesidebarTitle: aggregate---
# `fastmcp.server.providers.aggregate`
AggregateProvider for combining multiple providers into one.
This module provides `AggregateProvider`, a utility class that presentsmultiple providers as a single unified provider. Useful when you want tocombine custom providers without creating a full FastMCP server.
Example: ```python from fastmcp.server.providers import AggregateProvider
# Combine multiple providers into one combined = AggregateProvider() combined.add_provider(provider1) combined.add_provider(provider2, namespace="api") # Tools become "api_foo"
# Use like any other provider tools = await combined.list_tools() ```
## Classes
### `AggregateProvider` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/providers/aggregate.py#L46" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
Utility provider that combines multiple providers into one.
Components are aggregated from all providers. For get_* operations,providers are queried in parallel and the highest version is returned.
When adding providers with a namespace, wrap_transform() is used to applythe Namespace transform. This means namespace transformation is handledby the wrapped provider, not by AggregateProvider.
Errors from individual providers are logged and skipped (graceful degradation).
**Methods:**
#### `add_provider` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/providers/aggregate.py#L78" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonadd_provider(self, provider: Provider) -> None```
Add a provider with optional namespace.
If the provider is a FastMCP server, it's automatically wrapped inFastMCPProvider to ensure middleware is invoked correctly.
**Args:**- `provider`: The provider to add.- `namespace`: Optional namespace prefix. When set\:- Tools become "namespace_toolname"- Resources become "protocol\://namespace/path"- Prompts become "namespace_promptname"
#### `get_app_tool` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/providers/aggregate.py#L171" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_app_tool(self, app_name: str, tool_name: str) -> Tool | None```
Query all child providers for an app tool.
#### `get_tasks` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/providers/aggregate.py#L256" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonget_tasks(self) -> Sequence[FastMCPComponent]```
Get all task-eligible components from all providers.
#### `lifespan` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/providers/aggregate.py#L269" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```pythonlifespan(self) -> AsyncIterator[None]```
Combine lifespans of all providers.