mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-12 00:29:11 +02:00
Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
66 lines
2.1 KiB
Text
66 lines
2.1 KiB
Text
---
|
|
title: prompts_as_tools
|
|
sidebarTitle: prompts_as_tools
|
|
---
|
|
|
|
# `fastmcp.server.transforms.prompts_as_tools`
|
|
|
|
|
|
Transform that exposes prompts as tools.
|
|
|
|
This transform generates tools for listing and getting prompts, enabling
|
|
clients that only support tools to access prompt functionality.
|
|
|
|
The generated tools route through `ctx.fastmcp` at runtime, so all server
|
|
middleware (auth, visibility, rate limiting, etc.) applies to prompt
|
|
operations exactly as it would for direct `prompts/get` calls.
|
|
|
|
Example:
|
|
```python
|
|
from fastmcp import FastMCP
|
|
from fastmcp.server.transforms import PromptsAsTools
|
|
|
|
mcp = FastMCP("Server")
|
|
mcp.add_transform(PromptsAsTools(mcp))
|
|
# Now has list_prompts and get_prompt tools
|
|
```
|
|
|
|
|
|
## Classes
|
|
|
|
### `PromptsAsTools` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/prompts_as_tools.py#L38" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
|
|
Transform that adds tools for listing and getting prompts.
|
|
|
|
Generates two tools:
|
|
- `list_prompts`: Lists all prompts
|
|
- `get_prompt`: Gets a specific prompt with optional arguments
|
|
|
|
The generated tools route through the server at runtime, so auth,
|
|
middleware, and visibility apply automatically.
|
|
|
|
This transform should be applied to a FastMCP server instance, not
|
|
a raw Provider, because the generated tools need the server's
|
|
middleware chain for auth and visibility filtering.
|
|
|
|
|
|
**Methods:**
|
|
|
|
#### `list_tools` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/prompts_as_tools.py#L75" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
list_tools(self, tools: Sequence[Tool]) -> Sequence[Tool]
|
|
```
|
|
|
|
Add prompt tools to the tool list.
|
|
|
|
|
|
#### `get_tool` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/server/transforms/prompts_as_tools.py#L83" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
|
|
|
|
```python
|
|
get_tool(self, name: str, call_next: GetToolNext) -> Tool | None
|
|
```
|
|
|
|
Get a tool by name, including generated prompt tools.
|
|
|