Function: defineTool()
Makaio Framework / tools-core / defineTool
Function: defineTool()
Section titled “Function: defineTool()”defineTool<
TInput,TOutput>(config):ToolDefinition<TInput,TOutput>
Defined in: ../../../tools/core/src/define-tool.ts:83
Creates a ToolDefinition from a configuration object.
Provides a clean builder API for defining tools with full type inference. The returned ToolDefinition can be used directly or registered with a toolset.
Type Parameters
Section titled “Type Parameters”TInput
Section titled “TInput”TInput extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
Zod schema type for input validation
TOutput
Section titled “TOutput”TOutput extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
Zod schema type for output validation
Parameters
Section titled “Parameters”config
Section titled “config”DefineToolConfig<TInput, TOutput>
Tool configuration
Returns
Section titled “Returns”ToolDefinition<TInput, TOutput>
Fully typed ToolDefinition
Example
Section titled “Example”import { z } from 'zod';import { defineTool, toolSuccess, toolError, ToolErrorCodes } from '@makaio/tools-core';
const ReadFileInputSchema = z.object({ path: z.string().describe('File path to read'), encoding: z.enum(['utf-8', 'base64']).default('utf-8'),});
const ReadFileOutputSchema = z.object({ content: z.string(), size: z.number(),});
const readFileTool = defineTool({ name: 'readFile', description: 'Reads a file from the filesystem', annotations: { readOnly: true }, inputSchema: ReadFileInputSchema, outputSchema: ReadFileOutputSchema, execute: async (input, context) => { const fullPath = path.resolve(context.cwd, input.path);
try { const content = await fs.readFile(fullPath, input.encoding); const stats = await fs.stat(fullPath); return toolSuccess({ content, size: stats.size }); } catch (err) { return toolError( ToolErrorCodes.RESOURCE_NOT_FOUND, `Failed to read file: ${fullPath}` ); } },});