{"record":{"id":"210e4c2343e9e050","repo":"microsoft/semantic-kernel","slug":"prompt-name-is-required","errorCode":null,"errorMessage":"Prompt name is required.","messagePattern":"Prompt name is required\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/samples/Demos/ModelContextProtocolClientServer/MCPServer/Extensions/McpServerBuilderExtensions.cs","lineNumber":202,"sourceCode":"    }\n\n    private static ValueTask<ListPromptsResult> HandleListPromptRequestsAsync(RequestContext<ListPromptsRequestParams> context, CancellationToken cancellationToken)\n    {\n        // Get and return all prompt definitions registered in the DI container\n        IEnumerable<PromptDefinition> promptDefinitions = context.Server.Services!.GetServices<PromptDefinition>();\n\n        return ValueTask.FromResult(new ListPromptsResult\n        {\n            Prompts = [.. promptDefinitions.Select(d => d.Prompt)]\n        });\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    {","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/samples/Demos/ModelContextProtocolClientServer/MCPServer/Extensions/McpServerBuilderExtensions.cs#L184-L220","documentation":"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.","triggerScenarios":"context.Params is null, or context.Params.Name is null/empty string — i.e. a malformed prompts/get request from the MCP client.","commonSituations":"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.","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."],"exampleFix":"// before\nif (context.Params?.Name is not string { } promptName || string.IsNullOrEmpty(promptName))\n{\n    throw new ArgumentException(\"Prompt name is required.\");\n}\n\n// after (return structured MCP error instead of throwing)\nif (string.IsNullOrEmpty(context.Params?.Name))\n{\n    return new ValueTask<GetPromptResult>(\n        Task.FromResult(new GetPromptResult { /* IsError = true with message */ }));\n}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(context.Params?.Name))\n    return BadRequestError(\"prompts/get requires a non-empty 'name'.\");","typeGuard":"static bool HasPromptName(GetPromptRequestParams? p) =>\n    !string.IsNullOrEmpty(p?.Name);","tryCatchPattern":"try { return await HandleGetPromptRequestsAsync(context, ct); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Prompt name is required\"))\n{ return McpError(-32602, ex.Message); }","preventionTips":["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."],"tags":["mcp","validation","server","prompts"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}