{"record":{"id":"16d1375906aa23a5","repo":"linshenkx/prompt-optimizer","slug":"prompt-must-be-a-non-empty-string","errorCode":null,"errorMessage":"Prompt must be a non-empty string","messagePattern":"Prompt must be a non-empty string","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mcp-server/src/adapters/parameter-adapter.ts","lineNumber":13,"sourceCode":"/**\n * 参数验证工具\n * 简化的参数验证，移除过度抽象\n */\n\nexport class ParameterValidator {\n\n  /**\n   * 验证提示词输入\n   */\n  static validatePrompt(prompt: string): void {\n    if (!prompt || typeof prompt !== 'string' || prompt.trim().length === 0) {\n      throw new Error('Prompt must be a non-empty string');\n    }\n    if (prompt.length > 50000) {\n      throw new Error('Prompt must not exceed 50,000 characters');\n    }\n  }\n\n  /**\n   * 验证模板输入\n   */\n  static validateTemplate(template?: string): void {\n    if (template !== undefined && (typeof template !== 'string' || template.trim().length === 0)) {\n      throw new Error('Template must be a non-empty string');\n    }\n  }\n\n  /**\n   * 验证需求描述输入\n   */","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/mcp-server/src/adapters/parameter-adapter.ts#L1-L31","documentation":"ParameterAdapter.validatePrompt rejects a prompt argument that is falsy, not a string, or a string containing only whitespace. It runs in the MCP server request handlers, guarding the core prompt input before processing; a second check enforces the 50,000-character maximum.","triggerScenarios":"Calling the MCP tool/prompt endpoint with prompt: '' , prompt: null, prompt: 123 (wrong type), or prompt: '   ' (whitespace only). These typically come from an LLM client constructing tool-call arguments incorrectly.","commonSituations":"An MCP client (Claude, Cursor, custom integration) omitting the prompt field or sending an empty string; templating bugs producing undefined interpolated into the call; schema drift where the client sends a different parameter name so prompt arrives undefined.","solutions":["Ensure the caller always sends a non-empty trimmed string for prompt","Trim/validate client-side before invoking: if (!prompt?.trim()) fix the caller","Check the tool's input schema and the client's argument construction for typos in the parameter name","If undefined is legitimate for your flow, substitute a default prompt string before calling"],"exampleFix":"// before\nawait tool.call({ prompt: userInput }); // userInput may be ''\n\n// after\nawait tool.call({ prompt: (userInput ?? '').trim() || fallbackPrompt });","handlingStrategy":"validation","validationCode":"if (typeof prompt !== 'string' || prompt.trim().length === 0) {\n  throw new Error('client-side: prompt required');\n}","typeGuard":"const isValidPrompt = (p: unknown): p is string =>\n  typeof p === 'string' && p.trim().length > 0;","tryCatchPattern":"try {\n  await server.callTool('prompt', { prompt });\n} catch (e) {\n  if ((e as Error).message.includes('Prompt must be a non-empty string')) {\n    return { error: 'Please provide a prompt' };\n  }\n  throw e;\n}","preventionTips":["Validate tool inputs client-side with the tool's schema before sending","Trim user input and reject empty submissions in the UI"],"tags":["validation","input-validation","prompt","mcp-server"],"backgroundTag":"required-parameter-missing","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}