MCP Client
Themcpfy 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.
Installation
Architecture
Responsibilities
MCPClient
MCPClient is the primary entry point.
Configuration
Example
Creating a Session
- Checks existing sessions
- Looks up configuration
- Creates connector
- Connects to MCP server
- Creates
MCPSession - Stores session
- Returns session
Creating All Sessions
Getting a Session
Closing Sessions
Server Configuration
Stdio Server Example
Advanced Example
HTTP Server Example
Custom Headers
Bearer Authentication
OAuth
MCPSession
Create a session:- 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
createConnectorFromConfig
StdioConnector.
HttpConnector.
Complete Example
Multiple MCP Servers
Error Handling
Public Exports
Summary
MCPClient for application-level connection management, MCPSession for interacting with a connected server, and connector classes when transport-level control is required.
