mcp-use TypeScript API
    Preparing search index...

    Class BaseConnectorAbstract

    Implements protocol operations shared by MCP transport connectors.

    Subclasses provide transport-specific connection setup and a public identifier. Call BaseConnector.connect, then BaseConnector.initialize, before invoking protocol operations.

    Hierarchy (View Summary)

    Index
    • get instructions(): string | undefined

      Instructions supplied by the connected server, if any.

      Returns string | undefined

    • get isClientConnected(): boolean

      Whether an SDK client currently exists for this connector.

      Returns boolean

    • get negotiatedProtocolVersion(): string | undefined

      The protocol version string negotiated for the active connection.

      Returns string | undefined

    • get protocolEra(): ProtocolEra | undefined

      The negotiated protocol era for the active connection.

      • "legacy" — 2025-era server, sessionful initialize handshake.
      • "modern" — 2026-era server, stateless per-request. undefined before the connection has negotiated.

      Returns ProtocolEra | undefined

    • get publicIdentifier(): Record<string, string>

      Returns transport-specific fields suitable for logs and telemetry.

      Returns Record<string, string>

      A record identifying the connector without exposing credentials.

    • get serverCapabilities(): Record<string, unknown>

      Capabilities cached during initialization, or an empty object.

      Returns Record<string, unknown>

    • get serverInfo(): MCPServerInfo | null

      Server identity cached during initialization, or null.

      Returns MCPServerInfo | null

    • get tools(): {}[]

      Returns the tool list cached during initialization.

      Returns {}[]

      When BaseConnector.initialize has not completed.

    • Calls a tool on the connected server.

      Parameters

      • name: string

        Tool name.

      • args: Record<string, any>

        Tool arguments.

      • Optionaloptions: RequestOptions

        Per-request timeout, cancellation, and progress options.

      Returns Promise<{ [key: string]: unknown }>

      The tool result returned by the server.

      When the connector is not connected or the tool call fails.

    • Request completion suggestions for a prompt or resource template argument

      Parameters

      • params: {}

        Completion request parameters

      • Optionaloptions: RequestOptions

        Request options

      Returns Promise<{ [key: string]: unknown }>

      Completion suggestions from the server

    • Establishes the transport connection and creates the SDK client.

      Returns Promise<void>

      A promise that resolves when the connector is connected.

    • Disconnects the SDK client and releases transport resources.

      Returns Promise<void>

      A promise that resolves after cleanup completes.

    • Gets a prompt with the supplied arguments.

      Parameters

      • name: string

        Prompt name.

      • args: Record<string, any>

        Prompt arguments.

      Returns Promise<{ [key: string]: unknown }>

      The rendered prompt returned by the server.

    • Returns the roots currently advertised to the server.

      Returns {}[]

      A copy of the configured roots.

    • Initialise the MCP session after connect() has succeeded.

      In the SDK, Client.connect(transport) automatically performs the protocol‑level initialize handshake, so we only need to cache the list of tools and expose some server info.

      Parameters

      • defaultRequestOptions: RequestOptions = ...

        Options used while fetching the initial tool list.

      Returns Promise<{} | undefined>

      The capabilities advertised by the server.

      When BaseConnector.connect has not completed.

    • List all resources from the server, automatically handling pagination

      Parameters

      • Optionaloptions: RequestOptions

        Request options

      Returns Promise<{ resources: any[] }>

      Complete list of all resources

    • Lists prompts exposed by the server.

      Returns Promise<{ [key: string]: unknown }>

      The prompt list, or an empty list when prompts are unsupported.

    • List resources from the server with optional pagination

      Parameters

      • Optionalcursor: string

        Optional cursor for pagination

      • Optionaloptions: RequestOptions

        Request options

      Returns Promise<{ [key: string]: unknown }>

      Resource list with optional nextCursor for pagination

    • List resource templates from the server

      Parameters

      • Optionaloptions: RequestOptions

        Request options

      Returns Promise<{ [key: string]: unknown }>

      List of available resource templates

    • List all available tools from the MCP server. This method fetches fresh tools from the server, unlike the tools getter which returns cached tools.

      Parameters

      • Optionaloptions: RequestOptions

        Optional request options

      Returns Promise<{}[]>

      Array of available tools

    • Register a handler for server notifications

      Parameters

      Returns void

      connector.onNotification((notification) => {
      console.log(`Received: ${notification.method}`, notification.params);
      });
    • Reads a resource by URI.

      Parameters

      • uri: string

        Resource URI to read.

      • Optionaloptions: RequestOptions

        Per-request options.

      Returns Promise<{ [key: string]: unknown }>

      The resource contents returned by the server.

    • Sends a raw, potentially non-standard request through the SDK client.

      Parameters

      • method: string

        JSON-RPC method name.

      • params: Record<string, any> | null = null

        Request parameters. Defaults to an empty object.

      • Optionaloptions: RequestOptions

        Per-request options.

      Returns Promise<unknown>

      The unvalidated result returned by the server.

    • Set roots and notify the server. Roots represent directories or files that the client has access to.

      Parameters

      • roots: {}[]

        Array of Root objects with uri (must start with "file://") and optional name

      Returns Promise<void>

      Roots are retained only for v1 compatibility.

      await connector.setRoots([
      { uri: "file:///home/user/project", name: "My Project" },
      { uri: "file:///home/user/data" }
      ]);
    • Subscribe to resource updates

      Parameters

      • uri: string

        URI of the resource to subscribe to

      • Optionaloptions: RequestOptions

        Request options

      Returns Promise<{}>

    • Unsubscribe from resource updates

      Parameters

      • uri: string

        URI of the resource to unsubscribe from

      • Optionaloptions: RequestOptions

        Request options

      Returns Promise<{}>