@mcpkit-dev/testing 2.0.0 → 2.1.0

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 (2) hide show
  1. package/README.md +21 -271
  2. package/package.json +2 -1
package/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # @mcpkit-dev/testing
2
2
 
3
- Testing utilities for MCPKit MCP servers. Provides mock clients, in-memory transports, and helpers for writing comprehensive tests.
3
+ [![npm version](https://img.shields.io/npm/v/@mcpkit-dev/testing.svg)](https://www.npmjs.com/package/@mcpkit-dev/testing)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ Testing utilities for MCPKit MCP servers.
4
7
 
5
8
  ## Installation
6
9
 
@@ -8,12 +11,6 @@ Testing utilities for MCPKit MCP servers. Provides mock clients, in-memory trans
8
11
  npm install -D @mcpkit-dev/testing
9
12
  ```
10
13
 
11
- ## Features
12
-
13
- - **MockMcpClient** - Full-featured mock MCP client for testing servers
14
- - **InMemoryTransport** - Zero-latency transport for unit tests
15
- - **Test helpers** - Utilities for common testing patterns
16
-
17
14
  ## Quick Start
18
15
 
19
16
  ```typescript
@@ -46,12 +43,6 @@ describe('MyServer', () => {
46
43
  await cleanup();
47
44
  });
48
45
 
49
- it('should list available tools', async () => {
50
- const result = await client.listTools();
51
- expect(result.tools).toHaveLength(1);
52
- expect(result.tools[0].name).toBe('greet');
53
- });
54
-
55
46
  it('should call a tool', async () => {
56
47
  const result = await client.callTool('greet', { name: 'World' });
57
48
  expect(result.content[0].text).toBe('Hello, World!');
@@ -59,286 +50,45 @@ describe('MyServer', () => {
59
50
  });
60
51
  ```
61
52
 
62
- ## API Reference
53
+ ## Features
63
54
 
64
- ### MockMcpClient
55
+ - **MockMcpClient** - Full-featured mock MCP client
56
+ - **InMemoryTransport** - Zero-latency transport for unit tests
57
+ - **Test helpers** - `createTestClient()`, `waitForCondition()`
65
58
 
66
- A mock MCP client that communicates with servers over in-memory transports.
59
+ ## API
67
60
 
68
- #### Creating a Client
61
+ ### MockMcpClient
69
62
 
70
63
  ```typescript
71
- import { MockMcpClient } from '@mcpkit-dev/testing';
72
-
73
- // Create with default options
74
64
  const { client, serverTransport } = MockMcpClient.create();
75
65
 
76
- // Create with custom options
77
- const { client, serverTransport } = MockMcpClient.create({
78
- name: 'test-client',
79
- version: '1.0.0',
80
- });
81
- ```
82
-
83
- #### Methods
84
-
85
- ##### `connect(): Promise<void>`
86
-
87
- Connect the client to the server.
88
-
89
- ```typescript
90
66
  await client.connect();
91
- ```
92
-
93
- ##### `close(): Promise<void>`
94
-
95
- Close the client connection.
96
-
97
- ```typescript
67
+ await client.listTools();
68
+ await client.callTool('toolName', { arg: 'value' });
69
+ await client.listResources();
70
+ await client.readResource('uri://resource');
71
+ await client.listPrompts();
72
+ await client.getPrompt('promptName', { arg: 'value' });
98
73
  await client.close();
99
74
  ```
100
75
 
101
- ##### `listTools(): Promise<ListToolsResult>`
102
-
103
- List all available tools from the server.
104
-
105
- ```typescript
106
- const { tools } = await client.listTools();
107
- console.log(tools); // [{ name: 'greet', description: '...' }]
108
- ```
109
-
110
- ##### `callTool(name: string, args?: Record<string, unknown>)`
111
-
112
- Call a tool by name with optional arguments.
113
-
114
- ```typescript
115
- const result = await client.callTool('greet', { name: 'Alice' });
116
- console.log(result.content[0].text); // 'Hello, Alice!'
117
- ```
118
-
119
- ##### `listResources(): Promise<ListResourcesResult>`
120
-
121
- List all available resources.
122
-
123
- ```typescript
124
- const { resources } = await client.listResources();
125
- ```
126
-
127
- ##### `readResource(uri: string): Promise<ReadResourceResult>`
128
-
129
- Read a resource by URI.
130
-
131
- ```typescript
132
- const result = await client.readResource('config://settings');
133
- console.log(result.contents[0].text);
134
- ```
135
-
136
- ##### `listPrompts(): Promise<ListPromptsResult>`
137
-
138
- List all available prompts.
139
-
140
- ```typescript
141
- const { prompts } = await client.listPrompts();
142
- ```
143
-
144
- ##### `getPrompt(name: string, args?: Record<string, string>): Promise<GetPromptResult>`
145
-
146
- Get a prompt by name with optional arguments.
147
-
148
- ```typescript
149
- const result = await client.getPrompt('greeting', { name: 'Bob' });
150
- console.log(result.messages);
151
- ```
152
-
153
- ##### `rawClient: Client`
154
-
155
- Access the underlying MCP SDK client for advanced operations.
156
-
157
- ```typescript
158
- const sdkClient = client.rawClient;
159
- ```
160
-
161
76
  ### InMemoryTransport
162
77
 
163
- A transport implementation that allows direct communication between client and server without network overhead.
164
-
165
- #### Creating a Transport Pair
166
-
167
78
  ```typescript
168
- import { InMemoryTransport } from '@mcpkit-dev/testing';
169
-
170
79
  const { clientTransport, serverTransport } = InMemoryTransport.createPair();
171
-
172
- // Connect to server
173
- await server.connect(serverTransport);
174
-
175
- // Connect client
176
- await client.connect(clientTransport);
177
- ```
178
-
179
- #### Methods
180
-
181
- ##### `start(): Promise<void>`
182
-
183
- Start the transport and process any queued messages.
184
-
185
- ##### `send(message: JSONRPCMessage): Promise<void>`
186
-
187
- Send a message to the peer transport.
188
-
189
- ##### `close(): Promise<void>`
190
-
191
- Close the transport and its peer.
192
-
193
- ##### `deliverMessage(message: JSONRPCMessage): void`
194
-
195
- Directly deliver a message (for testing edge cases).
196
-
197
- ### Helper Functions
198
-
199
- #### `createTestClient(options?)`
200
-
201
- Convenience function to create a mock client.
202
-
203
- ```typescript
204
- import { createTestClient } from '@mcpkit-dev/testing';
205
-
206
- const { client, serverTransport } = createTestClient({
207
- name: 'my-test-client',
208
- });
209
80
  ```
210
81
 
211
- #### `waitForCondition(condition, options?)`
212
-
213
- Wait for a condition to be true with timeout.
82
+ ## Documentation
214
83
 
215
- ```typescript
216
- import { waitForCondition } from '@mcpkit-dev/testing';
217
-
218
- // Wait up to 5 seconds for server to be ready
219
- await waitForCondition(() => server.isReady, {
220
- timeout: 5000,
221
- interval: 100,
222
- });
223
- ```
84
+ **[Read the full documentation](https://v-checha.github.io/mcpkit/)**
224
85
 
225
- **Options:**
226
-
227
- | Option | Type | Default | Description |
228
- |--------|------|---------|-------------|
229
- | `timeout` | `number` | `5000` | Maximum time to wait (ms) |
230
- | `interval` | `number` | `50` | Check interval (ms) |
231
-
232
- #### `createTestServer(ServerClass, listenFn)`
233
-
234
- Create a complete test environment with server and connected client.
235
-
236
- ```typescript
237
- import { createTestServer } from '@mcpkit-dev/testing';
238
- import { listen } from '@mcpkit-dev/core';
239
-
240
- const { client, server, instance, cleanup } = await createTestServer(
241
- MyServer,
242
- listen
243
- );
244
-
245
- // Run tests...
246
- const tools = await client.listTools();
247
-
248
- // Clean up
249
- await cleanup();
250
- ```
251
-
252
- ## Testing Patterns
253
-
254
- ### Testing Tools
255
-
256
- ```typescript
257
- it('should handle tool errors gracefully', async () => {
258
- const result = await client.callTool('divide', { a: 10, b: 0 });
259
- expect(result.isError).toBe(true);
260
- expect(result.content[0].text).toContain('Cannot divide by zero');
261
- });
262
-
263
- it('should validate tool parameters', async () => {
264
- await expect(
265
- client.callTool('greet', { invalidParam: 'value' })
266
- ).rejects.toThrow();
267
- });
268
- ```
269
-
270
- ### Testing Resources
271
-
272
- ```typescript
273
- it('should read dynamic resources', async () => {
274
- const result = await client.readResource('users://123');
275
- const user = JSON.parse(result.contents[0].text);
276
- expect(user.id).toBe('123');
277
- });
278
-
279
- it('should list resource templates', async () => {
280
- const { resources } = await client.listResources();
281
- const template = resources.find(r => r.uri.includes('{'));
282
- expect(template).toBeDefined();
283
- });
284
- ```
285
-
286
- ### Testing Prompts
287
-
288
- ```typescript
289
- it('should generate prompt with arguments', async () => {
290
- const result = await client.getPrompt('code-review', {
291
- language: 'typescript',
292
- focus: 'security',
293
- });
294
-
295
- expect(result.messages[0].content.text).toContain('typescript');
296
- expect(result.messages[0].content.text).toContain('security');
297
- });
298
- ```
299
-
300
- ### Testing with Mocked Dependencies
301
-
302
- ```typescript
303
- import { vi } from 'vitest';
304
-
305
- // Mock external service
306
- vi.mock('./weather-api', () => ({
307
- getWeather: vi.fn().mockResolvedValue({ temp: 22, condition: 'sunny' }),
308
- }));
309
-
310
- it('should use mocked weather data', async () => {
311
- const result = await client.callTool('getWeather', { city: 'London' });
312
- expect(result.content[0].text).toContain('22');
313
- });
314
- ```
315
-
316
- ## Integration with Test Frameworks
317
-
318
- ### Vitest
319
-
320
- ```typescript
321
- import { describe, it, expect, beforeAll, afterAll } from 'vitest';
322
-
323
- describe('MCP Server Integration', () => {
324
- // ... setup and tests
325
- });
326
- ```
327
-
328
- ### Jest
329
-
330
- ```typescript
331
- import { describe, it, expect, beforeAll, afterAll } from '@jest/globals';
332
-
333
- describe('MCP Server Integration', () => {
334
- // ... setup and tests
335
- });
336
- ```
86
+ - [Testing Guide](https://v-checha.github.io/mcpkit/docs/guides/testing)
337
87
 
338
88
  ## Related Packages
339
89
 
340
- - [@mcpkit-dev/core](https://www.npmjs.com/package/@mcpkit-dev/core) - Core decorators and server framework
341
- - [@mcpkit-dev/cli](https://www.npmjs.com/package/@mcpkit-dev/cli) - CLI tool for project scaffolding
90
+ - [@mcpkit-dev/core](https://www.npmjs.com/package/@mcpkit-dev/core) - Core framework
91
+ - [@mcpkit-dev/cli](https://www.npmjs.com/package/@mcpkit-dev/cli) - CLI tool
342
92
 
343
93
  ## License
344
94
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcpkit-dev/testing",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Testing utilities for mcpkit MCP servers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -46,6 +46,7 @@
46
46
  "model-context-protocol"
47
47
  ],
48
48
  "license": "MIT",
49
+ "homepage": "https://v-checha.github.io/mcpkit",
49
50
  "repository": {
50
51
  "type": "git",
51
52
  "url": "https://github.com/v-checha/mcpkit.git",