{"record":{"id":"6097d44d260012cc","repo":"PrefectHQ/fastmcp","slug":"unexpected-createtaskresult-context-calls-should","errorCode":null,"errorMessage":"Unexpected CreateTaskResult: Context calls should not have task metadata","messagePattern":"Unexpected CreateTaskResult: Context calls should not have task metadata","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/server/context.py","lineNumber":588,"sourceCode":"            call_handler=self.fastmcp._on_list_prompts,\n            extract_items=lambda result: result.prompts,\n        )\n\n    async def get_prompt(\n        self, name: str, arguments: dict[str, Any] | None = None\n    ) -> GetPromptResult:\n        \"\"\"Get a prompt by name with optional arguments.\n\n        Args:\n            name: The name of the prompt to get\n            arguments: Optional arguments to pass to the prompt\n\n        Returns:\n            The prompt result\n        \"\"\"\n        result = await self.fastmcp.render_prompt(name, arguments)\n        if isinstance(result, mcp_types.CreateTaskResult):\n            raise RuntimeError(\n                \"Unexpected CreateTaskResult: Context calls should not have task metadata\"\n            )\n        return result.to_mcp_prompt_result()\n\n    async def read_resource(self, uri: str | AnyUrl) -> ResourceResult:\n        \"\"\"Read a resource by URI.\n\n        Args:\n            uri: Resource URI to read\n\n        Returns:\n            ResourceResult with contents\n        \"\"\"\n        result = await self.fastmcp.read_resource(str(uri))\n        if isinstance(result, mcp_types.CreateTaskResult):\n            raise RuntimeError(\n                \"Unexpected CreateTaskResult: Context calls should not have task metadata\"\n            )","sourceCodeStart":570,"sourceCodeEnd":606,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/server/context.py#L570-L606","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"def is_task_result(r) -> bool:\n    return isinstance(r, mcp_types.CreateTaskResult)","tryCatchPattern":"try:\n    pr = await ctx.get_prompt(\"name\", {\"arg\": \"v\"})\nexcept RuntimeError as e:\n    if \"CreateTaskResult\" in str(e):\n        logging.error(\"internal task metadata leaked into prompt read: %s\", e)\n    raise","preventionTips":["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."],"tags":["python","context","prompts","internal-error","runtimeerror"],"backgroundTag":"unexpected-internal-result-type","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}