fastmcp/docs/python-sdk/fastmcp-fs-decorators.mdx
marvin-context-protocol[bot] 24d500d384
chore: Update SDK documentation (#2761)
Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
2026-01-10 11:49:29 -05:00

156 lines
5.1 KiB
Text

---
title: decorators
sidebarTitle: decorators
---
# `fastmcp.fs.decorators`
Decorators for marking functions in filesystem-based discovery.
These decorators mark functions with metadata so that FileSystemProvider
can discover and register them. Unlike LocalProvider's decorators, these
do NOT register components immediately - they just store metadata on the
function for later discovery.
Example:
```python
# mcp/tools/greet.py
from fastmcp.fs import tool
@tool
def greet(name: str) -> str:
'''Greet someone by name.'''
return f"Hello, {name}!"
@tool(name="custom-greet", tags={"greeting"})
def my_greet(name: str) -> str:
return f"Hi, {name}!"
```
## Functions
### `get_fs_meta` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/fs/decorators.py#L86" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```python
get_fs_meta(fn: Any) -> FSMeta | None
```
Get filesystem metadata from a function if it has been decorated.
### `has_fs_meta` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/fs/decorators.py#L91" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```python
has_fs_meta(fn: Any) -> bool
```
Check if a function has filesystem metadata.
### `tool` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/fs/decorators.py#L134" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```python
tool(fn: AnyFunction | str | None = None) -> Any
```
Mark a function as a tool for filesystem-based discovery.
This decorator stores metadata on the function but does NOT register it.
FileSystemProvider discovers marked functions when scanning directories.
Supports multiple calling patterns:
- @tool (without parentheses)
- @tool() (with empty parentheses)
- @tool("custom_name") (with name as first argument)
- @tool(name="custom_name") (with keyword arguments)
**Args:**
- `fn`: The function to decorate, or a name string, or None
- `name`: Optional name for the tool (defaults to function name)
- `title`: Optional title for display
- `description`: Optional description (defaults to docstring)
- `icons`: Optional icons for the tool
- `tags`: Optional tags for categorization
- `output_schema`: Optional JSON schema for output
- `annotations`: Optional tool annotations
- `meta`: Optional metadata dict
### `resource` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/fs/decorators.py#L222" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```python
resource(uri: str) -> Any
```
Mark a function as a resource for filesystem-based discovery.
This decorator stores metadata on the function but does NOT register it.
FileSystemProvider discovers marked functions when scanning directories.
Unlike @tool and @prompt, @resource REQUIRES a URI argument.
**Args:**
- `uri`: URI for the resource (e.g., "config\://app" or "users\://{user_id}")
- `name`: Optional name for the resource
- `title`: Optional title for display
- `description`: Optional description (defaults to docstring)
- `icons`: Optional icons for the resource
- `mime_type`: Optional MIME type
- `tags`: Optional tags for categorization
- `annotations`: Optional resource annotations
- `meta`: Optional metadata dict
### `prompt` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/fs/decorators.py#L324" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```python
prompt(fn: AnyFunction | str | None = None) -> Any
```
Mark a function as a prompt for filesystem-based discovery.
This decorator stores metadata on the function but does NOT register it.
FileSystemProvider discovers marked functions when scanning directories.
Supports multiple calling patterns:
- @prompt (without parentheses)
- @prompt() (with empty parentheses)
- @prompt("custom_name") (with name as first argument)
- @prompt(name="custom_name") (with keyword arguments)
**Args:**
- `fn`: The function to decorate, or a name string, or None
- `name`: Optional name for the prompt (defaults to function name)
- `title`: Optional title for display
- `description`: Optional description (defaults to docstring)
- `icons`: Optional icons for the prompt
- `tags`: Optional tags for categorization
- `meta`: Optional metadata dict
## Classes
### `ToolMeta` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/fs/decorators.py#L40" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
Metadata stored on functions decorated with @tool.
### `ResourceMeta` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/fs/decorators.py#L55" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
Metadata stored on functions decorated with @resource.
### `PromptMeta` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/fs/decorators.py#L71" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
Metadata stored on functions decorated with @prompt.