MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / validateUserConfig

Function validateUserConfig

source code/utils/plugins/mcpbHandler.ts:348–410  ·  view source on GitHub ↗
(
  values: UserConfigValues,
  schema: UserConfigSchema,
)

Source from the content-addressed store, hash-verified

346 * Validate user configuration values against DXT user_config schema
347 */
348export function validateUserConfig(
349 values: UserConfigValues,
350 schema: UserConfigSchema,
351): { valid: boolean; errors: string[] } {
352 const errors: string[] = []
353
354 // Check each field in the schema
355 for (const [key, fieldSchema] of Object.entries(schema)) {
356 const value = values[key]
357
358 // Check required fields
359 if (fieldSchema.required && (value === undefined || value === '')) {
360 errors.push(`${fieldSchema.title || key} is required but not provided`)
361 continue
362 }
363
364 // Skip validation for optional fields that aren't provided
365 if (value === undefined || value === '') {
366 continue
367 }
368
369 // Type validation
370 if (fieldSchema.type === 'string') {
371 if (Array.isArray(value)) {
372 // String arrays are allowed if multiple: true
373 if (!fieldSchema.multiple) {
374 errors.push(
375 `${fieldSchema.title || key} must be a string, not an array`,
376 )
377 } else if (!value.every(v => typeof v === 'string')) {
378 errors.push(`${fieldSchema.title || key} must be an array of strings`)
379 }
380 } else if (typeof value !== 'string') {
381 errors.push(`${fieldSchema.title || key} must be a string`)
382 }
383 } else if (fieldSchema.type === 'number' && typeof value !== 'number') {
384 errors.push(`${fieldSchema.title || key} must be a number`)
385 } else if (fieldSchema.type === 'boolean' && typeof value !== 'boolean') {
386 errors.push(`${fieldSchema.title || key} must be a boolean`)
387 } else if (
388 (fieldSchema.type === 'file' || fieldSchema.type === 'directory') &&
389 typeof value !== 'string'
390 ) {
391 errors.push(`${fieldSchema.title || key} must be a path string`)
392 }
393
394 // Number range validation
395 if (fieldSchema.type === 'number' && typeof value === 'number') {
396 if (fieldSchema.min !== undefined && value < fieldSchema.min) {
397 errors.push(
398 `${fieldSchema.title || key} must be at least ${fieldSchema.min}`,
399 )
400 }
401 if (fieldSchema.max !== undefined && value > fieldSchema.max) {
402 errors.push(
403 `${fieldSchema.title || key} must be at most ${fieldSchema.max}`,
404 )
405 }

Callers 3

getUnconfiguredOptionsFunction · 0.70
getUnconfiguredChannelsFunction · 0.70
loadMcpbFileFunction · 0.70

Calls 1

entriesMethod · 0.80

Tested by

no test coverage detected