mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-09 15:19:10 +02:00
feat: Provider abstraction for dynamic MCP components (#2622)
* feat: add Provider abstraction for dynamic components
Introduces a `Provider` base class that allows dynamic provision of
tools, resources, and prompts at runtime. Providers are queried after
static components, enabling database-backed tools, external integrations,
and other dynamic component sources.
```python
from fastmcp import FastMCP, Provider
class DatabaseProvider(Provider):
async def list_tools(self, context):
return await db.fetch_tools()
mcp = FastMCP("Server", providers=[DatabaseProvider()])
```
* Add execution methods to Provider interface
Enable providers to customize how components are executed, not just listed.
This unlocks MountedProvider (future) invoking wrapped server middleware.
- call_tool, read_resource, read_resource_template, render_prompt
- Server uses provider execution methods after filter checks
- Default implementations delegate to component methods
* Apply unified error handling to provider execution
- Document error semantics: list_* gracefully degrades, execution propagates
- Wrap provider call_tool/read_resource/render_prompt with masking logic
- ToolError/ResourceError/PromptError pass through, others wrapped
This commit is contained in:
parent
8abd84bf1e
commit
0e5a8fed6c
12 changed files with 1398 additions and 63 deletions
|
|
@ -133,6 +133,14 @@ async with Client(transport=StreamableHttpTransport(server_url)) as client:
|
|||
- Use `# type: ignore[attr-defined]` in tests for MCP results instead of type assertions
|
||||
- Each feature needs corresponding tests
|
||||
|
||||
### Module Exports
|
||||
|
||||
- **Be intentional about re-exports** - don't blindly re-export everything to parent namespaces
|
||||
- Core types that define a module's purpose should be exported (e.g., `Middleware` from `fastmcp.server.middleware`)
|
||||
- Specialized features can live in submodules (e.g., `fastmcp.server.middleware.dynamic`)
|
||||
- Only re-export to `fastmcp.*` for the most fundamental types (e.g., `FastMCP`, `Client`)
|
||||
- When in doubt, prefer users importing from the specific submodule over re-exporting
|
||||
|
||||
### Documentation
|
||||
|
||||
- Uses Mintlify framework
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue