1.0.14 • Published 11 months ago

mcplex v1.0.14

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

MCPlex

A lightweight multiplexer for managing multiple Model Context Protocol (MCP) clients.

Features

  • Support for multiple MCP clients (both SSE and StdIO transports)
  • Easy client initialization and management
  • Combined tool management across all clients
  • Type-safe configurations
  • Enable/disable functionality for clients

Installation

npm install mcplex

Usage

import { Mcplex } from 'mcplex';

// Create a new wrapper instance
const wrapper = new Mcplex();

// Initialize a StdIO client with additional options
await wrapper.initializeClient({
  name: 'linear-bot',
  type: 'stdio',
  command: 'npx',
  args: ['-y', 'linear-mcp-server'],
  env: {
    LINEAR_API_KEY: process.env.LINEAR_API_KEY,
  },
  version: '1.0.0',           // Optional: specify client version
  cwd: process.cwd(),         // Optional: specify working directory
  clientOptions: {},          // Optional: MCP client options
});

// Initialize an SSE client with options
await wrapper.initializeClient({
  name: 'sse-client',
  type: 'sse',
  url: 'http://localhost:3000/sse',
  version: '1.0.0',           // Optional: specify client version
  clientOptions: {},          // Optional: MCP client options
  options: {}                  // Optional: SSE transport options
});

// Check if a client is connected
const isConnected = wrapper.isClientConnected('linear-bot');

// Get tools for a specific client
const linearTools = wrapper.getClientTools('linear-bot');

// Get all tools from all connected clients
const allTools = wrapper.getAllTools();

// Enable/disable a client
await wrapper.setClientEnabled('linear-bot', false);

// Get list of all registered clients
const clients = wrapper.getClients();

API Reference

Mcplex

Methods

  • initializeClient(config: ClientConfig): Promise<void>

    • Initializes a new MCP client with the given configuration
  • connectClient(clientName: string): Promise<boolean>

    • Connects a specific client by name
  • isClientConnected(clientName: string): boolean

    • Returns the connection status of a specific client
  • getClientTools(clientName: string): ToolSet | undefined

    • Returns the tools available for a specific client
  • getAllTools(): ToolSet

    • Returns all tools from all connected clients combined
  • setClientEnabled(clientName: string, enabled: boolean): Promise<void>

    • Enables or disables a specific client
  • getClients(): string[]

    • Returns an array of all registered client names

Configuration Types

interface BaseClientConfig {
  name: string;
  type: "stdio" | "sse";
  enabled?: boolean;
  version?: string;
  clientOptions?: ClientOptions;
}

interface StdioClientConfig extends BaseClientConfig {
  type: "stdio";
  command: string;
  args?: string[];
  env?: Record<string, string>;
  cwd?: string;
  stderr?: boolean | "pipe";
}

interface SSEClientConfig extends BaseClientConfig {
  type: "sse";
  url: string;
  options?: {
    headers?: Record<string, string>;
    [key: string]: any;
  };
}

type ClientConfig = StdioClientConfig | SSEClientConfig;

Configuration Options

  • name: Unique identifier for the client
  • type: Type of client transport ("stdio" or "sse")
  • enabled: Whether the client should be automatically connected (optional)
  • version: Client version (optional, defaults to package version)
  • clientOptions: MCP client configuration options (optional)

For StdIO clients:

  • command: Command to execute
  • args: Command arguments (optional)
  • env: Environment variables (optional)
  • cwd: Working directory for the command (optional)
  • stderr: How to handle stderr output (optional)

For SSE clients:

  • url: SSE endpoint URL
  • options: SSE transport options including headers (optional)

License

MIT

1.0.14

11 months ago

1.0.13

11 months ago

1.0.12

11 months ago

1.0.11

11 months ago

1.0.10

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago