-
Notifications
You must be signed in to change notification settings - Fork 2k
Convert mounted servers to MountedProvider #2635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
115ec5c
Simplify Provider interface and consolidate docket registration
jlowin ba70dc5
Fix control flow in ComponentService resource methods
jlowin 5466bb7
Move providers to server/providers
jlowin 58d7484
Ensure MountedProvider get_* methods go through middleware
jlowin cacce67
Fix get_resource to only return concrete resources
jlowin e6b16ff
Move prefix utilities into mounted.py, deprecate import_server
jlowin 5931612
Fix provider iteration order and remove dead _is_mounted flag
jlowin 7edb1ba
Add TaskComponents type and exception handling for provider task regi…
jlowin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| """Providers for dynamic MCP components. | ||
|
|
||
| This module provides the `Provider` abstraction for providing tools, | ||
| resources, and prompts dynamically at runtime. | ||
|
|
||
| Example: | ||
| ```python | ||
| from fastmcp import FastMCP | ||
| from fastmcp.server.providers import Provider | ||
| from fastmcp.tools import Tool | ||
|
|
||
| class DatabaseProvider(Provider): | ||
| def __init__(self, db_url: str): | ||
| self.db = Database(db_url) | ||
|
|
||
| async def list_tools(self) -> list[Tool]: | ||
| rows = await self.db.fetch("SELECT * FROM tools") | ||
| return [self._make_tool(row) for row in rows] | ||
|
|
||
| async def get_tool(self, name: str) -> Tool | None: | ||
| row = await self.db.fetchone("SELECT * FROM tools WHERE name = ?", name) | ||
| return self._make_tool(row) if row else None | ||
|
|
||
| mcp = FastMCP("Server", providers=[DatabaseProvider(db_url)]) | ||
| ``` | ||
| """ | ||
|
|
||
| from fastmcp.server.providers.base import Components, Provider, TaskComponents | ||
| from fastmcp.server.providers.mounted import MountedProvider | ||
|
|
||
| __all__ = [ | ||
| "Components", | ||
| "MountedProvider", | ||
| "Provider", | ||
| "TaskComponents", | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.