You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An optional `ToolAnnotations` object or dictionary to add additional metadata about the tool.
96
92
<Expandabletitle="ToolAnnotations attributes">
@@ -345,33 +341,28 @@ Field provides several validation and documentation features:
345
341
-`pattern`: Regex pattern for string validation
346
342
-`default`: Default value if parameter is omitted
347
343
344
+
### Hiding Parameters from the LLM
348
345
346
+
<VersionBadgeversion="2.14.0" />
349
347
348
+
To inject values at runtime without exposing them to the LLM (such as `user_id`, credentials, or database connections), use dependency injection with `Depends()`. Parameters using `Depends()` are automatically excluded from the tool schema:
350
349
351
-
### Excluding Arguments
352
-
353
-
<VersionBadgeversion="2.6.0" />
354
-
355
-
You can exclude certain arguments from the tool schema shown to the LLM. This is useful for arguments that are injected at runtime (such as `state`, `user_id`, or credentials) and should not be exposed to the LLM or client. Only arguments with default values can be excluded; attempting to exclude a required argument will raise an error.
350
+
```python
351
+
from fastmcp import FastMCP
352
+
from fastmcp.dependencies import Depends
356
353
357
-
**Note:**`exclude_args` will be deprecated in FastMCP 2.14 in favor of dependency injection with `Depends()` for better lifecycle management and more explicit dependency handling. `exclude_args` will continue to work until then.
354
+
mcp =FastMCP()
358
355
359
-
Example with `exclude_args`:
356
+
defget_user_id() -> str:
357
+
return"user_123"# Injected at runtime
360
358
361
-
```python
362
-
@mcp.tool(
363
-
name="get_user_details",
364
-
exclude_args=["user_id"]
365
-
)
366
-
defget_user_details(user_id: str=None) -> str:
367
-
# user_id will be injected by the server, not provided by the LLM
0 commit comments