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

Method validateToolParams

packages/core/src/tools/shell.ts:365–409  ·  view source on GitHub ↗
(
    params: ShellToolParams,
  )

Source from the content-addressed store, hash-verified

363 }
364
365 protected override validateToolParams(
366 params: ShellToolParams,
367 ): string | null {
368 const commandCheck = isCommandAllowed(params.command, this.config);
369 if (!commandCheck.allowed) {
370 if (!commandCheck.reason) {
371 console.error(
372 'Unexpected: isCommandAllowed returned false without a reason',
373 );
374 return `Command is not allowed: ${params.command}`;
375 }
376 return commandCheck.reason;
377 }
378 const errors = SchemaValidator.validate(
379 this.schema.parametersJsonSchema,
380 params,
381 );
382 if (errors) {
383 return errors;
384 }
385 if (!params.command.trim()) {
386 return 'Command cannot be empty.';
387 }
388 if (getCommandRoots(params.command).length === 0) {
389 return 'Could not identify command root to obtain permission from user.';
390 }
391 if (params.directory) {
392 if (path.isAbsolute(params.directory)) {
393 return 'Directory cannot be absolute. Please refer to workspace directories by their name.';
394 }
395 const workspaceDirs = this.config.getWorkspaceContext().getDirectories();
396 const matchingDirs = workspaceDirs.filter(
397 (dir) => path.basename(dir) === params.directory,
398 );
399
400 if (matchingDirs.length === 0) {
401 return `Directory '${params.directory}' is not a registered workspace directory.`;
402 }
403
404 if (matchingDirs.length > 1) {
405 return `Directory name '${params.directory}' is ambiguous as it matches multiple workspace directories.`;
406 }
407 }
408 return null;
409 }
410
411 protected createInvocation(
412 params: ShellToolParams,

Callers

nothing calls this directly

Calls 5

isCommandAllowedFunction · 0.85
getCommandRootsFunction · 0.85
validateMethod · 0.80
getDirectoriesMethod · 0.80
getWorkspaceContextMethod · 0.80

Tested by

no test coverage detected