{"record":{"id":"17ea344f47ce40d9","repo":"linshenkx/prompt-optimizer","slug":"requirements-must-be-a-non-empty-string","errorCode":null,"errorMessage":"Requirements must be a non-empty string","messagePattern":"Requirements must be a non-empty string","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mcp-server/src/adapters/parameter-adapter.ts","lineNumber":34,"sourceCode":"      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   */\n  static validateRequirements(requirements: string): void {\n    if (!requirements || typeof requirements !== 'string' || requirements.trim().length === 0) {\n      throw new Error('Requirements must be a non-empty string');\n    }\n    if (requirements.length > 10000) {\n      throw new Error('Requirements must not exceed 10,000 characters');\n    }\n  }\n}\n","sourceCodeStart":16,"sourceCodeEnd":41,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/mcp-server/src/adapters/parameter-adapter.ts#L16-L41","documentation":"ParameterAdapter.validateRequirements rejects a requirements argument that is falsy, not a string, or whitespace-only. It mirrors validatePrompt but for the requirements (需求描述) input, and is enforced by the MCP server handlers before processing.","triggerScenarios":"Calling a tool that requires requirements with requirements: '', null, a non-string value, or only whitespace. Clients that treat requirements as optional will hit this because the validator requires a non-empty string.","commonSituations":"Tool schema marks requirements required but the client omits it; a form field left blank producing ''; parameter-name drift so requirements arrives undefined.","solutions":["Always supply a non-empty trimmed requirements string","Validate client-side: if (!requirements?.trim()) prompt the user for input","Check the tool schema to confirm whether requirements is required for the specific endpoint you call"],"exampleFix":"// before\nawait tool.call({ requirements: spec ?? '' });\n\n// after\nif (!spec?.trim()) throw new Error('requirements is required');\nawait tool.call({ requirements: spec.trim() });","handlingStrategy":"validation","validationCode":"if (!requirements?.trim()) throw new Error('client-side: requirements required');","typeGuard":"const isValidRequirements = (r: unknown): r is string =>\n  typeof r === 'string' && r.trim().length > 0;","tryCatchPattern":"try { await call({ requirements }); } catch (e) { if ((e as Error).message.includes('Requirements must be a non-empty')) return { error: 'requirements missing' }; throw e; }","preventionTips":["Check the tool schema to know which params are required","Reject blank requirements fields in forms before submission"],"tags":["validation","input-validation","requirements","mcp-server"],"backgroundTag":"required-parameter-missing","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}