Docs: https://mcp-z.github.io/client Programmatic MCP client for spawning, connecting to, and calling MCP servers.
npm install --save-dev @mcp-z/client
Requires Node.js >= 22.
import { createServerRegistry } from '@mcp-z/client';
const registry = createServerRegistry({
todoist: { type: 'http', url: 'https://ai.todoist.net/mcp' }
});
const client = await registry.connect('todoist');
await client.callTool('add-tasks', {
tasks: [{ content: 'Learn MCP', priority: 4 }]
});
await registry.close();
MCP supports stdio and HTTP.
Stdio
{
echo: {
command: 'node',
args: ['server.js'],
env: { LOG_LEVEL: 'info' }
}
}
HTTP
{
todoist: {
type: 'http',
url: 'https://ai.todoist.net/mcp',
headers: { Authorization: 'Bearer token' }
}
}
HTTP with start block (extension)
Use dialects: ['start'] to spawn HTTP servers with start blocks.
const registry = createServerRegistry(
{
api: {
type: 'http',
url: 'http://localhost:3000/mcp',
start: { command: 'node', args: ['server.js'] }
}
},
{ dialects: ['start'] }
);
createServerRegistry(config, options?)registry.connect(name, options?)registry.searchCapabilities(query, options?)registry.close()client.callTool(name, args)client.getPrompt(name, args)client.readResource(uri)client.listTools() / client.listResources() / client.listPrompts()client.callToolRaw() / client.getPromptRaw() / client.readResourceRaw() (raw SDK responses)Tool, prompt, and resource calls return wrappers with:
json() - Parse structured contenttext() - First text resultraw() - Raw MCP responseconst response = await client.callTool('drive-search', { query: 'Q4 Reports' });
const data = response.json();
const prompt = await client.getPrompt('query-syntax', { service: 'gmail' });
console.log(prompt.text());
const resource = await client.readResource('mcp-pdf://abc123');
console.log(resource.text());
const results = await registry.searchCapabilities('message send', {
types: ['tool'],
servers: ['gmail', 'outlook']
});
cwd - Working directory for spawned processes (default: process.cwd())env - Base env for all servers (if set, process.env is not merged)dialects - Which servers to spawn: ['servers'] (stdio), ['start'] (HTTP start blocks), or bothIf an HTTP server supports DCR, pass a token store via dcrAuthenticator:
import Keyv from 'keyv';
import { createServerRegistry } from '@mcp-z/client';
const registry = createServerRegistry({
todoist: { type: 'http', url: 'https://ai.todoist.net/mcp' }
});
const client = await registry.connect('todoist', {
dcrAuthenticator: { tokenStore: new Keyv() }
});