Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/fastmcp/server/providers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async def get_tool(self, name: str) -> Tool | None:
from fastmcp.resources.resource import Resource
from fastmcp.resources.template import ResourceTemplate
from fastmcp.tools.tool import Tool
from fastmcp.utilities.async_utils import gather
from fastmcp.utilities.components import FastMCPComponent
from fastmcp.utilities.visibility import VisibilityFilter

Expand All @@ -60,6 +61,9 @@ class Provider:
def __init__(self) -> None:
self._visibility = VisibilityFilter()

def __repr__(self) -> str:
return f"{self.__class__.__name__}()"

def with_transforms(
self,
*,
Expand Down Expand Up @@ -219,19 +223,18 @@ async def get_component(
Returns:
The component if found, or None to continue searching other providers.
"""
# Default implementation: iterate through all components and match by key
for tool in await self.list_tools():
if tool.key == key:
return tool
for resource in await self.list_resources():
if resource.key == key:
return resource
for template in await self.list_resource_templates():
if template.key == key:
return template
for prompt in await self.list_prompts():
if prompt.key == key:
return prompt
# Default implementation: fetch all component types in parallel
# Exceptions propagate since return_exceptions=False
results = await gather(
self.list_tools(),
self.list_resources(),
self.list_resource_templates(),
self.list_prompts(),
)
for components in results:
for component in components: # type: ignore[union-attr]
if component.key == key:
return component
return None

# -------------------------------------------------------------------------
Expand Down
Loading