{"record":{"id":"c16c84eb5c4025b8","repo":"microsoft/semantic-kernel","slug":"failed-to-call-prompt-prompt-name","errorCode":null,"errorMessage":"Failed to call prompt '{prompt_name}'.","messagePattern":"Failed to call prompt '(.+?)'\\.","errorType":"exception","errorClass":"FunctionExecutionException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/mcp.py","lineNumber":640,"sourceCode":"            raise FunctionExecutionException(f\"Failed to call tool '{tool_name}'.\") from ex\n\n    async def get_prompt(self, prompt_name: str, **kwargs: Any) -> list[ChatMessageContent]:\n        \"\"\"Call a prompt with the given arguments.\"\"\"\n        if not self.session:\n            raise KernelPluginInvalidConfigurationError(\n                \"MCP server not connected, please call connect() before using this method.\"\n            )\n        if not self.load_prompts_flag:\n            raise KernelPluginInvalidConfigurationError(\n                \"Prompts are not loaded for this server, please set load_prompts=True in the constructor.\"\n            )\n        try:\n            prompt_result = await self.session.get_prompt(prompt_name, arguments=kwargs)\n            return [_mcp_prompt_message_to_kernel_content(message) for message in prompt_result.messages]\n        except McpError:\n            raise\n        except Exception as ex:\n            raise FunctionExecutionException(f\"Failed to call prompt '{prompt_name}'.\") from ex\n\n    def added_to_kernel(self, kernel: Kernel) -> None:\n        \"\"\"Add the plugin to the kernel.\"\"\"\n        self.kernel = kernel\n\n\n# region: MCP Plugin Implementations\n\n\nclass MCPStdioPlugin(MCPPluginBase):\n    \"\"\"MCP stdio server configuration.\"\"\"\n\n    def __init__(\n        self,\n        name: str,\n        command: str,\n        *,\n        load_tools: bool = True,","sourceCodeStart":622,"sourceCodeEnd":658,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/mcp.py#L622-L658","documentation":"Thrown by MCPPluginBase.get_prompt (mcp.py:640) as a FunctionExecutionException, wrapping any non-McpError exception raised by self.session.get_prompt. McpError instances are re-raised unchanged (structured MCP errors); transport/timeout/serialization failures are wrapped with the prompt_name for context.","triggerScenarios":"The MCP server's get_prompt raised a non-MCP exception, the network failed, request_timeout elapsed, or the prompt arguments could not be serialized. Originates at mcp.py:636-641.","commonSituations":"Network drop mid-call; timeout too short for a prompt that triggers heavy server work; argument schema mismatch; server process crashed during prompt rendering.","solutions":["Inspect the chained __cause__ for the underlying error.","Increase request_timeout if the prompt is slow to render.","Verify kwargs match the prompt's declared arguments (see _get_parameter_dict_from_mcp_prompt).","Catch FunctionExecutionException separately from McpError to distinguish transport errors from structured server errors."],"exampleFix":"# before\nawait plugin.get_prompt(\"summary\", text=obj)  # non-serializable arg\n\n# after\ntry:\n    await plugin.get_prompt(\"summary\", text=str(obj))\nexcept FunctionExecutionException as ex:\n    log.error(\"prompt failed: %s\", ex.__cause__)","handlingStrategy":"try-catch","validationCode":"# confirm prompt args match the prompt's declared arguments before calling\ndef prompt_args_valid(args: dict, prompt_arguments: list) -> bool:\n    names = {a.name for a in (prompt_arguments or [])}\n    return set(args.keys()) <= names","typeGuard":"import json\n\ndef args_are_json_serializable(args: dict) -> bool:\n    try:\n        json.dumps(args)\n        return True\n    except TypeError:\n        return False","tryCatchPattern":"from semantic_kernel.exceptions.function_exceptions import FunctionExecutionException\nfrom mcp.shared.exceptions import McpError\n\ntry:\n    await plugin.get_prompt(\"summary\", text=\"x\")\nexcept McpError:\n    raise\nexcept FunctionExecutionException as ex:\n    log.error(\"get_prompt failed: %r\", ex.__cause__)\n    # check timeout / arg serialization, then retry","preventionTips":["Catch McpError and FunctionExecutionException separately.","Match kwargs to the prompt's declared arguments (see _get_parameter_dict_from_mcp_prompt).","Size request_timeout to the slowest prompt.","Inspect __cause__ for the underlying error.","Serialize all arguments to JSON-compatible types before calling."],"tags":["mcp","get-prompt","timeout","error-wrapping","function-execution"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}