About this project
@mcp-z/client is a programmatic MCP client library for Node.js (requires Node.js >= 22). It supports connecting to multiple MCP servers within a single process, running MCP tools from scripts, and writing integration tests for MCP servers.
Supported transports include stdio and HTTP. HTTP servers can optionally be spawned via a `start` block extension using the `dialects: ['start']` option. The library also supports OAuth via Dynamic Client Registration (DCR) when an HTTP server supports it, allowing a token store (e.g., Keyv) to be passed through `dcrAuthenticator`.
Core API centers around a server registry created via `createServerRegistry(config, options?)`. The registry provides methods to connect to named servers (`registry.connect`), search capabilities across servers (`registry.searchCapabilities`), and close all connections (`registry.close`). Managed clients expose methods to call tools (`callTool`), get prompts (`getPrompt`), read resources (`readResource`), and list tools, resources, or prompts. Raw SDK response variants are also available (`callToolRaw`, `getPromptRaw`, `readResourceRaw`).
Response wrappers provide helper methods: `json()` for parsing structured content, `text()` for the first text result, and `raw()` for the raw MCP response. Registry options include `cwd` for spawned process working directory, `env` for base environment variables, and `dialects` to control which server types to spawn (stdio servers, HTTP start blocks, or both). API documentation is available at the project's documentation site.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.