import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { ToolAnnotations, CallToolResult } from '@modelcontextprotocol/sdk/types';
import { ApiClientConfig } from '@mondaydotcomorg/api';
import { ZodRawShape, z, ZodTypeAny } from 'zod';

interface Executable<Input, Output> {
    execute: (input?: Input) => Promise<Output>;
}

type ToolInputType<Input extends ZodRawShape | undefined> = Input extends ZodRawShape ? z.objectOutputType<Input, ZodTypeAny> : undefined;
type ToolOutputType<T extends Record<string, unknown>> = {
    content: string;
    metadata?: T;
};
declare enum ToolType {
    READ = "read",
    WRITE = "write",
    ALL_API = "all_api"
}
interface Tool<Input extends ZodRawShape | undefined, Output extends Record<string, unknown> = never> extends Executable<ToolInputType<Input>, ToolOutputType<Output>> {
    name: string;
    type: ToolType;
    annotations: ToolAnnotations;
    /** Whether the tool is enabled by default. Defaults to true if not specified. */
    enabledByDefault?: boolean;
    getDescription(): string;
    getInputSchema(): Input;
}

type MondayApiToolContext = {
    boardId?: number;
    apiVersion?: string;
    agentType?: string;
    agentClientName?: string;
    clientRedirectUris?: string[];
};

declare enum ToolMode {
    API = "api",
    APPS = "apps",
    ATP = "atp"
}
type ToolsConfiguration = {
    include?: string[];
    exclude?: string[];
    readOnlyMode?: boolean;
    mode?: ToolMode;
    enableDynamicApiTools?: boolean | 'only';
    enableToolManager?: boolean;
};
type MondayAgentToolkitConfig = {
    mondayApiToken: ApiClientConfig['token'];
    mondayApiVersion?: ApiClientConfig['apiVersion'];
    mondayApiEndpoint?: ApiClientConfig['endpoint'];
    mondayApiRequestConfig?: ApiClientConfig['requestConfig'];
    toolsConfiguration?: ToolsConfiguration;
    context?: MondayApiToolContext;
};

interface GetToolsOptions {
    schemaFormat?: 'zod' | 'json';
}
/**
 * Monday Agent Toolkit providing an MCP server with monday.com tools
 */
declare class MondayAgentToolkit extends McpServer {
    private readonly mondayApiClient;
    private readonly mondayApiToken;
    private readonly context?;
    private readonly dynamicToolManager;
    private toolInstances;
    private managementTool;
    /**
     * Creates a new instance of the Monday Agent Toolkit
     * @param config Configuration for the toolkit
     */
    constructor(config: MondayAgentToolkitConfig);
    /**
     * Create and configure the Monday API client
     */
    private createApiClient;
    /**
     * Register all tools with the MCP server
     */
    private registerTools;
    /**
     * Register the management tool with toolkit reference
     */
    private registerManagementTool;
    /**
     * Initialize both API and CLI tools
     */
    private initializeTools;
    /**
     * Register a single tool with the MCP server
     */
    private registerSingleTool;
    /**
     * Dynamically enable a tool
     */
    enableTool(toolName: string): boolean;
    /**
     * Dynamically disable a tool
     */
    disableTool(toolName: string): boolean;
    /**
     * Check if a tool is enabled
     */
    isToolEnabled(toolName: string): boolean;
    /**
     * Get list of all available tools and their status
     */
    getToolsStatus(): Record<string, boolean>;
    /**
     * Get list of all dynamic tool names
     */
    getDynamicToolNames(): string[];
    getServer(): McpServer;
    /**
     * Get all tools as an array of tool objects that can be registered individually
     * Each tool includes name, description, schema, annotations, and handler for external registration
     * @param options Options for schema format control
     * @returns Array of tool objects ready for individual registration
     */
    getTools(options?: GetToolsOptions): Array<{
        name: string;
        description: string;
        schema: any;
        annotations: any;
        handler: (params: any) => Promise<any>;
    }>;
    /**
     * Get all tools with MCP-formatted handlers for direct registration with MCP servers
     * This method wraps the handlers to return the proper CallToolResult format
     * @param options Options for schema format control
     * @returns Array of tool objects with MCP-compatible handlers
     */
    getToolsForMcp(options?: GetToolsOptions): Array<{
        name: string;
        description: string;
        schema: any;
        annotations: any;
        handler: (params: any, extra?: any) => Promise<CallToolResult>;
    }>;
    /**
     * Create a bound handler function for a tool that maintains access to toolkit state
     * @param tool The tool instance to create a handler for
     * @returns Async handler function that can be used externally
     */
    private createToolHandler;
    /**
     * Create a bound handler function for a tool that returns MCP-formatted results
     * @param tool The tool instance to create a handler for
     * @returns Async handler function that returns CallToolResult format
     */
    private createMcpToolHandler;
    /**
     * Get the schema for a tool in the requested format
     * @param tool The tool instance
     * @param options Options for schema format control
     * @returns Schema in the requested format (Zod shape or JSON Schema)
     */
    private getSchemaForTool;
    /**
     * Format the tool result into the expected MCP format
     */
    private formatToolResult;
    /**
     * Handle tool execution errors
     */
    private handleToolError;
}

interface ToolkitManager {
    enableTool(toolName: string): boolean;
    disableTool(toolName: string): boolean;
    isToolEnabled(toolName: string): boolean;
    isToolEnabledByDefault(toolName: string): boolean;
    getToolsStatus(): Record<string, boolean>;
    getDetailedToolsStatus(): Record<string, {
        enabled: boolean;
        enabledByDefault: boolean;
    }>;
    resetToolToDefault(toolName: string): boolean;
    getDynamicToolNames(): string[];
}

/**
 * Interface representing an MCP server tool registration handle
 */
interface MCPToolHandle {
    enable(): void;
    disable(): void;
}
/**
 * Interface for dynamic tool control
 */
interface DynamicTool {
    instance: Tool<any, any>;
    mcpTool: MCPToolHandle;
    enabled: boolean;
    enabledByDefault: boolean;
}
/**
 * Manages dynamic tool registration, enabling, and disabling
 */
declare class DynamicToolManager implements ToolkitManager {
    private readonly dynamicTools;
    /**
     * Register a tool for dynamic management
     */
    registerTool(tool: Tool<any, any>, mcpTool: MCPToolHandle): void;
    /**
     * Enable a specific tool
     */
    enableTool(toolName: string): boolean;
    /**
     * Disable a specific tool
     */
    disableTool(toolName: string): boolean;
    /**
     * Check if a tool is currently enabled
     */
    isToolEnabled(toolName: string): boolean;
    /**
     * Check if a tool is enabled by default
     */
    isToolEnabledByDefault(toolName: string): boolean;
    /**
     * Get list of all available tools and their status
     */
    getToolsStatus(): Record<string, boolean>;
    /**
     * Get list of all dynamic tool names
     */
    getDynamicToolNames(): string[];
    /**
     * Get list of all available tools with their current and default status
     */
    getDetailedToolsStatus(): Record<string, {
        enabled: boolean;
        enabledByDefault: boolean;
    }>;
    /**
     * Reset a tool to its default enabled state
     */
    resetToolToDefault(toolName: string): boolean;
    /**
     * Get all registered dynamic tools (for internal use)
     */
    getAllDynamicTools(): Map<string, DynamicTool>;
    /**
     * Clear all registered tools (for cleanup)
     */
    clear(): void;
}

export { DynamicToolManager, GetToolsOptions, MondayAgentToolkit };
