BaseTool.d.ts•2.25 kB
import { z } from "zod";
import { Tool as SDKTool } from "@modelcontextprotocol/sdk/types.js";
import { ImageContent } from "../transports/utils/image-handler.js";
export type ToolInputSchema<T> = {
[K in keyof T]: {
type: z.ZodType<T[K]>;
description: string;
};
};
export type ToolInput<T extends ToolInputSchema<any>> = {
[K in keyof T]: z.infer<T[K]["type"]>;
};
export type TextContent = {
type: "text";
text: string;
};
export type ErrorContent = {
type: "error";
text: string;
};
export type ToolContent = TextContent | ErrorContent | ImageContent;
export type ToolResponse = {
content: ToolContent[];
};
export interface ToolProtocol extends SDKTool {
name: string;
description: string;
toolDefinition: {
name: string;
description: string;
inputSchema: {
type: "object";
properties?: Record<string, unknown>;
};
};
toolCall(request: {
params: {
name: string;
arguments?: Record<string, unknown>;
};
}): Promise<ToolResponse>;
}
export declare abstract class MCPTool<TInput extends Record<string, any> = {}> implements ToolProtocol {
abstract name: string;
abstract description: string;
protected abstract schema: ToolInputSchema<TInput>;
[key: string]: unknown;
get inputSchema(): {
type: "object";
properties?: Record<string, unknown>;
};
get toolDefinition(): {
name: string;
description: string;
inputSchema: {
type: "object";
properties?: Record<string, unknown>;
};
};
protected abstract execute(input: TInput): Promise<unknown>;
toolCall(request: {
params: {
name: string;
arguments?: Record<string, unknown>;
};
}): Promise<ToolResponse>;
private validateInput;
private getJsonSchemaType;
protected createSuccessResponse(data: unknown): ToolResponse;
protected createErrorResponse(error: Error): ToolResponse;
private isImageContent;
private isTextContent;
private isErrorContent;
private isValidContent;
protected fetch<T>(url: string, init?: RequestInit): Promise<T>;
}