@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, and professional CLI. Built-in tools operational, 58+ external MCP servers discoverable. Connect to filesystem, GitHub, database operations, and more. Build, test, and
100 lines (99 loc) • 3.05 kB
TypeScript
/**
* NeuroLink SDK Tool Registration API
* Simple interface for developers to register custom tools
*/
import { z } from "zod";
import type { Tool } from "ai";
import { logger } from "../utils/logger.js";
import type { InMemoryMCPServerConfig, InMemoryToolInfo } from "../types/mcpTypes.js";
import type { ToolArgs, ToolContext as CoreToolContext, ToolResult, SimpleTool as CoreSimpleTool } from "../types/tools.js";
import type { JsonValue } from "../types/common.js";
/**
* Context provided to tools during execution
* Extends the core ToolContext with SDK-specific features
*/
export interface ToolContext extends CoreToolContext {
/**
* Current session ID
*/
sessionId: string;
/**
* AI provider being used
*/
provider?: string;
/**
* Model being used
*/
model?: string;
/**
* Call another tool
*/
callTool?: (name: string, args: ToolArgs) => Promise<ToolResult>;
/**
* Logger instance
*/
logger: typeof logger;
}
/**
* Simple tool interface for SDK users
* Extends the core SimpleTool with specific types
*/
export interface SimpleTool<TArgs = ToolArgs, TResult = JsonValue> extends Omit<CoreSimpleTool<TArgs, TResult>, "execute"> {
/**
* Tool description that helps AI understand when to use it
*/
description: string;
/**
* Parameters schema using Zod (optional)
*/
parameters?: z.ZodSchema;
/**
* Tool execution function
*/
execute: (args: TArgs, context?: ToolContext) => Promise<TResult> | TResult;
/**
* Optional metadata
*/
metadata?: {
category?: string;
version?: string;
author?: string;
tags?: string[];
documentation?: string;
[key: string]: JsonValue | undefined;
};
}
/**
* Converts a SimpleTool to Vercel AI SDK format
*/
export declare function convertToAISDKTool(name: string, simpleTool: SimpleTool): Tool;
/**
* Converts a SimpleTool to MCP tool format
*/
export declare function convertToMCPTool(simpleTool: SimpleTool): InMemoryToolInfo;
/**
* Creates an in-memory MCP server configuration from a set of tools
*/
export declare function createMCPServerFromTools(serverId: string, tools: Record<string, SimpleTool>, metadata?: {
title?: string;
description?: string;
category?: string;
version?: string;
author?: string;
[key: string]: JsonValue | undefined;
}): InMemoryMCPServerConfig;
/**
* Helper to create a tool with type safety
*/
export declare function createTool<TParams = ToolArgs>(config: SimpleTool): SimpleTool;
/**
* Helper to create a tool with typed parameters
*/
export declare function createTypedTool<TParams extends z.ZodSchema>(config: Omit<SimpleTool, "execute"> & {
parameters: TParams;
execute: (args: z.infer<TParams>, context?: ToolContext) => Promise<JsonValue> | JsonValue;
}): SimpleTool;
/**
* Validate tool configuration with detailed error messages
*/
export declare function validateTool(name: string, tool: SimpleTool): void;