{"record":{"id":"99ed4936d2f7a6f6","repo":"upstash/context7","slug":"invalid-mcp-max-subscriptions-using-the-default-o","errorCode":null,"errorMessage":"Invalid MCP_MAX_SUBSCRIPTIONS; using the default of ${DEFAULT_MAX_SUBSCRIPTIONS}.","messagePattern":"Invalid MCP_MAX_SUBSCRIPTIONS; using the default of (.+?)\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/mcp/src/lib/subscriptions.ts","lineNumber":10,"sourceCode":"// 16k stayed near baseline latency in Docker; 32,768 raised tools/list p95 to ~39 ms.\nexport const DEFAULT_MAX_SUBSCRIPTIONS = 16_000;\n\nexport function getMaxSubscriptions(value = process.env.MCP_MAX_SUBSCRIPTIONS): number {\n  if (value === undefined) return DEFAULT_MAX_SUBSCRIPTIONS;\n\n  const parsed = Number(value);\n  if (Number.isSafeInteger(parsed) && parsed > 0) return parsed;\n\n  console.warn(`Invalid MCP_MAX_SUBSCRIPTIONS; using the default of ${DEFAULT_MAX_SUBSCRIPTIONS}.`);\n  return DEFAULT_MAX_SUBSCRIPTIONS;\n}\n","sourceCodeStart":1,"sourceCodeEnd":13,"githubUrl":"https://github.com/upstash/context7/blob/c05c71c5fddf9ff4b1a128752fc04a1fce73360e/packages/mcp/src/lib/subscriptions.ts#L1-L13","documentation":"This is a console warning (not a thrown exception) emitted by getMaxSubscriptions() in packages/mcp/src/lib/subscriptions.ts when the MCP_MAX_SUBSCRIPTIONS environment variable is set but cannot be parsed as a positive safe integer. The function falls back to DEFAULT_MAX_SUBSCRIPTIONS and continues, so subscriptions still work but the custom limit is ignored. It exists to surface misconfiguration instead of silently accepting a bad value.","triggerScenarios":"Setting MCP_MAX_SUBSCRIPTIONS to a non-numeric string (e.g. 'ten'), a zero or negative number (e.g. '0', '-5'), a decimal (e.g. '2.5' → NaN-safe check fails since Number.isSafeInteger(2.5) is false), or an out-of-range/Infinity value, then calling getMaxSubscriptions() (indirectly via mcpHandler).","commonSituations":"Typo or quoting mistakes in .env / docker-compose / CI environment files; YAML or shell configs quoting the value as a string with stray characters ('10\\n', '\"10\"' is fine but '10 ' may parse oddly); Kubernetes ConfigMap values with whitespace; someone setting the var to a percentage or descriptive word expecting it to be interpreted.","solutions":["Set MCP_MAX_SUBSCRIPTIONS to a whole positive integer string, e.g. MCP_MAX_SUBSCRIPTIONS=1000","Unset/delete MCP_MAX_SUBSCRIPTIONS entirely if the default limit is acceptable","Trim whitespace and remove quotes/suffixes from the value in your env file or secret manager","In code, pre-validate with Number.isSafeInteger(Number(value)) && Number(value) > 0 before relying on the env var"],"exampleFix":"// before (.env)\nMCP_MAX_SUBSCRIPTIONS=1000x\n\n// after (.env)\nMCP_MAX_SUBSCRIPTIONS=1000","handlingStrategy":"validation","validationCode":"function isValidMaxSubscriptions(value) {\n  const n = Number(value);\n  return Number.isSafeInteger(n) && n > 0;\n}\nconst raw = process.env.MCP_MAX_SUBSCRIPTIONS;\nif (raw !== undefined && !isValidMaxSubscriptions(raw)) {\n  throw new Error(`MCP_MAX_SUBSCRIPTIONS must be a positive integer, got: ${raw}`);\n}","typeGuard":"function isPositiveSafeInt(value: unknown): value is number {\n  return typeof value === 'number'\n    ? Number.isSafeInteger(value) && value > 0\n    : typeof value === 'string' && /^\\d+$/.test(value.trim()) && Number.isSafeInteger(Number(value)) && Number(value) > 0;\n}","tryCatchPattern":null,"preventionTips":["Validate environment variables at process startup with a schema library (e.g. zod) so bad values fail fast","Always store numeric env vars as unquoted plain integers in .env / deployment configs","Check container/CI logs for this warning when bumping subscription limits — it indicates the new value was ignored","Add a startup assertion or smoke test that reads the resolved limit via getMaxSubscriptions() and asserts it matches the intended value"],"tags":["configuration","environment-variables","validation","fallback","mcp"],"backgroundTag":"invalid-env-var-value","analyzedSha":"c05c71c5fddf9ff4b1a128752fc04a1fce73360e","analyzedAt":"2026-09-02T01:01:18.365Z","contentChangedAt":"2026-09-02T01:01:18.365Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}