Skip to main content

MCP Client

The mcpfy client API provides a simple way to connect to MCP servers and interact with their tools, prompts, and resources. It is designed around three main concepts:
  • MCPClient — manages connections to one or more configured MCP servers.
  • MCPSession — represents an active connection to a specific MCP server.
  • Connectors — handle the underlying transport, currently supporting stdio and HTTP.
The client API is intentionally lightweight and forwards MCP operations to the official Model Context Protocol TypeScript SDK.

Installation

Or import all client utilities:

Architecture

Responsibilities


MCPClient

MCPClient is the primary entry point.

Configuration

Example


Creating a Session

The method:
  1. Checks existing sessions
  2. Looks up configuration
  3. Creates connector
  4. Connects to MCP server
  5. Creates MCPSession
  6. Stores session
  7. Returns session

Creating All Sessions

Sessions are created concurrently.

Getting a Session

Returns:

Closing Sessions

Example:

Server Configuration


Stdio Server Example

Advanced Example


HTTP Server Example

Custom Headers

Bearer Authentication

Automatically sends:

OAuth


MCPSession

Create a session:
A session provides access to:
  • Tools
  • Prompts
  • Resources
  • Resource contents

Tools

List Tools

Call Tool


Prompts

List Prompts

Get Prompt


Resources

List Resources

Read Resource


Close Session


Connectors

StdioConnector


HttpConnector

Supports:
Bearer Auth:
OAuth:

createConnectorFromConfig

Creates a StdioConnector.
Creates an HttpConnector.

Complete Example


Multiple MCP Servers

Or:

Error Handling


Public Exports

Types:

Summary

Use MCPClient for application-level connection management, MCPSession for interacting with a connected server, and connector classes when transport-level control is required.