New in versionDocumentation Index
Fetch the complete documentation index at: https://fastmcp-transfer-to-prefecthq.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
3.0.0
FileSystemProvider scans a directory for Python files and automatically registers functions decorated with @tool, @resource, or @prompt. This enables a file-based organization pattern similar to Next.js routing, where your project structure becomes your component registry.
Why Filesystem Discovery
Traditional FastMCP servers require coordination between files. Either your tool files import the server to call@server.tool(), or your server file imports all the tool modules. Both approaches create coupling that some developers prefer to avoid.
FileSystemProvider eliminates this coordination. Each file is self-contained—it uses standalone decorators (@tool, @resource, @prompt) that don’t require access to a server instance. The provider discovers these files at startup, so you can add new tools without modifying your server file.
This is a convention some teams prefer, not necessarily better for all projects. The tradeoffs:
- No coordination: Files don’t import the server; server doesn’t import files
- Predictable naming: Function names become component names (unless overridden)
- Development mode: Optionally re-scan files on every request for rapid iteration
Quick Start
Create a provider pointing to your components directory, then pass it to your server. UsePath(__file__).parent to make the path relative to your server file.
mcp/ directory, create Python files with decorated functions.
FileSystemProvider scans the directory, imports all Python files, and registers any decorated functions it finds.
Decorators
FastMCP provides standalone decorators that mark functions for discovery:@tool from fastmcp.tools, @resource from fastmcp.resources, and @prompt from fastmcp.prompts. These support the full syntax of server-bound decorators—all the same parameters work identically.
@tool
Mark a function as a tool. The function name becomes the tool name by default.name, title, description, icons, tags, output_schema, annotations, and meta.
@resource
Mark a function as a resource. Unlike@tool, the @resource decorator requires a URI argument.
{parameters} or the function has arguments.
uri (required), name, title, description, icons, mime_type, tags, annotations, and meta.
@prompt
Mark a function as a prompt template.name, title, description, icons, tags, and meta.
Directory Structure
The directory structure is purely organizational. The provider recursively scans all.py files regardless of which subdirectory they’re in. Subdirectories like tools/, resources/, and prompts/ are optional conventions that help you organize code.
Discovery Rules
The provider follows these rules when scanning:| Rule | Behavior |
|---|---|
| File extensions | Only .py files are scanned |
__init__.py | Skipped (used for package structure, not components) |
__pycache__ | Skipped |
| Private functions | Functions starting with _ are ignored, even if decorated |
| No decorators | Files without @tool, @resource, or @prompt are silently skipped |
| Multiple components | A single file can contain any number of decorated functions |
Package Imports
If your directory contains an__init__.py file, the provider imports files as proper Python package members. This means relative imports work correctly within your components directory.
__init__.py, files are imported directly using importlib.util.spec_from_file_location.
Reload Mode
During development, you may want changes to component files to take effect without restarting the server. Enable reload mode to re-scan the directory on every request.reload=True, the provider:
- Re-discovers all Python files on each request
- Re-imports modules that have changed
- Updates the component registry with any new, modified, or removed components
Error Handling
When a file fails to import (syntax error, missing dependency, etc.), the provider logs a warning and continues scanning other files. Failed imports don’t prevent the server from starting.Example Project
A complete example is available in the repository atexamples/filesystem-provider/. The structure demonstrates the recommended organization.
fastmcp run examples/filesystem-provider/server.py or inspect with fastmcp inspect examples/filesystem-provider/server.py.
