// file: libs/plugins/src/codecall/tools/invoke.schema.ts
import { z } from '@frontmcp/lazy-zod';
import { CallToolResultSchema } from '@frontmcp/protocol';

export const invokeToolDescription = `Call ONE tool directly. Returns standard MCP CallToolResult.

USE invoke: single tool, no transformation
USE execute: multiple tools, loops, filtering, joining

INPUT: tool (string), input (object matching tool schema)
OUTPUT: MCP CallToolResult (same as standard tool call)
ERRORS: tool_not_found (→ re-search) | validation_error | execution_error | permission_denied

FLOW: search → describe → invoke`;

export const invokeToolInputSchema = {
  tool: z
    .string()
    .describe(
      'The name of the tool to invoke (e.g., "users:getById", "billing:getInvoice"). Must be a tool you discovered via codecall:search.',
    ),
  input: z
    .record(z.string(), z.unknown())
    .describe(
      "The input parameters for the tool. Structure must match the tool's input schema (check codecall:describe for schema details).",
    ),
};

export type InvokeToolInput = z.infer<z.ZodObject<typeof invokeToolInputSchema>>;

// Use standard MCP CallToolResult schema - returns same format as direct tool call
export const invokeToolOutputSchema = CallToolResultSchema;

export type InvokeToolOutput = z.infer<typeof invokeToolOutputSchema>;
