/** * Worker side of the MCP manager bridge: {@link RemoteMCPManager} implements * {@link MCPManagerApi} over the main thread's manager (remote-object kind * {@link MCP_MANAGER_KIND}). Workers never own MCP connections: every tool call, * resource read and change subscription runs on main. */ import type { TSchema } from "@oh-my-pi/pi-ai"; import type { MCPToolDetails } from "@oh-my-pi/pi-tui/tools/mcp"; import type { CustomTool } from "../../extensibility/custom-tools/types.js"; import type { MCPManagerApi, MCPToolScope } from "../../mcp/manager.js"; import type { MCPRequestOptions, MCPResource, MCPResourceReadResult, MCPResourceTemplate } from "../../mcp/types.js"; import type { RemoteObject, RpcMethod } from "../rpc.js"; /** Remote-object kind of a main-thread `MCPManager`. */ export declare const MCP_MANAGER_KIND = "mcp-manager"; /** Listener for server notification frames. */ export type McpNotificationListener = (serverName: string, method: string, params: unknown) => void; /** Reply to {@link McpManagerProtocol.tools}. */ export interface McpToolsReply { /** Version of main's tool views; it changes whenever any session's view may have. */ readonly version: number; /** The current tools; omitted when the caller already holds `version`. */ readonly tools?: CustomTool[]; } /** Protocol a {@link RemoteMCPManager} speaks to its main-thread manager. */ export type McpManagerProtocol = { /** One scope's tools as plain cross-thread views (data + `execute` running on main), unless `knownVersion` is current. */ tools: RpcMethod<[knownVersion: number, scope: MCPToolScope | undefined], McpToolsReply>; openToolScope: RpcMethod<[scope: MCPToolScope, seed: MCPToolScope | undefined], void>; /** Attribute a tool call; the returned release is synchronous for the worker. */ trackToolCall: RpcMethod<[scope: MCPToolScope, toolCallId: string], () => void>; /** Subscribe; the returned unsubscribe is synchronous for the worker. */ onToolsChanged: RpcMethod<[listener: () => void], () => void>; onNotification: RpcMethod<[listener: McpNotificationListener], () => void>; connectedServers: RpcMethod<[], string[]>; serverResources: RpcMethod<[ name: string ], { resources: MCPResource[]; templates: MCPResourceTemplate[]; } | undefined>; ensureServerResources: RpcMethod<[name: string], void>; waitForPendingConnections: RpcMethod<[], void>; readServerResource: RpcMethod<[ name: string, uri: string, options: MCPRequestOptions | undefined ], MCPResourceReadResult | undefined>; serverInstructions: RpcMethod<[], Map>; reconcileBrowserFilter: RpcMethod<[enabled: boolean], void>; }; /** Worker-side proxy of one main-thread `MCPManager`. */ export declare class RemoteMCPManager implements MCPManagerApi { #private; constructor(remote: RemoteObject); /** `scope`'s current tools; the views cross only when main's tool views changed since this scope's last call. */ getTools(scope?: MCPToolScope): CustomTool[]; openToolScope(scope: MCPToolScope, seed?: MCPToolScope): void; trackToolCall(scope: MCPToolScope, toolCallId: string): () => void; addToolsChangedListener(listener: () => void): () => void; addNotificationListener(listener: McpNotificationListener): () => void; getConnectedServers(): string[]; getServerResources(name: string): { resources: MCPResource[]; templates: MCPResourceTemplate[]; } | undefined; ensureServerResources(name: string): Promise; waitForPendingConnections(): Promise; readServerResource(name: string, uri: string, options?: MCPRequestOptions): Promise; getServerInstructions(): Map; reconcileBrowserFilter(enabled: boolean): Promise; }