PrefectHQ/fastmcp · error
PromptsAsTools requires a FastMCP server instance, not a
Error message
PromptsAsTools requires a FastMCP server instance, not a {type(provider).__name__}. The generated tools route through the server's middleware chain at runtime for auth and visibility. Pass your FastMCP server: PromptsAsTools(mcp) What it means
PromptsAsTools is a transform that exposes a server's prompts as callable tools; because the generated tools route through the server's middleware chain (auth, visibility) at runtime, it requires an actual FastMCP instance. Passing any other Provider raises TypeError at construction.
Solutions
- Pass the FastMCP server instance: PromptsAsTools(mcp)
- If you intended to transform a plain provider, mount it into a FastMCP server first and pass that server
- Review the transform's signature — it accepts only FastMCP
Example fix
// before PromptsAsTools(my_provider) // after PromptsAsTools(mcp) # mcp is your FastMCP server
Defensive patterns
Strategy: type-guard
Validate before calling
from fastmcp.server.server import FastMCP assert isinstance(mcp, FastMCP), "PromptsAsTools needs a FastMCP server"
Type guard
def is_fastmcp(obj) -> bool:
from fastmcp.server.server import FastMCP
return isinstance(obj, FastMCP) Try / catch
try:
t = PromptsAsTools(mcp)
except TypeError as e:
logger.error("bad transform arg: %s", e) Prevention
- Always pass the FastMCP instance (mcp), not a provider
- Check transform constructors' expected types
- Mount plain providers into a server before transforming
When it happens
Trigger: PromptsAsTools(some_provider) where some_provider is not a FastMCP server — e.g., passing a Provider, a transform, or a mounted provider.
Common situations: Confusing PromptsAsTools with providers that accept Provider arguments; wiring transforms in a pipeline and passing the wrong object.
Related errors
- Expected Prompt or @prompt-decorated function, got
- Invalid first argument
- messages[ ] must be Message, got . Use Message( ) to wrap…
- messages[ ] must be Message or str, got . Use Message( ) to…
- messages must be str or list[Message], got
AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29).
Data as JSON: /api/errors/fc193ef70fc59371.
Report an issue: GitHub.
Appendix: source
Thrown at fastmcp_slim/fastmcp/server/transforms/prompts_as_tools.py:64
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.
Example:
```python
mcp = FastMCP("Server")
mcp.add_transform(PromptsAsTools(mcp))
# Now has list_prompts and get_prompt tools
```
"""
def __init__(self, provider: Provider) -> None:
from fastmcp.server.server import FastMCP
if not isinstance(provider, FastMCP):
raise TypeError(
"PromptsAsTools requires a FastMCP server instance, not a"
f" {type(provider).__name__}. The generated tools route through"
" the server's middleware chain at runtime for auth and"
" visibility. Pass your FastMCP server: PromptsAsTools(mcp)"
)
self._provider = provider
def __repr__(self) -> str:
return f"PromptsAsTools({self._provider!r})"
async def list_tools(self, tools: Sequence[Tool]) -> Sequence[Tool]:
"""Add prompt tools to the tool list."""
return [
*tools,
self._make_list_prompts_tool(),
self._make_get_prompt_tool(),
]
View on GitHub (pinned to 1f02114297)