π The fast, Pythonic way to build MCP servers and clients.
Update middleware imports and documentation
Jeremiah Lowin26908784127f
diff --git a/CLAUDE.md b/CLAUDE.mdindex c47c2e3eb..4232c279b 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -1,5 +1,9 @@# FastMCP Development Guidelines+## Git++This project uses `pre-commit` to run checks on all commits. If your commit doesn't pass the checks, it will not be created. Do not attempt to amend commits to pass checks.+## Documentation- Documentation uses the Mintlify frameworkdiff --git a/docs/servers/middleware.mdx b/docs/servers/middleware.mdxindex c00c298ac..453bd28fe 100644--- a/docs/servers/middleware.mdx+++ b/docs/servers/middleware.mdx@@ -181,7 +181,7 @@ class ComponentAccessMiddleware(Middleware):### Working with Listing Results-For listing operations, you can inspect and modify the FastMCP components directly:+For listing operations, the middleware `call_next` function returns a special object that contains the full list of FastMCP components prior to being converted to MCP format. You can modify this object and return it to the client. Specifically, the `ListToolsResult`, `ListResourcesResult`, `ListResourceTemplatesResult`, and `ListPromptsResult` objects can all be imported from fastmcp.server.middleware for this purpose. For example:```pythonfrom fastmcp.server.middleware import Middleware, MiddlewareContext, ListToolsResultdiff --git a/src/fastmcp/server/middleware/__init__.py b/src/fastmcp/server/middleware/__init__.pyindex 548a61bd9..ffe56775e 100644--- a/src/fastmcp/server/middleware/__init__.py+++ b/src/fastmcp/server/middleware/__init__.py@@ -1,6 +1,19 @@-from .middleware import Middleware, MiddlewareContext+from .middleware import (+ Middleware,+ MiddlewareContext,+ CallNext,+ ListToolsResult,+ ListResourcesResult,+ ListResourceTemplatesResult,+ ListPromptsResult,+)__all__ = ["Middleware","MiddlewareContext",+ "CallNext",+ "ListToolsResult",+ "ListResourcesResult",+ "ListResourceTemplatesResult",+ "ListPromptsResult",]diff --git a/src/fastmcp/server/middleware/middleware.py b/src/fastmcp/server/middleware/middleware.pyindex d31a2a820..8d8443586 100644--- a/src/fastmcp/server/middleware/middleware.py+++ b/src/fastmcp/server/middleware/middleware.py@@ -25,6 +25,16 @@ from fastmcp.tools.tool import Toolif TYPE_CHECKING:from fastmcp.server.context import Context+__all__ = [+ "Middleware",+ "MiddlewareContext",+ "CallNext",+ "ListToolsResult",+ "ListResourcesResult",+ "ListResourceTemplatesResult",+ "ListPromptsResult",+]+logger = logging.getLogger(__name__)@@ -52,12 +62,6 @@ ServerResultT = TypeVar()-@dataclass(kw_only=True)-class CallToolResult:- content: list[mt.Content]- isError: bool = False--@dataclass(kw_only=True)class ListToolsResult:tools: dict[str, Tool]