mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-09 07:09:11 +02:00
Rename filesystem-provider example dir to avoid mcp/ collision (#3878)
This commit is contained in:
parent
1d39e26025
commit
dfe9b307bd
6 changed files with 11 additions and 11 deletions
|
|
@ -34,13 +34,13 @@ from pathlib import Path
|
||||||
from fastmcp import FastMCP
|
from fastmcp import FastMCP
|
||||||
from fastmcp.server.providers import FileSystemProvider
|
from fastmcp.server.providers import FileSystemProvider
|
||||||
|
|
||||||
mcp = FastMCP("MyServer", providers=[FileSystemProvider(Path(__file__).parent / "mcp")])
|
mcp = FastMCP("MyServer", providers=[FileSystemProvider(Path(__file__).parent / "components")])
|
||||||
```
|
```
|
||||||
|
|
||||||
In your `mcp/` directory, create Python files with decorated functions.
|
In your `components/` directory, create Python files with decorated functions.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# mcp/tools/greet.py
|
# components/tools/greet.py
|
||||||
from fastmcp.tools import tool
|
from fastmcp.tools import tool
|
||||||
|
|
||||||
@tool
|
@tool
|
||||||
|
|
@ -139,7 +139,7 @@ The decorator supports: `name`, `title`, `description`, `icons`, `tags`, and `me
|
||||||
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.
|
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.
|
||||||
|
|
||||||
```
|
```
|
||||||
mcp/
|
components/
|
||||||
├── tools/
|
├── tools/
|
||||||
│ ├── greeting.py # @tool functions
|
│ ├── greeting.py # @tool functions
|
||||||
│ └── calculator.py # @tool functions
|
│ └── calculator.py # @tool functions
|
||||||
|
|
@ -152,7 +152,7 @@ mcp/
|
||||||
You can also put all components in a single file or organize by feature rather than type.
|
You can also put all components in a single file or organize by feature rather than type.
|
||||||
|
|
||||||
```
|
```
|
||||||
mcp/
|
components/
|
||||||
├── user_management.py # @tool, @resource, @prompt for users
|
├── user_management.py # @tool, @resource, @prompt for users
|
||||||
├── billing.py # @tool, @resource for billing
|
├── billing.py # @tool, @resource for billing
|
||||||
└── analytics.py # @tool for analytics
|
└── analytics.py # @tool for analytics
|
||||||
|
|
@ -176,9 +176,9 @@ The provider follows these rules when scanning:
|
||||||
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.
|
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.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# mcp/__init__.py exists
|
# components/__init__.py exists
|
||||||
|
|
||||||
# mcp/tools/greeting.py
|
# components/tools/greeting.py
|
||||||
from ..helpers import format_name # Relative imports work
|
from ..helpers import format_name # Relative imports work
|
||||||
|
|
||||||
@tool
|
@tool
|
||||||
|
|
@ -197,7 +197,7 @@ from pathlib import Path
|
||||||
|
|
||||||
from fastmcp.server.providers import FileSystemProvider
|
from fastmcp.server.providers import FileSystemProvider
|
||||||
|
|
||||||
provider = FileSystemProvider(Path(__file__).parent / "mcp", reload=True)
|
provider = FileSystemProvider(Path(__file__).parent / "components", reload=True)
|
||||||
```
|
```
|
||||||
|
|
||||||
With `reload=True`, the provider:
|
With `reload=True`, the provider:
|
||||||
|
|
@ -227,7 +227,7 @@ A complete example is available in the repository at `examples/filesystem-provid
|
||||||
```
|
```
|
||||||
examples/filesystem-provider/
|
examples/filesystem-provider/
|
||||||
├── server.py # Server entry point
|
├── server.py # Server entry point
|
||||||
└── mcp/
|
└── components/
|
||||||
├── tools/
|
├── tools/
|
||||||
│ ├── greeting.py # greet, farewell tools
|
│ ├── greeting.py # greet, farewell tools
|
||||||
│ └── calculator.py # add, multiply tools
|
│ └── calculator.py # add, multiply tools
|
||||||
|
|
@ -246,7 +246,7 @@ from fastmcp import FastMCP
|
||||||
from fastmcp.server.providers import FileSystemProvider
|
from fastmcp.server.providers import FileSystemProvider
|
||||||
|
|
||||||
provider = FileSystemProvider(
|
provider = FileSystemProvider(
|
||||||
root=Path(__file__).parent / "mcp",
|
root=Path(__file__).parent / "components",
|
||||||
reload=True,
|
reload=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ from fastmcp.server.providers import FileSystemProvider
|
||||||
# Functions decorated with @tool, @resource, or @prompt are registered.
|
# Functions decorated with @tool, @resource, or @prompt are registered.
|
||||||
# Directory structure is purely organizational - decorators determine type.
|
# Directory structure is purely organizational - decorators determine type.
|
||||||
provider = FileSystemProvider(
|
provider = FileSystemProvider(
|
||||||
root=Path(__file__).parent / "mcp",
|
root=Path(__file__).parent / "components",
|
||||||
reload=True, # Set True for dev mode (re-scan on every request)
|
reload=True, # Set True for dev mode (re-scan on every request)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue