A robust Node.js client for connecting to Model Context Protocol (MCP) servers with automatic reconnect, authentication, and flexible transport support.
- Connects to MCP servers with automatic reconnect
- Supports both ESM and CommonJS
- Customizable log, transport, and client classes
- Reads configuration from environment variables or options
- TypeScript type definitions included
npm install @eliware/mcp-clientimport mcpClient from '@eliware/mcp-client';
(async () => {
try {
const client = await mcpClient({
// token: 'your-mcp-token',
// baseUrl: 'http://localhost:1234/',
});
console.log('MCP Client connected:', !!client);
// Use the client as needed...
} catch (err) {
console.error('Failed to connect MCP Client:', err);
}
})();const mcpClient = require('@eliware/mcp-client');
(async () => {
try {
const client = await mcpClient({
// token: 'your-mcp-token',
// baseUrl: 'http://localhost:1234/',
});
console.log('MCP Client connected:', !!client);
// Use the client as needed...
} catch (err) {
console.error('Failed to connect MCP Client:', err);
}
})();Creates and connects an MCP client. Returns a connected client instance. Automatically reconnects on disconnect.
log(optional): Custom log (default: @eliware/log)port(optional): MCP server port (default: 1234)baseUrl(optional): MCP server URL (default: http://localhost:1234/)token(optional): Authentication token (default: from MCP_TOKEN env)ClientClass(optional): Custom client class (default: SDK Client)TransportClass(optional): Custom transport class (default: SDK StreamableHTTPClientTransport)
Type definitions are included:
import mcpClient, { McpClientOptions } from '@eliware/mcp-client';
const client = await mcpClient({
token: 'your-mcp-token',
baseUrl: 'http://localhost:1234/',
} as McpClientOptions);For help, questions, or to chat with the author and community, visit:


