/**
 * Model Context Protocol (MCP) server for Apify Actors
 */
import type { TaskStore } from '@modelcontextprotocol/sdk/experimental/tasks/interfaces.js';
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
import { ApifyClient } from '../apify_client.js';
import type { ActorsMcpServerOptions, ActorStore, Input, ToolEntry } from '../types.js';
import { ServerMode } from '../types.js';
/**
 * Create Apify MCP server
 */
export declare class ActorsMcpServer {
    readonly server: Server;
    readonly tools: Map<string, ToolEntry>;
    private toolsChangedHandler;
    private sigintHandler;
    private currentLogLevel;
    readonly options: ActorsMcpServerOptions;
    readonly taskStore: TaskStore;
    readonly actorStore?: ActorStore;
    /**
     * Resolved server mode. Preliminary value at construction (`'auto'` → `DEFAULT`).
     * Finalized inside the `initialize` request handler (see constructor) once the
     * client's capabilities are known. Effectively set-once per connection.
     */
    serverMode: ServerMode;
    /** Mode-specific executor for direct actor tools (`type: 'actor'`). Finalized with `serverMode`. */
    private actorExecutor;
    /**
     * Raw option captured from `options.serverMode` (or the legacy `uiMode`). Re-resolved
     * inside the initialize handler when set to `'auto'`; explicit `'default'`/`'apps'`
     * values bypass auto-detect.
     */
    private readonly serverModeOption;
    /** True once mode is final. False for `'auto'` until the initialize handler resolves client capabilities. */
    private serverModeResolved;
    /**
     * Tool requests queued before mode is final. Actor tools are upserted immediately
     * (mode-agnostic); we also capture the exact actor-tool slice fetched for each
     * request so the flush composes every entry against *its own* actor list rather
     * than the accumulated union across unrelated requests.
     */
    private pendingToolsAfterModeResolved;
    private telemetryEnabled;
    private telemetryEnv;
    private availableWidgets;
    /** Set in the initialize handler once client capabilities are known. */
    clientSupportsUi: boolean;
    constructor(options?: ActorsMcpServerOptions);
    /**
     * Telemetry configuration with precedence: explicit options > env vars > defaults
     */
    private setupTelemetry;
    /**
     * Override the SDK's `initialize` request handler to run mode resolution and
     * pending-source flush before `InitializeResult` is sent. Delegates boilerplate
     * (protocolVersion, capabilities, instructions) to the SDK's captured `_oninitialize`.
     *
     * Not using `server.oninitialized`: the SDK dispatches notification handlers
     * fire-and-forget (separate microtask), so a follow-up `tools/list` can race past them.
     * The request handler guarantees tools are final before the response and the first `tools/list`.
     */
    private setupInitializeHandler;
    private updateToolsAfterServerModeResolved;
    /**
     * Returns an array of tool names.
     * @returns {string[]} - An array of tool names.
     */
    listToolNames(): string[];
    /**
    * Register handler to get notified when tools change.
    * The handler receives an array of tool names that the server has after the change.
    * This is primarily used to store the tools in shared state (e.g., Redis) for recovery
    * when the server loses local state.
    * @throws {Error} - If a handler is already registered.
    * @param handler - The handler function to be called when tools change.
    */
    registerToolsChangedHandler(handler: (toolNames: string[]) => void): void;
    /**
    * Unregister the handler for tools changed event.
    * @throws {Error} - If no handler is currently registered.
    */
    unregisterToolsChangedHandler(): void;
    /**
     * Returns the list of all internal tool names
     * @returns {string[]} - Array of loaded tool IDs (e.g., 'apify/rag-web-browser')
     */
    private listInternalToolNames;
    /**
     * Returns the list of all currently loaded Actor tool IDs.
     * @returns {string[]} - Array of loaded Actor tool IDs (e.g., 'apify/rag-web-browser')
     */
    listActorToolNames(): string[];
    /**
     * Returns a list of Actor IDs that are registered as MCP servers.
     * @returns {string[]} - An array of Actor MCP server Actor IDs (e.g., 'apify/actors-mcp-server').
     */
    private listActorMcpServerToolIds;
    /**
     * Returns a list of Actor name and MCP server tool IDs.
     * @returns {string[]} - An array of Actor MCP server Actor IDs (e.g., 'apify/actors-mcp-server').
     */
    listAllToolNames(): string[];
    /**
    * Loads missing toolNames from a provided list of tool names.
    * Skips toolNames that are already loaded and loads only the missing ones.
    * @param toolNames - Array of tool names to ensure are loaded
    * @param apifyClient
    */
    loadToolsByName(toolNames: string[], apifyClient: ApifyClient): Promise<void>;
    /**
     * Load actors as tools, upsert them to the server, and return the tool entries.
     * This is a public method that wraps getActorsAsTools and handles the upsert operation.
     * @param actorIdsOrNames - Array of actor IDs or names to load as tools
     * @param apifyClient
     * @returns Promise<ToolEntry[]> - Array of loaded tool entries
     */
    loadActorsAsTools(actorIdsOrNames: string[], apifyClient: ApifyClient): Promise<ToolEntry[]>;
    /** Load tools from URL params. Used by SSE and HTTP entry points. */
    loadToolsFromUrl(url: string, apifyClient: ApifyClient): Promise<void>;
    /**
     * Two-phase: getActors (async, mode-agnostic Apify fetch) then getToolsForServerMode
     * (sync, mode-dependent compose). When mode is unresolved, queue actorTools and let
     * the initialize handler compose them later.
     *
     * Don't move the getActors await into the initialize handler — clients time out
     * waiting for InitializeResult. The queue buffers already-fetched data, not network
     * work. See #721.
     */
    loadToolsFromInput(input: Input, apifyClient: ApifyClient): Promise<void>;
    /** Delete tools from the server and notify the handler.
     */
    removeToolsByName(toolNames: string[], shouldNotifyToolsChangedHandler?: boolean): string[];
    /**
     * Upsert new tools.
     * @param tools - Array of tool wrappers to add or update
     * @param shouldNotifyToolsChangedHandler - Whether to notify the tools changed handler
     * @returns Array of added/updated tool wrappers
     */
    upsertTools(tools: ToolEntry[], shouldNotifyToolsChangedHandler?: boolean): ToolEntry[];
    private notifyToolsChangedHandler;
    private removeToolByName;
    private setupErrorHandling;
    private setupLoggingProxy;
    private setupLoggingHandlers;
    private setupResourceHandlers;
    /**
     * Sets up MCP request handlers for prompts.
     */
    private setupPromptHandlers;
    /**
      * Sets up MCP request handlers for long-running tasks.
      */
    private setupTaskHandlers;
    private setupToolHandlers;
    /**
     * Logs tool call completion at INFO level and tracks telemetry.
     * Computes duration once so both the log line and telemetry event use the same value.
     */
    private logToolCallAndTelemetry;
    /**
     * Executes a tool asynchronously for a long-running task and updates task status.
     *
     * @param params - Tool execution parameters
     * @param params.taskId - The task identifier
     * @param params.tool - The tool to execute
     * @param params.args - Tool arguments
     * @param params.apifyToken - Apify API token
     * @param params.progressToken - Progress token for notifications
     * @param params.extra - Extra request handler context
     * @param params.mcpSessionId - MCP session ID for telemetry
     */
    private executeToolAndUpdateTask;
    private prepareTelemetryData;
    /**
     * Resolves widgets and determines which ones are ready to be served.
     */
    private resolveWidgets;
    connect(transport: Transport): Promise<void>;
    close(): Promise<void>;
}
//# sourceMappingURL=server.d.ts.map