Bases: FastMCP
FastMCP server with declarative tool visibility predicates.
Source code in mcp_email_server/app.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 | class VisibilityAwareFastMCP(FastMCP):
"""FastMCP server with declarative tool visibility predicates."""
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self._tool_visibility: dict[str, ToolVisibilityPredicate] = {}
def tool(
self,
name: str | None = None,
*,
visible_if: ToolVisibilityPredicate | None = None,
**kwargs: Any,
) -> Callable[[Any], Any]:
decorator = super().tool(name=name, **kwargs)
def wrapped(fn: Any) -> Any:
registered = decorator(fn)
if visible_if is not None:
self._tool_visibility[name or fn.__name__] = visible_if
return registered
return wrapped
async def list_tools(self):
tools = await super().list_tools()
return [tool for tool in tools if self._tool_visibility.get(tool.name, lambda: True)()]
|