import type { ToolDefinition } from '../types/messages.js'; import { type McpTransport } from './protocol.js'; /** A tool an MCP server offers. */ export interface McpToolDescriptor { /** The tool's name. */ name: string; /** What the tool does, for the model. */ description?: string; /** JSON Schema for the arguments. */ inputSchema?: Record; } /** A resource an MCP server offers. */ export interface McpResourceDescriptor { /** The resource's URI. */ uri: string; /** A readable name. */ name?: string; /** What the resource contains. */ description?: string; /** Its MIME type. */ mimeType?: string; } /** One piece of content from an MCP server: text, or base64 data with a MIME type. */ export interface McpContent { /** `text`, `image`, `resource`, or another type the server defines. */ type: string; /** The text, for text content. */ text?: string; /** Base64 data, for binary content. */ data?: string; /** MIME type of `data`. */ mimeType?: string; [key: string]: unknown; } /** What a tool call returned. */ export interface McpToolResult { /** The result, as content parts. */ content: McpContent[]; /** True when the tool reported a failure rather than a result. */ isError?: boolean; } /** Options for an MCP client. */ export interface McpClientOptions { /** Name and version this client reports in the handshake. */ clientInfo?: { name: string; version: string; }; /** How long a request waits before failing. Defaults to 30 seconds. */ timeoutMs?: number; } /** * Talks to an MCP server. * * This is how the package reaches a tool ecosystem without maintaining its own catalogue of * integrations: anything exposed over MCP — a filesystem server, a database, an internal service — * becomes tools an agent can call, through `toNexusTools()`. */ export declare class McpClient { private readonly transport; private readonly options; private readonly pending; private nextId; private initialized; private connecting; private serverInfo; constructor(transport: McpTransport, options?: McpClientOptions); /** * Performs the handshake and returns the server's name and version. Called automatically by the * first request that needs it; requests made together share one handshake. */ connect(): Promise<{ name?: string; version?: string; }>; private handshake; /** Lists the server's tools. */ listTools(): Promise; /** * Calls a tool. A tool that fails reports `isError` rather than throwing; a protocol failure * throws `McpError`. */ callTool(name: string, args?: Record): Promise; /** Lists the server's resources. */ listResources(): Promise; /** Reads a resource's content. */ readResource(uri: string): Promise; /** Lists the server's prompts. */ listPrompts(): Promise>; /** Renders a prompt with arguments into messages. */ getPrompt(name: string, args?: Record): Promise>; /** * The server's tools, ready for `createAgent` or `ToolExecutor`. * * Names are prefixed when asked, because two servers can both offer `search` and a model has to be * able to tell them apart. */ toNexusTools(options?: { prefix?: string; }): Promise; /** Closes the connection and rejects every request still waiting. */ close(): Promise; private request; private notify; private receive; private settle; private failAll; } /** Launches a local MCP server as a child process and talks to it over stdin and stdout. */ export interface StdioClientOptions { /** Executable to run. */ command: string; /** Its arguments. */ args?: string[]; /** Environment variables for the process. */ env?: Record; /** Working directory for the process. */ cwd?: string; } /** * Runs an MCP server as a child process and speaks to it over its stdin and stdout. * * The transport most MCP servers ship with. `node:child_process` is imported lazily, so a browser * or edge build that only uses the HTTP transport never reaches for it. */ export declare function createStdioTransport(options: StdioClientOptions): McpTransport; /** Connects to a remote MCP server over HTTP. */ export interface HttpClientOptions { /** The server's endpoint. */ url: string; /** Headers sent with every request, such as authorization. */ headers?: Record; /** Replaces the global `fetch`. */ fetch?: typeof globalThis.fetch; } /** * Speaks to an MCP server over HTTP, one POST per message. * * Server-initiated streaming is not implemented: this covers request and response, which is what * calling a tool needs. */ export declare function createHttpTransport(options: HttpClientOptions): McpTransport;