Skip to main content

fastmcp.server.providers.filesystem

FileSystemProvider for filesystem-based component discovery. FileSystemProvider scans a directory for Python files, imports them, and registers any Tool, Resource, ResourceTemplate, or Prompt objects found. Components are created using the standalone decorators from fastmcp.tools, fastmcp.resources, and fastmcp.prompts: Example:
# In mcp/tools.py
from fastmcp.tools import tool

@tool
def greet(name: str) -> str:
    return f"Hello, {name}!"

# In main.py
from pathlib import Path

from fastmcp import FastMCP
from fastmcp.server.providers import FileSystemProvider

mcp = FastMCP("MyServer", providers=[FileSystemProvider(Path(__file__).parent / "mcp")])

Classes

FileSystemProvider

Provider that discovers components from the filesystem. Scans a directory for Python files and registers any Tool, Resource, ResourceTemplate, or Prompt objects found. Components are created using the standalone decorators:
  • @tool from fastmcp.tools
  • @resource from fastmcp.resources
  • @prompt from fastmcp.prompts
Args:
  • root: Root directory to scan. Defaults to current directory.
  • reload: If True, re-scan files on every request (dev mode). Defaults to False (scan once at init, cache results).
Methods:

list_tools

list_tools(self) -> Sequence[Tool]
Return all tools, reloading if in reload mode.

get_tool

get_tool(self, name: str) -> Tool | None
Get a tool by name, reloading if in reload mode.

list_resources

list_resources(self) -> Sequence[Resource]
Return all resources, reloading if in reload mode.

get_resource

get_resource(self, uri: str) -> Resource | None
Get a resource by URI, reloading if in reload mode.

list_resource_templates

list_resource_templates(self) -> Sequence[ResourceTemplate]
Return all resource templates, reloading if in reload mode.

get_resource_template

get_resource_template(self, uri: str) -> ResourceTemplate | None
Get a resource template, reloading if in reload mode.

list_prompts

list_prompts(self) -> Sequence[Prompt]
Return all prompts, reloading if in reload mode.

get_prompt

get_prompt(self, name: str) -> Prompt | None
Get a prompt by name, reloading if in reload mode.