microsoft/semantic-kernel · error · ArgumentException
No handler found for the prompt '{promptName}'.
Error message
No handler found for the prompt '{promptName}'. What it means
After validating the prompt name, the handler looks up a registered PromptDefinition whose Prompt.Name matches; if none is found it throws ArgumentException naming the missing prompt. So the request was well-formed but asked for a prompt the server did not register.
Source
Thrown at dotnet/samples/Demos/ModelContextProtocolClientServer/MCPServer/Extensions/McpServerBuilderExtensions.cs:212
});
}
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)
{
// Make sure the uri of the resource or resource template is provided
if (context.Params?.Uri is not string { } resourceUri || string.IsNullOrEmpty(resourceUri))
{
throw new ArgumentException("Resource uri is required.");
}
// Look up in registered resource first
IEnumerable<ResourceDefinition> resourceDefinitions = context.Server.Services!.GetServices<ResourceDefinition>();
ResourceDefinition? resourceDefinition = resourceDefinitions.FirstOrDefault(d => d.Resource.Uri == resourceUri);View on GitHub (pinned to c028a0c7dc)
Solutions
- Call prompts/list first to discover actually-registered prompt names and use one of those.
- Verify the server registers the desired PromptDefinition at startup.
- Check for case/exact-match issues — lookup is an exact Name equality.
- Return an MCP-level not-found error rather than throwing, if you control the server.
Example fix
// before
PromptDefinition? definition = promptDefinitions.FirstOrDefault(d => d.Prompt.Name == promptName);
if (definition is null)
{
throw new ArgumentException($"No handler found for the prompt '{promptName}'.");
}
// after (case-insensitive + structured response)
var definition = promptDefinitions.FirstOrDefault(d =>
string.Equals(d.Prompt.Name, promptName, StringComparison.OrdinalIgnoreCase));
if (definition is null)
{
return new ValueTask<GetPromptResult>(
Task.FromResult(new GetPromptResult { /* IsError, message lists available names */ }));
} Defensive patterns
Strategy: try-catch
Validate before calling
var known = promptDefinitions.Select(d => d.Prompt.Name).ToList();
if (!known.Contains(promptName, StringComparer.Ordinal))
return NotFoundError($"Unknown prompt '{promptName}'. Known: {string.Join(", ", known)}"); Type guard
static bool PromptExists(IEnumerable<PromptDefinition> defs, string name) =>
defs.Any(d => string.Equals(d.Prompt.Name, name, StringComparison.Ordinal)); Try / catch
try { return await definition.Handler(context, ct); }
catch (ArgumentException ex) when (ex.Message.Contains("No handler found for the prompt"))
{ return McpError(-32602, ex.Message); } Prevention
- Call prompts/list first to get valid names.
- Use exact name matching; consider case-insensitive lookup.
- Ensure desired prompts are registered at server startup.
When it happens
Trigger: Client requests a prompt name that has no matching PromptDefinition registered in the DI container (FirstOrDefault returns null).
Common situations: Client asks for a prompt that exists on another server, a typo in the prompt name, or the server failed to register the prompt at startup.
Related errors
- Prompt name is required.
- No handler found for the resource uri '{resourceUri}'.
- Resource uri is required.
- Plugin creation failed for {pluginName}
- The client does not support sampling.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/f0a15619637abf38.
Report an issue: GitHub.