microsoft/semantic-kernel · error · ArgumentException
Prompt name is required.
Error message
Prompt name is required.
What it means
In the MCP server's GetPrompt handler, an ArgumentException is thrown when the incoming GetPromptRequestParams.Name is null or empty. This validates the client request before any handler lookup. MCP clients must always send a prompt name with a prompts/get request.
Source
Thrown at dotnet/samples/Demos/ModelContextProtocolClientServer/MCPServer/Extensions/McpServerBuilderExtensions.cs:202
}
private static ValueTask<ListPromptsResult> HandleListPromptRequestsAsync(RequestContext<ListPromptsRequestParams> context, CancellationToken cancellationToken)
{
// Get and return all prompt definitions registered in the DI container
IEnumerable<PromptDefinition> promptDefinitions = context.Server.Services!.GetServices<PromptDefinition>();
return ValueTask.FromResult(new ListPromptsResult
{
Prompts = [.. promptDefinitions.Select(d => d.Prompt)]
});
}
private static async ValueTask<GetPromptResult> HandleGetPromptRequestsAsync(RequestContext<GetPromptRequestParams> context, CancellationToken cancellationToken)
{
// Make sure the prompt name is provided
if (context.Params?.Name is not string { } promptName || string.IsNullOrEmpty(promptName))
{
throw new ArgumentException("Prompt name is required.");
}
// Get all prompt definitions registered in the DI container
IEnumerable<PromptDefinition> promptDefinitions = context.Server.Services!.GetServices<PromptDefinition>();
// Look up the prompt definition
PromptDefinition? definition = promptDefinitions.FirstOrDefault(d => d.Prompt.Name == promptName);
if (definition is null)
{
throw new ArgumentException($"No handler found for the prompt '{promptName}'.");
}
// Invoke the handler
return await definition.Handler(context, cancellationToken);
}
private static ValueTask<ReadResourceResult> HandleReadResourceRequestAsync(RequestContext<ReadResourceRequestParams> context, CancellationToken cancellationToken)
{View on GitHub (pinned to c028a0c7dc)
Solutions
- Ensure the client always includes a non-empty `name` in the prompts/get params.
- Upgrade/fix the client SDK so it always sends the name.
- If you control the server, return an MCP-level error response instead of throwing an unhandled ArgumentException.
Example fix
// before
if (context.Params?.Name is not string { } promptName || string.IsNullOrEmpty(promptName))
{
throw new ArgumentException("Prompt name is required.");
}
// after (return structured MCP error instead of throwing)
if (string.IsNullOrEmpty(context.Params?.Name))
{
return new ValueTask<GetPromptResult>(
Task.FromResult(new GetPromptResult { /* IsError = true with message */ }));
} Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(context.Params?.Name))
return BadRequestError("prompts/get requires a non-empty 'name'."); Type guard
static bool HasPromptName(GetPromptRequestParams? p) =>
!string.IsNullOrEmpty(p?.Name); Try / catch
try { return await HandleGetPromptRequestsAsync(context, ct); }
catch (ArgumentException ex) when (ex.Message.Contains("Prompt name is required"))
{ return McpError(-32602, ex.Message); } Prevention
- Always include a non-empty name in prompts/get from the client.
- Translate validation throws into MCP-level error responses on the server.
- Validate params client-side before sending.
When it happens
Trigger: context.Params is null, or context.Params.Name is null/empty string — i.e. a malformed prompts/get request from the MCP client.
Common situations: A buggy/custom MCP client that omits the name field, an SDK version that serializes the field differently, or a manual JSON-RPC call missing the name.
Related errors
- No handler found for the prompt '{promptName}'.
- Resource uri is required.
- No handler found for the resource uri '{resourceUri}'.
- Invalid choice
- Invalid kernel selection. {selectedKernelName} is not a vali
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/210e4c2343e9e050.
Report an issue: GitHub.