Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
63bfcb4
1
Parent(s): 4a544ad
Update middleware imports and documentation
Browse files
CLAUDE.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
| 1 |
# FastMCP Development Guidelines
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
## Documentation
|
| 4 |
|
| 5 |
- Documentation uses the Mintlify framework
|
|
|
|
| 1 |
# FastMCP Development Guidelines
|
| 2 |
|
| 3 |
+
## Git
|
| 4 |
+
|
| 5 |
+
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.
|
| 6 |
+
|
| 7 |
## Documentation
|
| 8 |
|
| 9 |
- Documentation uses the Mintlify framework
|
docs/servers/middleware.mdx
CHANGED
|
@@ -181,7 +181,7 @@ class ComponentAccessMiddleware(Middleware):
|
|
| 181 |
|
| 182 |
### Working with Listing Results
|
| 183 |
|
| 184 |
-
For listing operations,
|
| 185 |
|
| 186 |
```python
|
| 187 |
from fastmcp.server.middleware import Middleware, MiddlewareContext, ListToolsResult
|
|
|
|
| 181 |
|
| 182 |
### Working with Listing Results
|
| 183 |
|
| 184 |
+
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:
|
| 185 |
|
| 186 |
```python
|
| 187 |
from fastmcp.server.middleware import Middleware, MiddlewareContext, ListToolsResult
|
src/fastmcp/server/middleware/__init__.py
CHANGED
|
@@ -1,6 +1,19 @@
|
|
| 1 |
-
from .middleware import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
__all__ = [
|
| 4 |
"Middleware",
|
| 5 |
"MiddlewareContext",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
]
|
|
|
|
| 1 |
+
from .middleware import (
|
| 2 |
+
Middleware,
|
| 3 |
+
MiddlewareContext,
|
| 4 |
+
CallNext,
|
| 5 |
+
ListToolsResult,
|
| 6 |
+
ListResourcesResult,
|
| 7 |
+
ListResourceTemplatesResult,
|
| 8 |
+
ListPromptsResult,
|
| 9 |
+
)
|
| 10 |
|
| 11 |
__all__ = [
|
| 12 |
"Middleware",
|
| 13 |
"MiddlewareContext",
|
| 14 |
+
"CallNext",
|
| 15 |
+
"ListToolsResult",
|
| 16 |
+
"ListResourcesResult",
|
| 17 |
+
"ListResourceTemplatesResult",
|
| 18 |
+
"ListPromptsResult",
|
| 19 |
]
|
src/fastmcp/server/middleware/middleware.py
CHANGED
|
@@ -25,6 +25,16 @@ from fastmcp.tools.tool import Tool
|
|
| 25 |
if TYPE_CHECKING:
|
| 26 |
from fastmcp.server.context import Context
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
logger = logging.getLogger(__name__)
|
| 29 |
|
| 30 |
|
|
@@ -52,12 +62,6 @@ ServerResultT = TypeVar(
|
|
| 52 |
)
|
| 53 |
|
| 54 |
|
| 55 |
-
@dataclass(kw_only=True)
|
| 56 |
-
class CallToolResult:
|
| 57 |
-
content: list[mt.Content]
|
| 58 |
-
isError: bool = False
|
| 59 |
-
|
| 60 |
-
|
| 61 |
@dataclass(kw_only=True)
|
| 62 |
class ListToolsResult:
|
| 63 |
tools: dict[str, Tool]
|
|
|
|
| 25 |
if TYPE_CHECKING:
|
| 26 |
from fastmcp.server.context import Context
|
| 27 |
|
| 28 |
+
__all__ = [
|
| 29 |
+
"Middleware",
|
| 30 |
+
"MiddlewareContext",
|
| 31 |
+
"CallNext",
|
| 32 |
+
"ListToolsResult",
|
| 33 |
+
"ListResourcesResult",
|
| 34 |
+
"ListResourceTemplatesResult",
|
| 35 |
+
"ListPromptsResult",
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
logger = logging.getLogger(__name__)
|
| 39 |
|
| 40 |
|
|
|
|
| 62 |
)
|
| 63 |
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
@dataclass(kw_only=True)
|
| 66 |
class ListToolsResult:
|
| 67 |
tools: dict[str, Tool]
|