microsoft/semantic-kernel · error · FunctionExecutionException
Failed to call prompt '{prompt_name}'.
Error message
Failed to call prompt '{prompt_name}'. What it means
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.
Source
Thrown at python/semantic_kernel/connectors/mcp.py:640
raise FunctionExecutionException(f"Failed to call tool '{tool_name}'.") from ex
async def get_prompt(self, prompt_name: str, **kwargs: Any) -> list[ChatMessageContent]:
"""Call a prompt with the given arguments."""
if not self.session:
raise KernelPluginInvalidConfigurationError(
"MCP server not connected, please call connect() before using this method."
)
if not self.load_prompts_flag:
raise KernelPluginInvalidConfigurationError(
"Prompts are not loaded for this server, please set load_prompts=True in the constructor."
)
try:
prompt_result = await self.session.get_prompt(prompt_name, arguments=kwargs)
return [_mcp_prompt_message_to_kernel_content(message) for message in prompt_result.messages]
except McpError:
raise
except Exception as ex:
raise FunctionExecutionException(f"Failed to call prompt '{prompt_name}'.") from ex
def added_to_kernel(self, kernel: Kernel) -> None:
"""Add the plugin to the kernel."""
self.kernel = kernel
# region: MCP Plugin Implementations
class MCPStdioPlugin(MCPPluginBase):
"""MCP stdio server configuration."""
def __init__(
self,
name: str,
command: str,
*,
load_tools: bool = True,View on GitHub (pinned to c028a0c7dc)
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.
Example fix
# before
await plugin.get_prompt("summary", text=obj) # non-serializable arg
# after
try:
await plugin.get_prompt("summary", text=str(obj))
except FunctionExecutionException as ex:
log.error("prompt failed: %s", ex.__cause__) Defensive patterns
Strategy: try-catch
Validate before calling
# confirm prompt args match the prompt's declared arguments before calling
def prompt_args_valid(args: dict, prompt_arguments: list) -> bool:
names = {a.name for a in (prompt_arguments or [])}
return set(args.keys()) <= names Type guard
import json
def args_are_json_serializable(args: dict) -> bool:
try:
json.dumps(args)
return True
except TypeError:
return False Try / catch
from semantic_kernel.exceptions.function_exceptions import FunctionExecutionException
from mcp.shared.exceptions import McpError
try:
await plugin.get_prompt("summary", text="x")
except McpError:
raise
except FunctionExecutionException as ex:
log.error("get_prompt failed: %r", ex.__cause__)
# check timeout / arg serialization, then retry Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Network drop mid-call; timeout too short for a prompt that triggers heavy server work; argument schema mismatch; server process crashed during prompt rendering.
Related errors
- Failed to call tool '{tool_name}'.
- Timeout waiting for OAuth callback
- Unsupported content type: {type(content)}
- Failed to enter context manager.
- Prompts are not loaded for this server, please set load_prom
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/c16c84eb5c4025b8.
Report an issue: GitHub.