diff --git a/CLAUDE.md b/CLAUDE.md index 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 framework diff --git a/docs/servers/middleware.mdx b/docs/servers/middleware.mdx index 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: ```python from fastmcp.server.middleware import Middleware, MiddlewareContext, ListToolsResult diff --git a/src/fastmcp/server/middleware/__init__.py b/src/fastmcp/server/middleware/__init__.py index 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.py index 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 Tool if 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]