{"record":{"id":"f0a15619637abf38","repo":"microsoft/semantic-kernel","slug":"no-handler-found-for-the-prompt-promptname","errorCode":null,"errorMessage":"No handler found for the prompt '{promptName}'.","messagePattern":"No handler found for the prompt '(.+?)'\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/Demos/ModelContextProtocolClientServer/MCPServer/Extensions/McpServerBuilderExtensions.cs","lineNumber":212,"sourceCode":"        });\n    }\n\n    private static async ValueTask<GetPromptResult> HandleGetPromptRequestsAsync(RequestContext<GetPromptRequestParams> context, CancellationToken cancellationToken)\n    {\n        // Make sure the prompt name is provided\n        if (context.Params?.Name is not string { } promptName || string.IsNullOrEmpty(promptName))\n        {\n            throw new ArgumentException(\"Prompt name is required.\");\n        }\n\n        // Get all prompt definitions registered in the DI container\n        IEnumerable<PromptDefinition> promptDefinitions = context.Server.Services!.GetServices<PromptDefinition>();\n\n        // Look up the prompt definition\n        PromptDefinition? definition = promptDefinitions.FirstOrDefault(d => d.Prompt.Name == promptName);\n        if (definition is null)\n        {\n            throw new ArgumentException($\"No handler found for the prompt '{promptName}'.\");\n        }\n\n        // Invoke the handler\n        return await definition.Handler(context, cancellationToken);\n    }\n\n    private static ValueTask<ReadResourceResult> HandleReadResourceRequestAsync(RequestContext<ReadResourceRequestParams> context, CancellationToken cancellationToken)\n    {\n        // Make sure the uri of the resource or resource template is provided\n        if (context.Params?.Uri is not string { } resourceUri || string.IsNullOrEmpty(resourceUri))\n        {\n            throw new ArgumentException(\"Resource uri is required.\");\n        }\n\n        // Look up in registered resource first\n        IEnumerable<ResourceDefinition> resourceDefinitions = context.Server.Services!.GetServices<ResourceDefinition>();\n\n        ResourceDefinition? resourceDefinition = resourceDefinitions.FirstOrDefault(d => d.Resource.Uri == resourceUri);","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/Demos/ModelContextProtocolClientServer/MCPServer/Extensions/McpServerBuilderExtensions.cs#L194-L230","documentation":"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.","triggerScenarios":"Client requests a prompt name that has no matching PromptDefinition registered in the DI container (FirstOrDefault returns null).","commonSituations":"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.","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."],"exampleFix":"// before\nPromptDefinition? definition = promptDefinitions.FirstOrDefault(d => d.Prompt.Name == promptName);\nif (definition is null)\n{\n    throw new ArgumentException($\"No handler found for the prompt '{promptName}'.\");\n}\n\n// after (case-insensitive + structured response)\nvar definition = promptDefinitions.FirstOrDefault(d =>\n    string.Equals(d.Prompt.Name, promptName, StringComparison.OrdinalIgnoreCase));\nif (definition is null)\n{\n    return new ValueTask<GetPromptResult>(\n        Task.FromResult(new GetPromptResult { /* IsError, message lists available names */ }));\n}","handlingStrategy":"try-catch","validationCode":"var known = promptDefinitions.Select(d => d.Prompt.Name).ToList();\nif (!known.Contains(promptName, StringComparer.Ordinal))\n    return NotFoundError($\"Unknown prompt '{promptName}'. Known: {string.Join(\", \", known)}\");","typeGuard":"static bool PromptExists(IEnumerable<PromptDefinition> defs, string name) =>\n    defs.Any(d => string.Equals(d.Prompt.Name, name, StringComparison.Ordinal));","tryCatchPattern":"try { return await definition.Handler(context, ct); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"No handler found for the prompt\"))\n{ return McpError(-32602, ex.Message); }","preventionTips":["Call prompts/list first to get valid names.","Use exact name matching; consider case-insensitive lookup.","Ensure desired prompts are registered at server startup."],"tags":["mcp","prompts","lookup","server"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}