{"id":18042,"library":"mcp-client","title":"MCP Client for Node.js","description":"mcp-client is a Node.js client library designed for simplified interaction with servers implementing the Model Context Protocol (MCP). As of version 1.13.1, this library offers a more convenient and less verbose API compared to the official MCP TypeScript SDK, abstracting lower-level details such as pagination and direct Zod schema handling. It distinguishes itself by employing more conventional method names (e.g., `getTools` instead of `listTools`). The client supports `httpStream` (recommended) and `stdio` connection types, with Server-Sent Events (SSE) connections explicitly marked as deprecated. It provides comprehensive functionalities for tool discovery and invocation, resource management (reading, listing), prompt interaction (getting, listing, completing), and receiving logging messages from the MCP server. While a specific release cadence is not detailed, the version history and recent publish date indicate active development.","status":"active","version":"1.13.1","language":"javascript","source_language":"en","source_url":"https://github.com/punkpeye/mcp-client","tags":["javascript","MCP","Client","EventSource","SSE","typescript"],"install":[{"cmd":"npm install mcp-client","lang":"bash","label":"npm"},{"cmd":"yarn add mcp-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add mcp-client","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for defining custom result schemas when calling tools.","package":"zod","optional":true}],"imports":[{"note":"The library primarily uses named ESM imports. While CJS might work via transpilation or specific Node.js settings, direct `require()` is not the idiomatic or recommended way due to potential underlying ESM dependencies.","wrong":"const { MCPClient } = require('mcp-client');","symbol":"MCPClient","correct":"import { MCPClient } from 'mcp-client';"},{"note":"Use `import type` for type-only imports to prevent bundling issues and ensure correct TypeScript compilation.","wrong":"import { MCPClientEvents } from 'mcp-client';","symbol":"MCPClientEvents","correct":"import type { MCPClientEvents } from 'mcp-client';"}],"quickstart":{"code":"import { MCPClient } from 'mcp-client';\nimport { z } from 'zod'; // Only needed if you use custom schemas\n\nasync function runClient() {\n  const client = new MCPClient({\n    name: \"MyAwesomeMCPClient\",\n    version: \"1.0.0\",\n  });\n\n  try {\n    // Connect using the recommended Streamable HTTP transport\n    await client.connect({\n      type: \"httpStream\",\n      url: process.env.MCP_SERVER_URL ?? \"http://localhost:8080/mcp\",\n    });\n    console.log('Connected to MCP server.');\n\n    // Ping the server to check connectivity\n    await client.ping();\n    console.log('Server responded to ping.');\n\n    // List all available tools\n    const tools = await client.getAllTools();\n    console.log('Available tools:', tools.map(t => t.name));\n\n    // Example: Call a simple 'add' tool\n    const addResult = await client.callTool({\n      name: 'add',\n      arguments: { a: 5, b: 3 }\n    });\n    console.log('Result of add(5, 3):', addResult);\n\n  } catch (error) {\n    console.error('MCP client encountered an error:', error);\n  } finally {\n    // Clean up if necessary (e.g., disconnect stdio processes)\n    // For httpStream, connection is typically stateless.\n  }\n}\n\nrunClient();","lang":"typescript","description":"Initializes an MCP client, connects via httpStream, pings the server, lists tools, and calls a basic tool."},"warnings":[{"fix":"Migrate to `type: \"httpStream\"` for new client connections. Existing SSE implementations may still function due to backward compatibility in the protocol, but new development should use `httpStream`.","message":"The `type: \"sse\"` connection method is deprecated. The underlying Model Context Protocol has shifted from SSE to Streamable HTTP as the preferred transport mechanism.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Ensure your project is configured for ESM by setting `\"type\": \"module\"` in your `package.json`. If using CommonJS is unavoidable, consider dynamic `import()` or transpilation setups (e.g., Webpack/Babel) to handle ESM-only dependencies.","message":"The underlying `@modelcontextprotocol/sdk` (which `mcp-client` relies on) can cause `Error [ERR_REQUIRE_ESM]` when used in CommonJS projects, particularly due to dependencies like `pkce-challenge` being ESM-only.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Configure your project to use ES Modules by adding `\"type\": \"module\"` to your `package.json`, or use dynamic `import()` for the conflicting package if possible, though this may require modifications to `@modelcontextprotocol/sdk`'s internal handling.","cause":"Attempting to `require()` an ESM-only module within a CommonJS context, typically from an underlying dependency of `mcp-client`.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module <path>/pkce-challenge/dist/index.node.js from <path>/@modelcontextprotocol/sdk/dist/cjs/client/auth.js not supported."},{"fix":"Verify that the `url` in `client.connect()` is correct and that the MCP server is running and accessible at that address and port. Check firewall rules or network configuration if connecting to a remote server.","cause":"The client could not establish a connection to the specified MCP server within the timeout period.","error":"MCP client encountered an error: ConnectTimeoutError: Connect timeout"},{"fix":"Ensure the command is correctly spelled and is either in your system's PATH or provide an absolute path to the executable in the `command` option.","cause":"When using `type: \"stdio\"` connection, the `command` specified for launching the MCP server subprocess is not found in the system's PATH.","error":"Error: Command not found: <command_name>"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}