/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: eb9603e91876
 */

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import { MCPServerIcon, MCPServerIcon$inboundSchema } from "./mcpservericon.js";
import { MCPToolMeta, MCPToolMeta$inboundSchema } from "./mcptoolmeta.js";
import {
  ToolAnnotations,
  ToolAnnotations$inboundSchema,
} from "./toolannotations.js";
import { ToolExecution, ToolExecution$inboundSchema } from "./toolexecution.js";

export type MCPTool = {
  name: string;
  title?: string | null | undefined;
  description?: string | null | undefined;
  inputSchema: { [k: string]: any };
  outputSchema?: { [k: string]: any } | null | undefined;
  icons?: Array<MCPServerIcon> | null | undefined;
  annotations?: ToolAnnotations | null | undefined;
  meta?: MCPToolMeta | null | undefined;
  execution?: ToolExecution | null | undefined;
  [additionalProperties: string]: unknown;
};

/** @internal */
export const MCPTool$inboundSchema: z.ZodType<MCPTool, unknown> = z.object({
  name: z.string(),
  title: z.nullable(z.string()).optional(),
  description: z.nullable(z.string()).optional(),
  inputSchema: z.record(z.string(), z.any()),
  outputSchema: z.nullable(z.record(z.string(), z.any())).optional(),
  icons: z.nullable(z.array(MCPServerIcon$inboundSchema)).optional(),
  annotations: z.nullable(ToolAnnotations$inboundSchema).optional(),
  _meta: z.nullable(MCPToolMeta$inboundSchema).optional(),
  execution: z.nullable(ToolExecution$inboundSchema).optional(),
}).catchall(z.any()).transform((v) => {
  return remap$(v, {
    "_meta": "meta",
  });
});

export function mcpToolFromJSON(
  jsonString: string,
): SafeParseResult<MCPTool, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => MCPTool$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'MCPTool' from JSON`,
  );
}
