import { CancellationToken } from "../../../../base/common/cancellation.js";
import { Disposable, IDisposable } from "../../../../base/common/lifecycle.js";
import { IObservable } from "../../../../base/common/observable.js";
import { URI, UriComponents } from "../../../../base/common/uri.js";
import { Location } from "../../../../editor/common/languages.js";
import { ConfigurationTarget } from "../../../../platform/configuration/common/configuration.js";
import { RawContextKey } from "../../../../platform/contextkey/common/contextkey.js";
import { ExtensionIdentifier } from "../../../../platform/extensions/common/extensions.js";
import { IGalleryMcpServer, ILocalMcpServer } from "@codingame/monaco-vscode-aa9ead53-dfd3-59da-b9e7-f163d201de8d-common/vscode/vs/platform/mcp/common/mcpManagement";
import { IMcpDevModeConfig } from "@codingame/monaco-vscode-mcp-service-override/vscode/vs/platform/mcp/common/mcpPlatformTypes";
import { StorageScope } from "../../../../platform/storage/common/storage.js";
import { IWorkspaceFolderData } from "../../../../platform/workspace/common/workspace.js";
import { ToolProgress } from "../../chat/common/languageModelToolsService.js";
import { McpServerRequestHandler } from "@codingame/monaco-vscode-mcp-service-override/vscode/vs/workbench/contrib/mcp/common/mcpServerRequestHandler";
import { IMcpWorkbenchService } from "./mcpTypes.service.js";
import { MCP } from "./modelContextProtocol.js";
import { UriTemplate } from "@codingame/monaco-vscode-mcp-service-override/vscode/vs/workbench/contrib/mcp/common/uriTemplate";
export declare const extensionMcpCollectionPrefix = "ext.";
export declare function extensionPrefixedIdentifier(identifier: ExtensionIdentifier, id: string): string;
export interface McpCollectionDefinition {
    readonly remoteAuthority: string | null;
    readonly id: string;
    readonly label: string;
    readonly serverDefinitions: IObservable<readonly McpServerDefinition[]>;
    readonly isTrustedByDefault: boolean;
    readonly scope: StorageScope;
    readonly configTarget: ConfigurationTarget;
    resolveServerLanch?(definition: McpServerDefinition): Promise<McpServerLaunch | undefined>;
    readonly lazy?: {
        isCached: boolean;
        load(): Promise<void>;
        removed?(): void;
    };
    readonly presentation?: {
        readonly order?: number;
        readonly origin?: URI;
    };
}
export declare enum McpCollectionSortOrder {
    WorkspaceFolder = 0,
    Workspace = 100,
    User = 200,
    Extension = 300,
    Filesystem = 400,
    RemoteBoost = -50
}
export declare namespace McpCollectionDefinition {
    interface FromExtHost {
        readonly id: string;
        readonly label: string;
        readonly isTrustedByDefault: boolean;
        readonly scope: StorageScope;
        readonly canResolveLaunch: boolean;
        readonly extensionId: string;
        readonly configTarget: ConfigurationTarget;
    }
    function equals(a: McpCollectionDefinition, b: McpCollectionDefinition): boolean;
}
export interface McpServerDefinition {
    readonly id: string;
    readonly label: string;
    readonly launch: McpServerLaunch;
    readonly roots?: URI[] | undefined;
    readonly variableReplacement?: McpServerDefinitionVariableReplacement;
    readonly cacheNonce?: string;
    readonly devMode?: IMcpDevModeConfig;
    readonly presentation?: {
        readonly order?: number;
        readonly origin?: Location;
    };
}
export declare namespace McpServerDefinition {
    interface Serialized {
        readonly id: string;
        readonly label: string;
        readonly cacheNonce?: string;
        readonly launch: McpServerLaunch.Serialized;
        readonly variableReplacement?: McpServerDefinitionVariableReplacement.Serialized;
    }
    function toSerialized(def: McpServerDefinition): McpServerDefinition.Serialized;
    function fromSerialized(def: McpServerDefinition.Serialized): McpServerDefinition;
    function equals(a: McpServerDefinition, b: McpServerDefinition): boolean;
}
export interface McpServerDefinitionVariableReplacement {
    section?: string;
    folder?: IWorkspaceFolderData;
    target: ConfigurationTarget;
}
export declare namespace McpServerDefinitionVariableReplacement {
    interface Serialized {
        target: ConfigurationTarget;
        section?: string;
        folder?: {
            name: string;
            index: number;
            uri: UriComponents;
        };
    }
    function toSerialized(def: McpServerDefinitionVariableReplacement): McpServerDefinitionVariableReplacement.Serialized;
    function fromSerialized(def: McpServerDefinitionVariableReplacement.Serialized): McpServerDefinitionVariableReplacement;
}
export declare enum LazyCollectionState {
    HasUnknown = 0,
    LoadingUnknown = 1,
    AllKnown = 2
}
export interface McpCollectionReference {
    id: string;
    label: string;
    presentation?: McpCollectionDefinition["presentation"];
}
export interface McpDefinitionReference {
    id: string;
    label: string;
}
export interface IMcpServerStartOpts {
    isFromInteraction?: boolean;
    debug?: boolean;
}
export interface IMcpServer extends IDisposable {
    readonly collection: McpCollectionReference;
    readonly definition: McpDefinitionReference;
    readonly connection: IObservable<IMcpServerConnection | undefined>;
    readonly connectionState: IObservable<McpConnectionState>;
    readDefinitions(): IObservable<{
        server: McpServerDefinition | undefined;
        collection: McpCollectionDefinition | undefined;
    }>;
    readonly trusted: IObservable<boolean | undefined>;
    showOutput(): void;
    start(opts?: IMcpServerStartOpts): Promise<McpConnectionState>;
    stop(): Promise<void>;
    readonly cacheState: IObservable<McpServerCacheState>;
    readonly tools: IObservable<readonly IMcpTool[]>;
    readonly prompts: IObservable<readonly IMcpPrompt[]>;
    readonly capabilities: IObservable<McpCapability | undefined>;
    resources(token?: CancellationToken): AsyncIterable<IMcpResource[]>;
    resourceTemplates(token?: CancellationToken): Promise<IMcpResourceTemplate[]>;
}
export interface IMcpResource {
    readonly uri: URI;
    readonly mcpUri: string;
    readonly name: string;
    readonly description?: string;
    readonly mimeType?: string;
    readonly sizeInBytes?: number;
}
export interface IMcpResourceTemplate {
    readonly name: string;
    readonly description?: string;
    readonly mimeType?: string;
    readonly template: UriTemplate;
    complete(templatePart: string, prefix: string, alreadyResolved: Record<string, string | string[]>, token: CancellationToken): Promise<string[]>;
    resolveURI(vars: Record<string, unknown>): URI;
}
export declare const isMcpResourceTemplate: (obj: IMcpResource | IMcpResourceTemplate) => obj is IMcpResourceTemplate;
export declare const isMcpResource: (obj: IMcpResource | IMcpResourceTemplate) => obj is IMcpResource;
export declare enum McpServerCacheState {
    Unknown = 0,
    Cached = 1,
    Outdated = 2,
    RefreshingFromUnknown = 3,
    RefreshingFromCached = 4,
    Live = 5
}
export interface IMcpPrompt {
    readonly id: string;
    readonly name: string;
    readonly description?: string;
    readonly arguments: readonly MCP.PromptArgument[];
    complete(argument: string, prefix: string, token: CancellationToken): Promise<string[]>;
    resolve(args: Record<string, string | undefined>, token?: CancellationToken): Promise<IMcpPromptMessage[]>;
}
export declare const mcpPromptReplaceSpecialChars: (s: string) => string;
export declare const mcpPromptPrefix: (definition: McpDefinitionReference) => string;
export interface IMcpPromptMessage extends MCP.PromptMessage {
}
export interface IMcpTool {
    readonly id: string;
    readonly referenceName: string;
    readonly definition: MCP.Tool;
    call(params: Record<string, unknown>, token?: CancellationToken): Promise<MCP.CallToolResult>;
    callWithProgress(params: Record<string, unknown>, progress: ToolProgress, token?: CancellationToken): Promise<MCP.CallToolResult>;
}
export declare enum McpServerTransportType {
    Stdio = 1,
    HTTP = 2
}
export interface McpServerTransportStdio {
    readonly type: McpServerTransportType.Stdio;
    readonly cwd: string | undefined;
    readonly command: string;
    readonly args: readonly string[];
    readonly env: Record<string, string | number | null>;
    readonly envFile: string | undefined;
}
export interface McpServerTransportHTTP {
    readonly type: McpServerTransportType.HTTP;
    readonly uri: URI;
    readonly headers: [
        string,
        string
    ][];
}
export type McpServerLaunch = McpServerTransportStdio | McpServerTransportHTTP;
export declare namespace McpServerLaunch {
    type Serialized = {
        type: McpServerTransportType.HTTP;
        uri: UriComponents;
        headers: [
            string,
            string
        ][];
    } | {
        type: McpServerTransportType.Stdio;
        cwd: string | undefined;
        command: string;
        args: readonly string[];
        env: Record<string, string | number | null>;
        envFile: string | undefined;
    };
    function toSerialized(launch: McpServerLaunch): McpServerLaunch.Serialized;
    function fromSerialized(launch: McpServerLaunch.Serialized): McpServerLaunch;
}
export interface IMcpServerConnection extends IDisposable {
    readonly definition: McpServerDefinition;
    readonly state: IObservable<McpConnectionState>;
    readonly handler: IObservable<McpServerRequestHandler | undefined>;
    readonly launchDefinition: McpServerLaunch;
    start(methods: IMcpClientMethods): Promise<McpConnectionState>;
    stop(): Promise<void>;
}
export interface IMcpClientMethods {
    createMessageRequestHandler?(req: MCP.CreateMessageRequest["params"]): Promise<MCP.CreateMessageResult>;
}
export declare namespace McpConnectionState {
    enum Kind {
        Stopped = 0,
        Starting = 1,
        Running = 2,
        Error = 3
    }
    const toString: (s: McpConnectionState) => string;
    const toKindString: (s: McpConnectionState.Kind) => string;
    const canBeStarted: (s: Kind) => s is Kind.Stopped | Kind.Error;
    const isRunning: (s: McpConnectionState) => boolean;
    interface Stopped {
        readonly state: Kind.Stopped;
    }
    interface Starting {
        readonly state: Kind.Starting;
    }
    interface Running {
        readonly state: Kind.Running;
    }
    interface Error {
        readonly state: Kind.Error;
        readonly code?: string;
        readonly shouldRetry?: boolean;
        readonly message: string;
    }
}
export type McpConnectionState = McpConnectionState.Stopped | McpConnectionState.Starting | McpConnectionState.Running | McpConnectionState.Error;
export declare class MpcResponseError extends Error {
    readonly code: number;
    readonly data: unknown;
    constructor(message: string, code: number, data: unknown);
}
export declare class McpConnectionFailedError extends Error {
}
export interface IMcpServerContainer extends IDisposable {
    mcpServer: IWorkbenchMcpServer | null;
    update(): void;
}
export interface IWorkbenchMcpServer {
    readonly gallery: IGalleryMcpServer | undefined;
    readonly local: ILocalMcpServer | undefined;
    readonly id: string;
    readonly name: string;
    readonly label: string;
    readonly description: string;
    readonly iconUrl?: string;
    readonly publisherUrl?: string;
    readonly publisherDisplayName?: string;
    readonly installCount?: number;
    readonly ratingCount?: number;
    readonly rating?: number;
    readonly url?: string;
    readonly repository?: string;
    getReadme(token: CancellationToken): Promise<string>;
}
export declare class McpServerContainers extends Disposable {
    private readonly containers;
    constructor(containers: IMcpServerContainer[], mcpWorkbenchService: IMcpWorkbenchService);
    set mcpServer(extension: IWorkbenchMcpServer | null);
    update(server: IWorkbenchMcpServer | undefined): void;
}
export declare const McpServersGalleryEnabledContext: RawContextKey<boolean>;
export declare const HasInstalledMcpServersContext: RawContextKey<boolean>;
export declare const InstalledMcpServersViewId = "workbench.views.mcp.installed";
export declare const mcpServerIcon: import("../../../../base/common/themables.js").ThemeIcon;
export declare namespace McpResourceURI {
    const scheme = "mcp-resource";
    function fromServer(def: McpDefinitionReference, resourceURI: URI | string): URI;
    function toServer(uri: URI | string): {
        definitionId: string;
        resourceURI: URI;
    };
}
export declare enum McpCapability {
    Logging = 1,
    Completions = 2,
    Prompts = 4,
    PromptsListChanged = 8,
    Resources = 16,
    ResourcesSubscribe = 32,
    ResourcesListChanged = 64,
    Tools = 128,
    ToolsListChanged = 256
}
export interface ISamplingOptions {
    server: IMcpServer;
    isDuringToolCall: boolean;
    params: MCP.CreateMessageRequest["params"];
}
export interface ISamplingResult {
    sample: MCP.CreateMessageResult;
}
export declare class McpError extends Error {
    readonly code: number;
    readonly data?: unknown | undefined;
    static methodNotFound(method: string): McpError;
    static notAllowed(): McpError;
    static unknown(e: Error): McpError;
    constructor(code: number, message: string, data?: unknown | undefined);
}
export declare enum McpToolName {
    Prefix = "mcp_",
    MaxPrefixLen = 18,
    MaxLength = 64
}
