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.
npm install mcp-clientVerified import paths — ran on the pinned version, not inferred.
Initializes an MCP client, connects via httpStream, pings the server, lists tools, and calls a basic tool.
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`.
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.
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.
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.
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.