# 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

- validateToolInput<T>(
  schema: ZodType<T>,
  args: unknown,
  ): Result<T, ValidationError>

  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

  #### Example

      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...
      });

  - Defined in packages/nexus-agents/src/mcp/middleware/validation.ts:45