Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
1394bb8
1
Parent(s): 6a92d5e
Document exclude_args
Browse files- docs/docs.json +11 -4
- docs/servers/tools.mdx +20 -1
- src/fastmcp/tools/tool.py +3 -6
docs/docs.json
CHANGED
|
@@ -46,10 +46,17 @@
|
|
| 46 |
"group": "Servers",
|
| 47 |
"pages": [
|
| 48 |
"servers/fastmcp",
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
"servers/openapi",
|
| 54 |
"servers/proxy",
|
| 55 |
"servers/composition"
|
|
|
|
| 46 |
"group": "Servers",
|
| 47 |
"pages": [
|
| 48 |
"servers/fastmcp",
|
| 49 |
+
{
|
| 50 |
+
"group": "Core Components",
|
| 51 |
+
"hidden": false,
|
| 52 |
+
"icon": "toolbox",
|
| 53 |
+
"pages": [
|
| 54 |
+
"servers/tools",
|
| 55 |
+
"servers/resources",
|
| 56 |
+
"servers/prompts",
|
| 57 |
+
"servers/context"
|
| 58 |
+
]
|
| 59 |
+
},
|
| 60 |
"servers/openapi",
|
| 61 |
"servers/proxy",
|
| 62 |
"servers/composition"
|
docs/servers/tools.mdx
CHANGED
|
@@ -158,7 +158,7 @@ While FastMCP infers the name and description from your function, you can overri
|
|
| 158 |
@mcp.tool(
|
| 159 |
name="find_products", # Custom tool name for the LLM
|
| 160 |
description="Search the product catalog with optional category filtering.", # Custom description
|
| 161 |
-
tags={"catalog", "search"} # Optional tags for organization/filtering
|
| 162 |
)
|
| 163 |
def search_products_implementation(query: str, category: str | None = None) -> list[dict]:
|
| 164 |
"""Internal function description (ignored if description is provided above)."""
|
|
@@ -172,6 +172,25 @@ def search_products_implementation(query: str, category: str | None = None) -> l
|
|
| 172 |
- **`tags`**: A set of strings used to categorize the tool. Clients *might* use tags to filter or group available tools.
|
| 173 |
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
### Async Tools
|
| 176 |
|
| 177 |
FastMCP seamlessly supports both standard (`def`) and asynchronous (`async def`) functions as tools.
|
|
|
|
| 158 |
@mcp.tool(
|
| 159 |
name="find_products", # Custom tool name for the LLM
|
| 160 |
description="Search the product catalog with optional category filtering.", # Custom description
|
| 161 |
+
tags={"catalog", "search"}, # Optional tags for organization/filtering
|
| 162 |
)
|
| 163 |
def search_products_implementation(query: str, category: str | None = None) -> list[dict]:
|
| 164 |
"""Internal function description (ignored if description is provided above)."""
|
|
|
|
| 172 |
- **`tags`**: A set of strings used to categorize the tool. Clients *might* use tags to filter or group available tools.
|
| 173 |
|
| 174 |
|
| 175 |
+
- **`exclude_args`**:
|
| 176 |
+
<VersionBadge version="2.6.0" />
|
| 177 |
+
A list of argument names to exclude 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.
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
Example:
|
| 181 |
+
|
| 182 |
+
```python
|
| 183 |
+
@mcp.tool(
|
| 184 |
+
name="get_user_details",
|
| 185 |
+
exclude_args=["user_id"]
|
| 186 |
+
)
|
| 187 |
+
def get_user_details(user_id: str = None) -> str:
|
| 188 |
+
# user_id will be injected by the server, not provided by the LLM
|
| 189 |
+
...
|
| 190 |
+
```
|
| 191 |
+
|
| 192 |
+
With this configuration, `user_id` will not appear in the tool's parameter schema, but can still be set by the server or framework at runtime.
|
| 193 |
+
|
| 194 |
### Async Tools
|
| 195 |
|
| 196 |
FastMCP seamlessly supports both standard (`def`) and asynchronous (`async def`) functions as tools.
|
src/fastmcp/tools/tool.py
CHANGED
|
@@ -102,15 +102,12 @@ class Tool(BaseModel):
|
|
| 102 |
type_adapter = get_cached_typeadapter(fn)
|
| 103 |
schema = type_adapter.json_schema()
|
| 104 |
|
|
|
|
| 105 |
context_kwarg = find_kwarg_by_type(fn, kwarg_type=Context)
|
| 106 |
-
temp_prune_params: list[str] = []
|
| 107 |
if context_kwarg:
|
| 108 |
-
|
| 109 |
if exclude_args:
|
| 110 |
-
|
| 111 |
-
prune_params: list[str] | None = (
|
| 112 |
-
None if not temp_prune_params else temp_prune_params
|
| 113 |
-
)
|
| 114 |
|
| 115 |
schema = compress_schema(schema, prune_params=prune_params)
|
| 116 |
|
|
|
|
| 102 |
type_adapter = get_cached_typeadapter(fn)
|
| 103 |
schema = type_adapter.json_schema()
|
| 104 |
|
| 105 |
+
prune_params: list[str] = []
|
| 106 |
context_kwarg = find_kwarg_by_type(fn, kwarg_type=Context)
|
|
|
|
| 107 |
if context_kwarg:
|
| 108 |
+
prune_params.append(context_kwarg)
|
| 109 |
if exclude_args:
|
| 110 |
+
prune_params.extend(exclude_args)
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
schema = compress_schema(schema, prune_params=prune_params)
|
| 113 |
|