Skip to content

Modules

VisibilityAwareFastMCP

Bases: FastMCP

FastMCP server with declarative tool visibility predicates.

Source code in mcp_email_server/app.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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)()]