{"record":{"id":"638ebc2b794f957e","repo":"linshenkx/prompt-optimizer","slug":"prompt-must-not-exceed-50-000-characters","errorCode":null,"errorMessage":"Prompt must not exceed 50,000 characters","messagePattern":"Prompt must not exceed 50,000 characters","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mcp-server/src/adapters/parameter-adapter.ts","lineNumber":16,"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   */\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');","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/mcp-server/src/adapters/parameter-adapter.ts#L1-L34","documentation":"ParameterAdapter.validatePrompt throws this when prompt.length exceeds 50,000 characters. It is a hard limit on the prompt input to the MCP server, applied after the non-empty check and before any processing.","triggerScenarios":"Calling the MCP prompt endpoint with a prompt longer than 50,000 characters — e.g. pasting an entire file, concatenating many documents, or stuffing conversation history into the prompt field.","commonSituations":"RAG-style integrations inlining large documents into the prompt instead of a separate context parameter; prompt templates that loop-append content; logs/dumps accidentally concatenated into the prompt.","solutions":["Truncate or chunk the prompt before sending (keep under 50k chars)","Move large reference content into a dedicated document/context parameter if the tool provides one","Summarize long input with a cheap pre-pass before the main call"],"exampleFix":"// before\nawait tool.call({ prompt: entireFile });\n\n// after\nconst MAX = 50000;\nawait tool.call({ prompt: entireFile.slice(0, MAX) });","handlingStrategy":"validation","validationCode":"const MAX_PROMPT = 50000;\nif (prompt.length > MAX_PROMPT) prompt = prompt.slice(0, MAX_PROMPT);","typeGuard":"const isWithinPromptLimit = (p: string): boolean => p.length <= 50000;","tryCatchPattern":"try { await call({ prompt }); } catch (e) { if ((e as Error).message.includes('50,000')) { prompt = prompt.slice(0, 50000); await call({ prompt }); } else throw e; }","preventionTips":["Enforce the 50k limit in the client UI with a character counter","Chunk or summarize large documents before inlining"],"tags":["validation","input-validation","prompt","limit"],"backgroundTag":"request-payload-too-large","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}