@mcp-z/client 2.2.1 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +39 -14
  2. package/package.json +3 -3
  3. package/AGENTS.md +0 -159
package/README.md CHANGED
@@ -11,25 +11,42 @@ Programmatic MCP client library for Node.js - connect, discover, and call tools
11
11
  ## Install
12
12
 
13
13
  ```bash
14
- npm install --save-dev @mcp-z/client
14
+ npm install @mcp-z/client
15
15
  ```
16
16
 
17
- Requires Node.js >= 22.
17
+ Requires Node.js >= 20.
18
18
 
19
19
  ## Quick start
20
20
 
21
- ```ts
22
- import { createServerRegistry } from '@mcp-z/client';
21
+ Create a local stdio server that exposes an `echo` tool:
23
22
 
24
- const registry = createServerRegistry({
25
- todoist: { type: 'http', url: 'https://ai.todoist.net/mcp' }
26
- });
23
+ ```bash
24
+ npm install @modelcontextprotocol/sdk zod
25
+ ```
27
26
 
28
- const client = await registry.connect('todoist');
29
- await client.callTool('add-tasks', {
30
- tasks: [{ content: 'Learn MCP', priority: 4 }]
31
- });
27
+ Save this as `echo-server.mjs`:
28
+
29
+ ```js
30
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
31
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
32
+ import { z } from 'zod';
33
+
34
+ const server = new McpServer({ name: 'echo', version: '1.0.0' });
35
+ server.registerTool('echo', { inputSchema: { message: z.string() } }, async ({ message }) => ({
36
+ content: [{ type: 'text', text: message }]
37
+ }));
38
+ await server.connect(new StdioServerTransport());
39
+ ```
40
+
41
+ Connect to it and print the returned text:
42
+
43
+ ```ts
44
+ import { createServerRegistry } from '@mcp-z/client';
32
45
 
46
+ const registry = createServerRegistry({ echo: { command: 'node', args: ['echo-server.mjs'] } });
47
+ const client = await registry.connect('echo');
48
+ const response = await client.callTool('echo', { message: 'hello MCP' });
49
+ console.log(response.text()); // hello MCP
33
50
  await registry.close();
34
51
  ```
35
52
 
@@ -176,12 +193,20 @@ const pinned = await registry.connect('strict-server', {
176
193
 
177
194
  After connecting, `client.getProtocolEra()` returns `'modern'` or `'legacy'` and `client.getNegotiatedProtocolVersion()` the revision the server settled on.
178
195
 
179
- Note: with `mode: 'auto'` against a stdio server, a legacy server that never answers the `server/discover` probe costs the full request timeout (60s) before the client falls back to the 2025 sequence. The probe ends fast when the server answers it at all — with any reply, even a "method not found" error.
196
+ With `mode: 'auto'` against a stdio server, a legacy server that never answers the `server/discover` probe costs the full 60-second request timeout before the client falls back to the 2025 sequence. Any reply, including a "method not found" error, ends the probe.
180
197
 
181
198
  ## Requirements
182
199
 
183
- - Node.js >= 22
200
+ - Node.js >= 20
201
+
202
+ ## Agent skill
203
+
204
+ If a coding agent will use this package, install its agent guidance globally:
205
+
206
+ ```bash
207
+ npx skills add https://github.com/mcp-z/client.git -g -s mcp-z-client
208
+ ```
184
209
 
185
- ### Documentation
210
+ ## Documentation
186
211
 
187
212
  [API Docs](https://mcp-z.github.io/client)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-z/client",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "Programmatic MCP client library for Node.js - connect, discover, and call tools on Model Context Protocol servers.",
5
5
  "keywords": [
6
6
  "mcp",
@@ -45,8 +45,7 @@
45
45
  "types": "./dist/esm/index.d.ts",
46
46
  "files": [
47
47
  "dist",
48
- "schemas",
49
- "AGENTS.md"
48
+ "schemas"
50
49
  ],
51
50
  "scripts": {
52
51
  "build": "tsds validate",
@@ -70,6 +69,7 @@
70
69
  },
71
70
  "devDependencies": {
72
71
  "@modelcontextprotocol/sdk": "^1.30.0",
72
+ "@modelcontextprotocol/server": "^2.0.0",
73
73
  "@types/express": "^5.0.6",
74
74
  "@types/mocha": "^10.0.10",
75
75
  "@types/node": "^26.2.0",
package/AGENTS.md DELETED
@@ -1,159 +0,0 @@
1
- # MCP Examples for AI Agents
2
-
3
- Quick-start examples for building scripts with MCP servers using `@mcp-z/client`.
4
-
5
- ## Install
6
-
7
- ```bash
8
- npm install @mcp-z/client
9
- ```
10
-
11
- ## Quick Peek
12
-
13
- ```javascript
14
- import { createServerRegistry } from '@mcp-z/client';
15
-
16
- const registry = createServerRegistry({ todoist: { url: 'https://ai.todoist.net/mcp' } });
17
- const client = await registry.connect('todoist');
18
- await client.callTool('add-tasks', { tasks: [{ content: 'My task', priority: 4 }] });
19
- await registry.close();
20
- ```
21
-
22
- ## Full Example: Todoist Task Management
23
-
24
- ```javascript
25
- /**
26
- * This example shows how to use @mcp-z/client to manage tasks via Todoist.
27
- * Copy this and modify it for your needs!
28
- *
29
- * PREREQUISITES:
30
- * npm install @mcp-z/client # the client library for typescript / javascript
31
- * npm install @mcp-z/cli # the cli command is "mcpz". Run "mcpz --help" for a full list of commands
32
- *
33
- * DISCOVERY (find tools before writing code):
34
- * npx @mcp-z/cli search "add task" # Find the tool you need
35
- * npx @mcp-z/cli inspect --servers todoist # See all available tools
36
- * npx @mcp-z/cli call-tool todoist add-tasks '{}' # Test it works
37
- *
38
- * TIP: Or load your own .mcp.json file instead of inline config:
39
- * const config = JSON.parse(fs.readFileSync('.mcp.json', 'utf-8'));
40
- * const registry = createServerRegistry(config.mcpServers);
41
- */
42
-
43
- import { createServerRegistry } from '@mcp-z/client';
44
-
45
- // Configure your MCP servers (inline, or load from .mcp.json file)
46
- const servers = {
47
- todoist: {
48
- url: 'https://ai.todoist.net/mcp'
49
- }
50
- };
51
-
52
- async function main() {
53
- const registry = createServerRegistry(servers);
54
-
55
- try {
56
- console.log('šŸš€ Connecting to Todoist...');
57
- const client = await registry.connect('todoist');
58
-
59
- console.log('āœ… Connected! Adding task...');
60
-
61
- // Add a task to Todoist
62
- // See available tools: npx @mcp-z/cli inspect --servers todoist
63
- await client.callTool('add-tasks', {
64
- tasks: [
65
- {
66
- content: 'Learn MCP with @mcp-z/client',
67
- projectId: undefined, // Optional: add to specific project
68
- priority: 4 // 1-4, where 4 is highest
69
- }
70
- ]
71
- });
72
-
73
- console.log('āœ… Task added successfully!');
74
-
75
- // List tasks (discovery first: npx @mcp-z/cli inspect --servers todoist)
76
- console.log('\nšŸ“‹ Fetching tasks...');
77
- const findResponse = await client.callTool('find-tasks', {
78
- searchText: 'Learn MCP'
79
- });
80
-
81
- console.log('āœ… Tasks found:', findResponse.json());
82
-
83
- } catch (error) {
84
- console.error('āŒ Error:', error.message);
85
- process.exit(1);
86
- } finally {
87
- console.log('šŸ”’ Closing connection...');
88
- await registry.close();
89
- console.log('āœ… Done!');
90
- }
91
- }
92
-
93
- main();
94
- ```
95
-
96
- ## The Pattern
97
-
98
- Once you understand this example, you understand them all:
99
-
100
- ```javascript
101
- import { createServerRegistry } from '@mcp-z/client';
102
-
103
- const registry = createServerRegistry(servers); // Configure servers
104
- try {
105
- const client = await registry.connect('server-name'); // Connect
106
- await client.callTool('tool-name', { /* args */ }); // Use tools
107
- } finally {
108
- await registry.close(); // Always cleanup
109
- }
110
- ```
111
-
112
- **Configure servers inline or from `.mcp.json`:**
113
- ```javascript
114
- // Inline config
115
- const servers = { todoist: { url: '...' } };
116
-
117
- // Or load from file
118
- const config = JSON.parse(fs.readFileSync('.mcp.json', 'utf-8'));
119
- const servers = config.mcpServers;
120
- ```
121
-
122
- ## Discovery Workflow
123
-
124
- **Before writing code, discover what's available:**
125
-
126
- 1. **Search for tools:**
127
- ```bash
128
- npx @mcp-z/cli search "add task"
129
- ```
130
-
131
- 2. **Inspect a server:**
132
- ```bash
133
- npx @mcp-z/cli inspect --servers todoist
134
- ```
135
-
136
- 3. **Test a tool:**
137
- ```bash
138
- npx @mcp-z/cli call-tool todoist add-tasks '{"tasks":[{"content":"Test"}]}'
139
- ```
140
-
141
- 4. **Write your script** using `@mcp-z/client`
142
-
143
- ## Available Public Servers
144
-
145
- These servers don't need special setup - just use their URLs:
146
-
147
- - **Todoist**: `https://ai.todoist.net/mcp`
148
- - **Notion**: `https://mcp.notion.com/mcp`
149
-
150
- Private servers (require authentication):
151
- - Google Sheets, Drive, Gmail, Outlook, PDF (contact us for access)
152
-
153
- ## Need Help?
154
-
155
- 1. **Discover tools**: `npx @mcp-z/cli search <query>`
156
- 2. **See all tools**: `npx @mcp-z/cli inspect --servers <server>`
157
- 3. **Test first**: `npx @mcp-z/cli call-tool <server> <tool> '{}'`
158
-
159
- Once you know a tool works via CLI, use it in your script with `@mcp-z/client`!