MCPcopy Index your code
hub / github.com/anus-dev/ANUS / validateToolParams

Method validateToolParams

packages/core/src/tools/write-file.ts:417–460  ·  view source on GitHub ↗
(
    params: WriteFileToolParams,
  )

Source from the content-addressed store, hash-verified

415 }
416
417 protected override validateToolParams(
418 params: WriteFileToolParams,
419 ): string | null {
420 const errors = SchemaValidator.validate(
421 this.schema.parametersJsonSchema,
422 params,
423 );
424 if (errors) {
425 return errors;
426 }
427
428 const filePath = params.file_path;
429
430 if (!filePath) {
431 return `Missing or empty "file_path"`;
432 }
433
434 if (!path.isAbsolute(filePath)) {
435 return `File path must be absolute: ${filePath}`;
436 }
437
438 const workspaceContext = this.config.getWorkspaceContext();
439 if (!workspaceContext.isPathWithinWorkspace(filePath)) {
440 const directories = workspaceContext.getDirectories();
441 return `File path must be within one of the workspace directories: ${directories.join(
442 ', ',
443 )}`;
444 }
445
446 try {
447 if (fs.existsSync(filePath)) {
448 const stats = fs.lstatSync(filePath);
449 if (stats.isDirectory()) {
450 return `Path is a directory, not a file: ${filePath}`;
451 }
452 }
453 } catch (statError: unknown) {
454 return `Error accessing path properties for validation: ${filePath}. Reason: ${
455 statError instanceof Error ? statError.message : String(statError)
456 }`;
457 }
458
459 return null;
460 }
461
462 protected createInvocation(
463 params: WriteFileToolParams,

Callers

nothing calls this directly

Calls 4

validateMethod · 0.80
getWorkspaceContextMethod · 0.80
isPathWithinWorkspaceMethod · 0.80
getDirectoriesMethod · 0.80

Tested by

no test coverage detected