import 'reflect-metadata'; import { type ConcurrencyConfigInput, type RateLimitConfigInput, type TimeoutConfigInput } from '@frontmcp/guard'; import type z from '@frontmcp/lazy-zod'; import { type ToolContext } from '../interfaces'; import { type AudioOutputSchema, type ImageOutputSchema, type ResourceLinkOutputSchema, type ResourceOutputSchema, type ToolInputType, type ToolMetadata, type ToolOutputType } from '../metadata'; import { type ToolUIConfig } from '../metadata/tool-ui.metadata'; export type FrontMcpToolExecuteHandler, Out = ToolOutputOf<{ outputSchema: OutSchema; }>> = (input: In, ctx: ToolContext) => Out | Promise; /** * Decorator that marks a class as a McpTool module and provides metadata */ declare function frontMcpTool(providedMetadata: T): (handler: FrontMcpToolExecuteHandler) => () => void; export { FrontMcpTool, FrontMcpTool as Tool, frontMcpTool, frontMcpTool as tool }; /** * This is a modified version of the original decorator, with the following changes: * - Added support for ZodRawShape as inputSchema * - Added support for outputSchema: any of the allowed forms * - Added rich error messages for input/output type mismatches * * Don't move below code outside the decorator file, it will break the module augmentation. */ type __Shape = z.ZodRawShape; type __AsZodObj = T extends z.ZodRawShape ? z.ZodObject : never; export type ToolInputOf = Opt extends { inputSchema: infer I; } ? z.output<__AsZodObj> : never; /** * Helper to infer the return type from any Zod schema, * including ZodRawShape. */ type __InferZod = S extends z.ZodType ? z.infer : S extends z.ZodRawShape ? z.infer> : never; /** * Infers the *output type* from a *single schema definition* * based on the new ToolSingleOutputType. */ type __InferFromSingleSchema = S extends 'image' ? z.infer : S extends 'audio' ? z.infer : S extends 'resource' ? z.infer : S extends 'resource_link' ? z.infer : S extends 'string' ? string : S extends 'number' ? number : S extends 'boolean' ? boolean : S extends 'date' ? Date : S extends z.ZodType | z.ZodRawShape ? __InferZod : any; /** * Infers a tuple/array of output types from an array of schemas */ type __InferFromArraySchema = A extends readonly any[] ? { [K in keyof A]: __InferFromSingleSchema; } : never; /** * Main output type inference. * Handles single schemas, arrays of schemas, or no schema. */ export type ToolOutputOf = Opt extends { outputSchema: infer O; } ? O extends readonly any[] ? __InferFromArraySchema : __InferFromSingleSchema : any; type __PrimitiveOutputType = 'string' | 'number' | 'date' | 'boolean' | z.ZodString | z.ZodNumber | z.ZodBoolean | z.ZodBigInt | z.ZodDate; type __ImageOutputType = 'image'; type __AudioOutputType = 'audio'; type __ResourceOutputType = 'resource'; type __ResourceLinkOutputType = 'resource_link'; type __StructuredOutputType = z.ZodRawShape | z.ZodObject | z.ZodArray | z.ZodUnion<[z.ZodObject, ...z.ZodObject[]]> | z.ZodDiscriminatedUnion<[z.ZodObject, ...z.ZodObject[]]>; type __ToolSingleOutputType = __PrimitiveOutputType | __ImageOutputType | __AudioOutputType | __ResourceOutputType | __ResourceLinkOutputType | __StructuredOutputType; type __OutputSchema = __ToolSingleOutputType | __ToolSingleOutputType[]; /** * Base tool metadata options without UI field. */ type __ToolMetadataBase = ToolMetadata; /** * Tool metadata options with optional UI configuration. * * The `ui` property accepts a `ToolUIConfig` from `@frontmcp/ui/types` * for configuring interactive widget rendering. */ /** * Tool metadata options with permissive guard config types for IDE IntelliSense. * * Guard fields (concurrency, rateLimit, timeout) use auto-generated Input types * where all fields are optional. Required fields are validated at runtime by Zod. * @see schemas.generated.ts in @frontmcp/guard * * These four fields are `Omit`-ed from {@link ToolMetadata} and re-declared with * the permissive `*Input` types. The re-declarations carry their own JSDoc so * editor hover docs work on them (the base field docs do not survive `Omit`) — * #452. */ export type ToolMetadataOptions = Omit<__ToolMetadataBase, 'concurrency' | 'rateLimit' | 'timeout' | 'ui'> & { /** * Concurrency control for this tool — caps the number of simultaneous executions. * * @example * ```typescript * @Tool({ name: 'deploy', inputSchema: { env: z.string() }, concurrency: { maxConcurrent: 1 } }) * ``` */ concurrency?: ConcurrencyConfigInput; /** * Rate limiting for this tool — how many requests are allowed within a time window. * * @example * ```typescript * @Tool({ * name: 'search', * inputSchema: { query: z.string() }, * rateLimit: { maxRequests: 100, windowMs: 60_000, partitionBy: 'userId' }, * }) * ``` */ rateLimit?: RateLimitConfigInput; /** * Timeout for this tool's execution — wraps the execute stage with a deadline. * * @example * ```typescript * @Tool({ name: 'long-task', inputSchema: { query: z.string() }, timeout: { executeMs: 30_000 } }) * ``` */ timeout?: TimeoutConfigInput; /** * Interactive widget UI for this tool's result (MCP-UI / ext-apps). * * Prefer the file-based form — point at a `.tsx`/`.html` widget and the build * bundles it; the input/output types are inferred from this tool's schemas. * * @example * ```typescript * @Tool({ name: 'chart', inputSchema: { points: z.array(z.number()) }, ui: { file: './chart.widget.tsx' } }) * ``` */ ui?: ToolUIConfig, ToolOutputOf<{ outputSchema: O; }>>; }; type __Ctor = (new (...a: any[]) => any) | (abstract new (...a: any[]) => any); type __A = C extends new (...a: infer A) => any ? A : C extends abstract new (...a: infer A) => any ? A : never; type __R = C extends new (...a: any[]) => infer R ? R : C extends abstract new (...a: any[]) => infer R ? R : never; type __ExecParams = __R extends { execute: (...args: infer P) => unknown; } ? P : never; type __HasNoParam = [__ExecParams] extends [readonly []] ? true : false; type __Param = __ExecParams extends readonly [infer P, ...unknown[]] ? P : never; type __Return = __R extends { execute: (...a: any) => infer R; } ? R : never; type __Unwrap = T extends Promise ? U : T; type __IsAny = 0 extends 1 & T ? true : false; type __MustExtendCtx = __R extends ToolContext ? unknown : { 'Tool class error': 'Class must extend ToolContext'; }; type __MustParam = __IsAny extends true ? unknown : __IsAny<__Param> extends true ? { 'execute() parameter error': "Parameter type must not be 'any'."; expected_input_type: In; } : __HasNoParam extends true ? In extends Record ? unknown : { 'execute() parameter error': 'execute() requires a parameter matching the input schema.'; expected_input_type: In; } : __Param extends In ? In extends __Param ? unknown : { 'execute() parameter error': 'Parameter type is too wide. It must exactly match the input schema.'; expected_input_type: In; actual_parameter_type: __Param; } : { 'execute() parameter error': 'Parameter type does not match the input schema.'; expected_input_type: In; actual_parameter_type: __Param; }; type __MustReturn = __IsAny extends true ? unknown : __IsAny<__Unwrap<__Return>> extends true ? { 'execute() return type error': "Return type must not be 'any'."; expected_output_type: Out; } : __Unwrap<__Return> extends Out ? unknown : { 'execute() return type error': "The method's return type is not assignable to the expected output schema type."; expected_output_type: Out; 'actual_return_type (unwrapped)': __Unwrap<__Return>; }; type __Rewrap = C extends abstract new (...a: __A) => __R ? C & (abstract new (...a: __A) => ToolContext & __R) : C extends new (...a: __A) => __R ? C & (new (...a: __A) => ToolContext & __R) : never; declare module '@frontmcp/sdk' { function Tool(opts: ToolMetadataOptions & { outputSchema: O; }): (cls: C & __MustExtendCtx & __MustParam> & __MustReturn>) => __Rewrap, ToolOutputOf<{ outputSchema: O; }>>; function Tool(opts: ToolMetadataOptions & { outputSchema?: never; }): (cls: C & __MustExtendCtx & __MustParam> & __MustReturn>) => __Rewrap, ToolOutputOf<{}>>; } //# sourceMappingURL=tool.decorator.d.ts.map