Skip to content

Open-source, local-first AI agent for real work.

1.9 KB
Raw Blame
import type { McpClientHandle } from "../client/index.js";
import type {
	McpConfig,
	McpResource,
	McpServerConfig,
	McpServerInfo,
	McpServerStatus,
	McpTool,
} from "../protocol/index.js";

/** Transport-neutral observation of one managed MCP server. */
export interface McpServerView {
	readonly name: string;
	readonly config: McpServerConfig;
	readonly status: McpServerStatus;
	readonly serverInfo?: McpServerInfo;
	readonly tools: readonly McpTool[];
	readonly resources: readonly McpResource[];
	readonly error?: string;
	readonly pid?: number;
	readonly startedAt?: number;
}

/** Internal-runtime binding exposed to host adapters that need to invoke tools. */
export interface McpServerBinding {
	readonly view: McpServerView;
	readonly client?: McpClientHandle;
	/**
	 * 为一个 Turn 固定当前连接/进程 generation;普通重配不得主动关闭该 lease。
	 * Lease 不保证 transport 或进程存活,物理故障仍可使调用失败。
	 */
	acquireLease(): McpServerBindingLease;
}

export interface McpServerBindingLease {
	readonly view: McpServerView;
	readonly client?: McpClientHandle;
	release(): Promise<void>;
}

export interface McpServerSupervisorState {
	readonly enabled: boolean;
	readonly servers: readonly McpServerView[];
	readonly globalConfig?: McpConfig;
	readonly projectConfig?: McpConfig;
}

export interface McpServerSupervisorStats {
	readonly totalServers: number;
	readonly readyServers: number;
	readonly errorServers: number;
	readonly totalTools: number;
	readonly totalResources: number;
	readonly retiredServers: number;
	readonly activeLeases: number;
}

/** Complete replacement set supplied by a dynamic capability source such as plugins. */
export interface McpDynamicServerSet {
	readonly servers: ReadonlyMap<string, McpServerConfig>;
	readonly signature: string;
}

export interface McpServerDisconnectOutcome {
	readonly status: "stopped" | "needs_auth";
	readonly error?: string;
}