nexus-agents - v2.80.0
    Preparing search index...

    Function validateToolInput

    MCP exports - MCP server implementation Split from index.ts for file size compliance (Issue #285) Updated Issue #538: Added missing tool registration exports

    • Validates tool input against a Zod schema.

      This function should be called at the start of every tool handler to validate incoming arguments before processing.

      Type Parameters

      • T

        The expected type after validation

      Parameters

      • schema: ZodType<T>

        The Zod schema to validate against

      • args: unknown

        The unknown input to validate

      Returns Result<T, ValidationError>

      Result containing validated data or a ValidationError

      const InputSchema = z.object({
      task: z.string().min(1),
      context: z.record(z.string(), z.unknown()).optional(),
      });

      server.tool('my_tool', InputSchema.shape, async (args) => {
      const result = validateToolInput(InputSchema, args);
      if (!result.ok) {
      return toolStructuredError({ errorCategory: 'validation', message: result.error.message });
      }
      const { task, context } = result.value;
      // Process validated input...
      });