PrefectHQ/fastmcp · error · RuntimeError
Unexpected CreateTaskResult: Context calls should not have t
Error message
Unexpected CreateTaskResult: Context calls should not have task metadata
What it means
Context.get_prompt renders a prompt internally and asserts the result is not a CreateTaskResult (a task-metadata wrapper used by task-augmented requests). Context-initiated calls are plain, synchronous-style requests and can never carry task metadata; if one appears it indicates an internal contract violation, so a RuntimeError is raised.
Source
Thrown at fastmcp_slim/fastmcp/server/context.py:588
call_handler=self.fastmcp._on_list_prompts,
extract_items=lambda result: result.prompts,
)
async def get_prompt(
self, name: str, arguments: dict[str, Any] | None = None
) -> GetPromptResult:
"""Get a prompt by name with optional arguments.
Args:
name: The name of the prompt to get
arguments: Optional arguments to pass to the prompt
Returns:
The prompt result
"""
result = await self.fastmcp.render_prompt(name, arguments)
if isinstance(result, mcp_types.CreateTaskResult):
raise RuntimeError(
"Unexpected CreateTaskResult: Context calls should not have task metadata"
)
return result.to_mcp_prompt_result()
async def read_resource(self, uri: str | AnyUrl) -> ResourceResult:
"""Read a resource by URI.
Args:
uri: Resource URI to read
Returns:
ResourceResult with contents
"""
result = await self.fastmcp.read_resource(str(uri))
if isinstance(result, mcp_types.CreateTaskResult):
raise RuntimeError(
"Unexpected CreateTaskResult: Context calls should not have task metadata"
)View on GitHub (pinned to 1f02114297)
Solutions
- Do not override render_prompt or the internal result path; let Context.get_prompt call the default implementation.
- Upgrade/align fastmcp and the mcp SDK to matching versions so internal results are not task-wrapped.
- If you need task-augmented behavior, use the public task APIs on the client/request layer, not Context.get_prompt.
- Catch RuntimeError only as a last-resort guard and re-inspect the prompt registration.
Defensive patterns
Strategy: try-catch
Type guard
def is_task_result(r) -> bool:
return isinstance(r, mcp_types.CreateTaskResult) Try / catch
try:
pr = await ctx.get_prompt("name", {"arg": "v"})
except RuntimeError as e:
if "CreateTaskResult" in str(e):
logging.error("internal task metadata leaked into prompt read: %s", e)
raise Prevention
- Keep fastmcp and the mcp SDK versions aligned (uv lock/uv sync).
- Do not override render_prompt or wrap its return value.
- Use the public task APIs for task-augmented flows instead of Context.get_prompt.
When it happens
Trigger: Calling ctx.get_prompt(name, arguments) when the underlying fastmcp.render_prompt unexpectedly returns an mcp_types.CreateTaskResult — effectively only through internal misconfiguration or a version mismatch where the prompt was resolved through a task-augmented path.
Common situations: Running code written against a different FastMCP/MCP SDK version where task metadata started leaking into internal results; custom subclass overrides of render_prompt that wrap results in CreateTaskResult.
Related errors
- FastMCP instance is no longer available
- request_id is not available because the MCP session has not
- session_id is not available because no session exists. This
- session is not available because the MCP session has not bee
- messages[{i}] must be Message, got {type(item).__name__}. Us
AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29).
Data as JSON: /api/errors/6097d44d260012cc.
Report an issue: GitHub.