mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-23 05:54:19 +02:00
Handle args/kwargs appropriately for various objects
This commit is contained in:
parent
55e62a0c63
commit
c449f1d697
11 changed files with 188 additions and 21 deletions
|
|
@ -53,6 +53,9 @@ def generate_code_request(language: str, task_description: str) -> UserMessage:
|
|||
* **Inferred Metadata:** By default:
|
||||
* Prompt Name: Taken from the function name (`ask_about_topic`).
|
||||
* Prompt Description: Taken from the function's docstring.
|
||||
<Tip>
|
||||
Functions with `*args` or `**kwargs` are not supported as prompts. This restriction exists because FastMCP needs to generate a complete parameter schema for the MCP protocol, which isn't possible with variable argument lists.
|
||||
</Tip>
|
||||
|
||||
### Return Values
|
||||
|
||||
|
|
@ -105,6 +108,7 @@ def generate_content_request(
|
|||
return prompt
|
||||
```
|
||||
|
||||
|
||||
### Required vs. Optional Parameters
|
||||
|
||||
Parameters in your function signature are considered **required** unless they have a default value.
|
||||
|
|
|
|||
|
|
@ -239,6 +239,10 @@ Resource templates share most configuration options with regular resources (name
|
|||
|
||||
Resource templates generate a new resource for each unique set of parameters, which means that resources can be dynamically created on-demand. For example, if the resource template `"user://profile/{name}"` is registered, MCP clients could request `"user://profile/ford"` or `"user://profile/marvin"` to retrieve either of those two user profiles as resources, without having to register each resource individually.
|
||||
|
||||
<Tip>
|
||||
Functions with `*args` are not supported as resource templates. However, unlike tools and prompts, resource templates do support `**kwargs` because the URI template defines specific parameter names that will be collected and passed as keyword arguments.
|
||||
</Tip>
|
||||
|
||||
Here is a complete example that shows how to define two resource templates:
|
||||
|
||||
```python
|
||||
|
|
|
|||
|
|
@ -43,9 +43,12 @@ When this tool is registered, FastMCP automatically:
|
|||
- Generates an input schema based on the function's parameters and type annotations.
|
||||
- Handles parameter validation and error reporting.
|
||||
|
||||
|
||||
The way you define your Python function dictates how the tool appears and behaves for the LLM client.
|
||||
|
||||
<Tip>
|
||||
Functions with `*args` or `**kwargs` are not supported as tools. This restriction exists because FastMCP needs to generate a complete parameter schema for the MCP protocol, which isn't possible with variable argument lists.
|
||||
</Tip>
|
||||
|
||||
### Parameters
|
||||
|
||||
#### Annotations
|
||||
|
|
@ -90,6 +93,7 @@ def process_image(
|
|||
# Implementation...
|
||||
```
|
||||
|
||||
|
||||
You can also use the Field as a default value, though the Annotated approach is preferred:
|
||||
|
||||
```python
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue