import type { Stream } from 'node:stream'; import { MastraBase } from '@mastra/core/base'; import type { Tool } from '@mastra/core/tools'; import type { EmptyResult, GetPromptResult, ListPromptsResult, ListResourcesResult, ListResourceTemplatesResult, ReadResourceResult } from '@modelcontextprotocol/sdk/types.js'; import { ElicitationClientActions } from './actions/elicitation.js'; import { ProgressClientActions } from './actions/progress.js'; import { PromptClientActions } from './actions/prompt.js'; import { ResourceClientActions } from './actions/resource.js'; import type { ElicitationHandler, ProgressHandler, InternalMastraMCPClientOptions, Root } from './types.js'; export type { LoggingLevel, LogMessage, LogHandler, ElicitationHandler, ProgressHandler, MastraFetchLike, MastraMCPServerDefinition, InternalMastraMCPClientOptions, Root, RequireToolApproval, RequireToolApprovalFn, RequireToolApprovalContext, } from './types.js'; /** * Internal MCP client implementation for connecting to a single MCP server. * * This class handles the low-level connection, transport management, and protocol * communication with an MCP server. Most users should use MCPClient instead. * * @internal */ export declare class InternalMastraMCPClient extends MastraBase { name: string; private client; private readonly timeout; private logHandler?; private enableServerLogs?; private enableProgressTracking?; private serverConfig; private transport?; private operationContextStore; private exitHookUnsubscribe?; private sigTermHandler?; private sigHupHandler?; private serverInstructions?; private _roots; private readonly requireToolApproval; /** Provides access to resource operations (list, read, subscribe, etc.) */ readonly resources: ResourceClientActions; /** Provides access to prompt operations (list, get, notifications) */ readonly prompts: PromptClientActions; /** Provides access to elicitation operations (request handling) */ readonly elicitation: ElicitationClientActions; /** Provides access to progress operations (notifications) */ readonly progress: ProgressClientActions; /** * @internal */ constructor({ name, version, server, capabilities, timeout, }: InternalMastraMCPClientOptions); /** * Log a message at the specified level * @param level Log level * @param message Log message * @param details Optional additional details */ private log; private setupLogging; /** * Set up handler for roots/list requests from the server. * * Per MCP spec (https://modelcontextprotocol.io/specification/2025-11-25/client/roots): * When a server sends a roots/list request, the client responds with the configured roots. */ private setupRootsHandler; /** * Get the currently configured roots. * * @returns Array of configured filesystem roots */ get roots(): Root[]; /** * Update the list of filesystem roots and notify the server. * * Per MCP spec, when roots change, the client sends a `notifications/roots/list_changed` * notification to inform the server that it should re-fetch the roots list. * * @param roots - New list of filesystem roots * * @example * ```typescript * await client.setRoots([ * { uri: 'file:///home/user/projects', name: 'Projects' }, * { uri: 'file:///tmp', name: 'Temp' } * ]); * ``` */ setRoots(roots: Root[]): Promise; /** * Send a roots/list_changed notification to the server. * * Per MCP spec, clients that support `listChanged` MUST send this notification * when the list of roots changes. The server will then call roots/list to get * the updated list. */ sendRootsListChanged(): Promise; private connectStdio; private connectHttp; private isConnected; /** * Connects to the MCP server using the configured transport. * * Automatically detects transport type based on configuration (stdio vs HTTP). * Safe to call multiple times - returns existing connection if already connected. * * @returns Promise resolving to true when connected * @throws {MastraError} If connection fails * * @internal */ connect(): Promise; /** * Gets the current session ID if using Streamable HTTP transport. * * Returns undefined if not connected or not using Streamable HTTP transport. * * @returns Session ID string or undefined * * @internal */ get sessionId(): string | undefined; /** * Gets the stderr stream of the child process, if using stdio transport with `stderr: 'pipe'`. * * Returns null if not connected, not using stdio transport, or stderr is not piped. * * @internal */ get stderr(): Stream | null; get instructions(): string | undefined; get forwardInstructions(): boolean; get instructionsMaxLength(): number; private refreshServerInstructions; disconnect(): Promise; /** * Forces a reconnection to the MCP server by disconnecting and reconnecting. * * This is useful when the session becomes invalid (e.g., after server restart) * and the client needs to establish a fresh connection. * * @returns Promise resolving when reconnection is complete * @throws {Error} If reconnection fails * * @internal */ forceReconnect(): Promise; listResources(): Promise; readResource(uri: string): Promise; subscribeResource(uri: string): Promise; unsubscribeResource(uri: string): Promise; listResourceTemplates(): Promise; /** * Fetch the list of available prompts from the MCP server. */ listPrompts(): Promise; /** * Get a prompt and its dynamic messages from the server. * @param name The prompt name * @param args Arguments for the prompt */ getPrompt({ name, args }: { name: string; args?: Record; }): Promise; /** * Register a handler to be called when the prompt list changes on the server. * Use this to refresh cached prompt lists in the client/UI if needed. */ setPromptListChangedNotificationHandler(handler: () => void): void; setResourceUpdatedNotificationHandler(handler: (params: any) => void): void; setResourceListChangedNotificationHandler(handler: () => void): void; setElicitationRequestHandler(handler: ElicitationHandler): void; setProgressNotificationHandler(handler: ProgressHandler): void; private convertInputSchema; tools(): Promise>>; private stampServerIdInMeta; } //# sourceMappingURL=client.d.ts.map