linshenkx/prompt-optimizer · error · Error
Prompt must not exceed 50,000 characters
Error message
Prompt must not exceed 50,000 characters
What it means
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.
Source
Thrown at packages/mcp-server/src/adapters/parameter-adapter.ts:16
/**
* 参数验证工具
* 简化的参数验证,移除过度抽象
*/
export class ParameterValidator {
/**
* 验证提示词输入
*/
static validatePrompt(prompt: string): void {
if (!prompt || typeof prompt !== 'string' || prompt.trim().length === 0) {
throw new Error('Prompt must be a non-empty string');
}
if (prompt.length > 50000) {
throw new Error('Prompt must not exceed 50,000 characters');
}
}
/**
* 验证模板输入
*/
static validateTemplate(template?: string): void {
if (template !== undefined && (typeof template !== 'string' || template.trim().length === 0)) {
throw new Error('Template must be a non-empty string');
}
}
/**
* 验证需求描述输入
*/
static validateRequirements(requirements: string): void {
if (!requirements || typeof requirements !== 'string' || requirements.trim().length === 0) {
throw new Error('Requirements must be a non-empty string');View on GitHub (pinned to 3e677b1d9f)
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
Example fix
// before
await tool.call({ prompt: entireFile });
// after
const MAX = 50000;
await tool.call({ prompt: entireFile.slice(0, MAX) }); Defensive patterns
Strategy: validation
Validate before calling
const MAX_PROMPT = 50000; if (prompt.length > MAX_PROMPT) prompt = prompt.slice(0, MAX_PROMPT);
Type guard
const isWithinPromptLimit = (p: string): boolean => p.length <= 50000;
Try / catch
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; } Prevention
- Enforce the 50k limit in the client UI with a character counter
- Chunk or summarize large documents before inlining
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Prompt must be a non-empty string
- Requirements must not exceed 10,000 characters
- Iteration requirement must not be empty.
- ${label} promptText must not be empty.
- User prompt is required
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/638ebc2b794f957e.
Report an issue: GitHub.