You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/servers/resources.mdx
+74-29Lines changed: 74 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -412,14 +412,14 @@ With these two templates defined, clients can request a variety of resources:
412
412
-`repos://jlowin/fastmcp/info` → Returns info about the jlowin/fastmcp repository
413
413
-`repos://prefecthq/prefect/info` → Returns info about the prefecthq/prefect repository
414
414
415
-
### Wildcard Parameters
415
+
### RFC 6570 URI Templates
416
416
417
-
<VersionBadgeversion="2.2.4" />
418
417
419
-
<Tip>
420
-
Please note: FastMCP's support for wildcard parameters is an **extension** of the Model Context Protocol standard, which otherwise follows RFC 6570. Since all template processing happens in the FastMCP server, this should not cause any compatibility issues with other MCP implementations.
421
-
</Tip>
418
+
FastMCP implements [RFC 6570 URI Templates](https://datatracker.ietf.org/doc/html/rfc6570) for resource templates, providing a standardized way to define parameterized URIs. This includes support for simple expansion, wildcard path parameters, and form-style query parameters.
422
419
420
+
#### Wildcard Parameters
421
+
422
+
<VersionBadgeversion="2.2.4" />
423
423
424
424
Resource templates support wildcard parameters that can match multiple path segments. While standard parameters (`{param}`) only match a single path segment and don't cross "/" boundaries, wildcard parameters (`{param*}`) can capture multiple segments including slashes. Wildcards capture all subsequent path segments *up until* the defined part of the URI template (whether literal or another parameter). This allows you to have multiple wildcard parameters in a single URI template.
"""Retrieves a file from a specific repository and path, but
451
+
"""Retrieves a file from a specific repository and path, but
452
452
only if the resource ends with `template.py`"""
453
453
# Can match repo://jlowin/fastmcp/src/resources/template.py
454
454
return {
@@ -466,43 +466,88 @@ Wildcard parameters are useful when:
466
466
467
467
Note that like regular parameters, each wildcard parameter must still be a named parameter in your function signature, and all required function parameters must appear in the URI template.
468
468
469
-
### Default Values
470
-
471
-
<VersionBadgeversion="2.2.0" />
469
+
#### Query Parameters
472
470
473
-
When creating resource templates, FastMCP enforces two rules for the relationship between URI template parameters and function parameters:
471
+
<VersionBadgeversion="2.13.0" />
474
472
475
-
1.**Required Function Parameters:** All function parameters without default values (required parameters) must appear in the URI template.
476
-
2.**URI Parameters:** All URI template parameters must exist as function parameters.
473
+
FastMCP supports RFC 6570 form-style query parameters using the `{?param1,param2}` syntax. Query parameters provide a clean way to pass optional configuration to resources without cluttering the path.
477
474
478
-
However, function parameters with default values don't need to be included in the URI template. When a client requests a resource, FastMCP will:
479
-
480
-
- Extract parameter values from the URI for parameters included in the template
481
-
- Use default values for any function parameters not in the URI template
482
-
483
-
This allows for flexible API designs. For example, a simple search template with optional parameters:
475
+
Query parameters must be optional function parameters (have default values), while path parameters map to required function parameters. This enforces a clear separation: required data goes in the path, optional configuration in query params.
-`files://src/main.py?encoding=ascii&lines=50` → Custom encoding and line limit
514
+
515
+
FastMCP automatically coerces query parameter string values to the correct types based on your function's type hints (`int`, `float`, `bool`, `str`).
516
+
517
+
**Query parameters vs. hidden defaults:**
518
+
519
+
Query parameters expose optional configuration to clients. To hide optional parameters from clients entirely (always use defaults), simply omit them from the URI template:
520
+
521
+
```python
522
+
# Clients CAN override max_results via query string
With this template, clients can request `search://python` and the function will be called with `query="python", max_results=10, include_archived=False`. MCP Developers can still call the underlying `search_resources` function directly with more specific parameters.
533
+
### Template Parameter Rules
534
+
535
+
<VersionBadgeversion="2.2.0" />
536
+
537
+
FastMCP enforces these validation rules when creating resource templates:
538
+
539
+
1.**Required function parameters** (no default values) must appear in the URI path template
540
+
2.**Query parameters** (specified with `{?param}` syntax) must be optional function parameters with default values
541
+
3.**All URI template parameters** (path and query) must exist as function parameters
542
+
543
+
Optional function parameters (those with default values) can be:
544
+
- Included as query parameters (`{?param}`) - clients can override via query string
545
+
- Omitted from URI template - always uses default value, not exposed to clients
546
+
- Used in alternative path templates - enables multiple ways to access the same resource
547
+
548
+
**Multiple templates for one function:**
504
549
505
-
You can also create multiple resource templates that provide different ways to access the same underlying data by manually applying decorators to a single function:
550
+
Create multiple resource templates that expose the same function through different URI patterns by manually applying decorators:
0 commit comments