UNPKG

pocketsmith-mcp

Version:

MCP server for managing budgets via PocketSmith API

34 lines (33 loc) 2 kB
/** * @fileoverview Handles the detailed logic for establishing a new MCP client connection. * This module encapsulates the steps involved in connecting to an MCP server, * including configuration validation, client identity setup, transport acquisition, * client instantiation, event handling, and the MCP initialization handshake. * @module src/mcp-client/core/clientConnectionLogic */ import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { McpError } from "../../types-global/errors.js"; import { RequestContext } from "../../utils/index.js"; /** * Type for the disconnect function that will be passed into `establishNewMcpConnection`. * This helps break the circular dependency with clientManager. */ type DisconnectFunction = (serverName: string, context: RequestContext, error?: Error | McpError) => Promise<void>; /** * Establishes a new connection to the specified MCP server. * This function performs the core steps of connecting, including configuration validation, * client identity setup, transport acquisition, SDK client instantiation, event handler setup, * and the MCP initialization handshake. * * IMPORTANT: This function is intended to be wrapped by a higher-level error handler * (e.g., ErrorHandler.tryCatch in clientManager.ts) to manage exceptions. * * @param serverName - The unique name of the MCP server to connect to. * @param operationContext - The request context for this connection attempt. * @param disconnectFn - A function to call for disconnecting the client (passed from clientManager). * @returns A promise that resolves to the connected and initialized `ConnectedMcpClient` instance. * @throws {McpError} If server configuration is missing/invalid, transport cannot be established, * or if the connection/MCP initialization fails. */ export declare function establishNewMcpConnection(serverName: string, operationContext: RequestContext, disconnectFn: DisconnectFunction): Promise<Client>; export {};