simple-dynamsoft-mcp 2.2.0 → 2.2.1

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Xiao Ling
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -87,8 +87,8 @@ Configuration:
87
87
 
88
88
  Global Location:
89
89
 
90
- - **macOS**: `~/.mcp.json`
91
- - **Windows**: `%USERPROFILE%\.mcp.json`
90
+ - **macOS**: `~/Library/Application Support/Code/User/mcp.json`
91
+ - **Windows**: `%APPDATA%\Code\User\mcp.json`
92
92
 
93
93
  ```json
94
94
  {
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "simple-dynamsoft-mcp",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "MCP server for Dynamsoft SDKs - Barcode Reader (Mobile/Python/Web) and Dynamic Web TWAIN. Provides documentation, code snippets, and API guidance.",
5
+ "license": "MIT",
5
6
  "repository": {
6
7
  "type": "git",
7
8
  "url": "https://github.com/yushulx/simple-dynamsoft-mcp.git"
@@ -17,7 +18,6 @@
17
18
  "src",
18
19
  "data",
19
20
  "code-snippet",
20
- "test",
21
21
  "README.md"
22
22
  ],
23
23
  "scripts": {
@@ -1,496 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Automated tests for Dynamsoft MCP Server
5
- * Run with: node test/server.test.js
6
- */
7
-
8
- import { spawn } from 'child_process';
9
- import { fileURLToPath } from 'url';
10
- import { dirname, join } from 'path';
11
-
12
- const __filename = fileURLToPath(import.meta.url);
13
- const __dirname = dirname(__filename);
14
- const serverPath = join(__dirname, '..', 'src', 'index.js');
15
-
16
- // Test counters
17
- let passed = 0;
18
- let failed = 0;
19
- const results = [];
20
-
21
- /**
22
- * Send a JSON-RPC request to the server and get the response
23
- */
24
- async function sendRequest(request) {
25
- return new Promise((resolve, reject) => {
26
- const proc = spawn('node', [serverPath], {
27
- stdio: ['pipe', 'pipe', 'pipe']
28
- });
29
-
30
- let stdout = '';
31
- let stderr = '';
32
-
33
- proc.stdout.on('data', (data) => {
34
- stdout += data.toString();
35
- });
36
-
37
- proc.stderr.on('data', (data) => {
38
- stderr += data.toString();
39
- });
40
-
41
- proc.on('close', (code) => {
42
- try {
43
- // Parse only the JSON-RPC response (last complete JSON object)
44
- const lines = stdout.trim().split('\n');
45
- const jsonLine = lines.find(line => {
46
- try {
47
- const parsed = JSON.parse(line);
48
- return parsed.jsonrpc === '2.0';
49
- } catch {
50
- return false;
51
- }
52
- });
53
-
54
- if (jsonLine) {
55
- resolve(JSON.parse(jsonLine));
56
- } else {
57
- reject(new Error(`No valid JSON-RPC response. stdout: ${stdout}, stderr: ${stderr}`));
58
- }
59
- } catch (e) {
60
- reject(new Error(`Failed to parse response: ${e.message}. stdout: ${stdout}`));
61
- }
62
- });
63
-
64
- proc.on('error', reject);
65
-
66
- // Send the request and close stdin
67
- proc.stdin.write(JSON.stringify(request) + '\n');
68
- proc.stdin.end();
69
- });
70
- }
71
-
72
- /**
73
- * Run a test case
74
- */
75
- async function test(name, fn) {
76
- try {
77
- await fn();
78
- passed++;
79
- results.push({ name, status: '✅ PASSED' });
80
- console.log(`✅ ${name}`);
81
- } catch (error) {
82
- failed++;
83
- results.push({ name, status: '❌ FAILED', error: error.message });
84
- console.log(`❌ ${name}`);
85
- console.log(` Error: ${error.message}`);
86
- }
87
- }
88
-
89
- /**
90
- * Assert helper
91
- */
92
- function assert(condition, message) {
93
- if (!condition) {
94
- throw new Error(message || 'Assertion failed');
95
- }
96
- }
97
-
98
- // ============================================
99
- // Test Cases
100
- // ============================================
101
-
102
- console.log('\n🧪 Dynamsoft MCP Server Test Suite\n');
103
- console.log('='.repeat(50));
104
-
105
- // Test 1: Server initialization
106
- await test('Server responds to initialize request', async () => {
107
- const response = await sendRequest({
108
- jsonrpc: '2.0',
109
- id: 1,
110
- method: 'initialize',
111
- params: {
112
- protocolVersion: '2024-11-05',
113
- capabilities: {},
114
- clientInfo: { name: 'test-client', version: '1.0.0' }
115
- }
116
- });
117
-
118
- assert(response.result, 'Should have result');
119
- assert(response.result.serverInfo, 'Should have serverInfo');
120
- assert(response.result.serverInfo.name === 'simple-dynamsoft-mcp', 'Server name should match');
121
- });
122
-
123
- // Test 2: List tools
124
- await test('tools/list returns all 18 tools', async () => {
125
- const response = await sendRequest({
126
- jsonrpc: '2.0',
127
- id: 1,
128
- method: 'tools/list'
129
- });
130
-
131
- assert(response.result, 'Should have result');
132
- assert(response.result.tools, 'Should have tools array');
133
- assert(response.result.tools.length === 18, `Expected 18 tools, got ${response.result.tools.length}`);
134
-
135
- const toolNames = response.result.tools.map(t => t.name);
136
- const expectedTools = [
137
- 'list_sdks', 'get_sdk_info', 'list_samples', 'list_python_samples',
138
- 'list_web_samples', 'list_dwt_categories', 'get_code_snippet',
139
- 'get_web_sample', 'get_python_sample', 'get_dwt_sample', 'get_quick_start',
140
- 'get_gradle_config', 'get_license_info', 'get_api_usage', 'search_samples',
141
- 'generate_project', 'search_dwt_docs', 'get_dwt_api_doc'
142
- ];
143
-
144
- for (const expected of expectedTools) {
145
- assert(toolNames.includes(expected), `Missing tool: ${expected}`);
146
- }
147
- });
148
-
149
- // Test 3: list_sdks tool
150
- await test('list_sdks returns SDK information', async () => {
151
- const response = await sendRequest({
152
- jsonrpc: '2.0',
153
- id: 1,
154
- method: 'tools/call',
155
- params: {
156
- name: 'list_sdks',
157
- arguments: {}
158
- }
159
- });
160
-
161
- assert(response.result, 'Should have result');
162
- assert(response.result.content, 'Should have content');
163
- assert(response.result.content.length > 0, 'Should have content items');
164
-
165
- const text = response.result.content[0].text;
166
- assert(text.includes('dbr-mobile'), 'Should include dbr-mobile');
167
- assert(text.includes('dbr-python'), 'Should include dbr-python');
168
- assert(text.includes('dbr-web'), 'Should include dbr-web');
169
- assert(text.includes('dwt'), 'Should include dwt');
170
- });
171
-
172
- // Test 4: get_sdk_info tool
173
- await test('get_sdk_info returns detailed SDK info', async () => {
174
- const response = await sendRequest({
175
- jsonrpc: '2.0',
176
- id: 1,
177
- method: 'tools/call',
178
- params: {
179
- name: 'get_sdk_info',
180
- arguments: { sdk_id: 'dbr-mobile' }
181
- }
182
- });
183
-
184
- assert(response.result, 'Should have result');
185
- assert(response.result.content, 'Should have content');
186
-
187
- const text = response.result.content[0].text;
188
- assert(text.includes('Android') || text.includes('android'), 'Should include Android');
189
- assert(text.includes('11.2.5000'), 'Should include version');
190
- });
191
-
192
- // Test 5: get_license_info tool (requires platform parameter)
193
- await test('get_license_info returns trial license', async () => {
194
- const response = await sendRequest({
195
- jsonrpc: '2.0',
196
- id: 1,
197
- method: 'tools/call',
198
- params: {
199
- name: 'get_license_info',
200
- arguments: { platform: 'android' }
201
- }
202
- });
203
-
204
- assert(response.result, 'Should have result');
205
- assert(!response.result.isError, 'Should not be an error');
206
-
207
- const text = response.result.content[0].text;
208
- assert(text.includes('DLS2') || text.includes('License'), 'Should include license info');
209
- });
210
-
211
- // Test 6: list_samples tool
212
- await test('list_samples returns mobile samples', async () => {
213
- const response = await sendRequest({
214
- jsonrpc: '2.0',
215
- id: 1,
216
- method: 'tools/call',
217
- params: {
218
- name: 'list_samples',
219
- arguments: { platform: 'android' }
220
- }
221
- });
222
-
223
- assert(response.result, 'Should have result');
224
-
225
- const text = response.result.content[0].text;
226
- assert(text.includes('android'), 'Should include android');
227
- });
228
-
229
- // Test 7: list_python_samples tool
230
- await test('list_python_samples returns Python samples', async () => {
231
- const response = await sendRequest({
232
- jsonrpc: '2.0',
233
- id: 1,
234
- method: 'tools/call',
235
- params: {
236
- name: 'list_python_samples',
237
- arguments: {}
238
- }
239
- });
240
-
241
- assert(response.result, 'Should have result');
242
- // Should return samples or indicate no local samples
243
- assert(response.result.content, 'Should have content');
244
- });
245
-
246
- // Test 8: list_dwt_categories tool
247
- await test('list_dwt_categories returns DWT categories', async () => {
248
- const response = await sendRequest({
249
- jsonrpc: '2.0',
250
- id: 1,
251
- method: 'tools/call',
252
- params: {
253
- name: 'list_dwt_categories',
254
- arguments: {}
255
- }
256
- });
257
-
258
- assert(response.result, 'Should have result');
259
- // Should return categories or indicate they exist
260
- assert(response.result.content, 'Should have content');
261
- });
262
-
263
- // Test 9: get_quick_start tool
264
- await test('get_quick_start returns quick start guide', async () => {
265
- const response = await sendRequest({
266
- jsonrpc: '2.0',
267
- id: 1,
268
- method: 'tools/call',
269
- params: {
270
- name: 'get_quick_start',
271
- arguments: { sdk_id: 'dbr-mobile', platform: 'android' }
272
- }
273
- });
274
-
275
- assert(response.result, 'Should have result');
276
-
277
- const text = response.result.content[0].text;
278
- assert(text.includes('Quick Start') || text.includes('Android'), 'Should include quick start info');
279
- });
280
-
281
- // Test 10: get_gradle_config tool
282
- await test('get_gradle_config returns Gradle configuration', async () => {
283
- const response = await sendRequest({
284
- jsonrpc: '2.0',
285
- id: 1,
286
- method: 'tools/call',
287
- params: {
288
- name: 'get_gradle_config',
289
- arguments: {}
290
- }
291
- });
292
-
293
- assert(response.result, 'Should have result');
294
-
295
- const text = response.result.content[0].text;
296
- assert(text.includes('gradle') || text.includes('Gradle') || text.includes('implementation'),
297
- 'Should include Gradle config');
298
- });
299
-
300
- // Test 11: get_api_usage tool
301
- await test('get_api_usage returns API usage info', async () => {
302
- const response = await sendRequest({
303
- jsonrpc: '2.0',
304
- id: 1,
305
- method: 'tools/call',
306
- params: {
307
- name: 'get_api_usage',
308
- arguments: { sdk_id: 'dbr-mobile', api_name: 'decode' }
309
- }
310
- });
311
-
312
- assert(response.result, 'Should have result');
313
- assert(response.result.content, 'Should have content');
314
- });
315
-
316
- // Test 12: search_samples tool
317
- await test('search_samples finds samples by keyword', async () => {
318
- const response = await sendRequest({
319
- jsonrpc: '2.0',
320
- id: 1,
321
- method: 'tools/call',
322
- params: {
323
- name: 'search_samples',
324
- arguments: { query: 'barcode' }
325
- }
326
- });
327
-
328
- assert(response.result, 'Should have result');
329
- assert(response.result.content, 'Should have content');
330
- });
331
-
332
- // Test 13: generate_project tool
333
- await test('generate_project returns project structure', async () => {
334
- const response = await sendRequest({
335
- jsonrpc: '2.0',
336
- id: 1,
337
- method: 'tools/call',
338
- params: {
339
- name: 'generate_project',
340
- arguments: { platform: 'android', sample_name: 'ScanSingleBarcode' }
341
- }
342
- });
343
-
344
- assert(response.result, 'Should have result');
345
- assert(response.result.content, 'Should have content');
346
- const text = response.result.content[0].text;
347
- assert(text.includes('# Project Generation:'), 'Should include project generation header');
348
- assert(text.includes('AndroidManifest.xml') || text.includes('build.gradle'), 'Should include project files');
349
- });
350
-
351
- // Test 14: list_web_samples tool
352
- await test('list_web_samples returns web barcode samples', async () => {
353
- const response = await sendRequest({
354
- jsonrpc: '2.0',
355
- id: 1,
356
- method: 'tools/call',
357
- params: {
358
- name: 'list_web_samples',
359
- arguments: {}
360
- }
361
- });
362
-
363
- assert(response.result, 'Should have result');
364
- assert(response.result.content, 'Should have content');
365
- const text = response.result.content[0].text;
366
- assert(text.includes('Web Barcode Reader Samples'), 'Should include web samples header');
367
- });
368
-
369
- // Test 15: get_web_sample tool
370
- await test('get_web_sample returns web barcode sample code', async () => {
371
- const response = await sendRequest({
372
- jsonrpc: '2.0',
373
- id: 1,
374
- method: 'tools/call',
375
- params: {
376
- name: 'get_web_sample',
377
- arguments: { sample_name: 'hello-world' }
378
- }
379
- });
380
-
381
- assert(response.result, 'Should have result');
382
- assert(response.result.content, 'Should have content');
383
- const text = response.result.content[0].text;
384
- assert(text.includes('Web Barcode Reader') || text.includes('html') || text.includes('not found'), 'Should return sample or indicate not found');
385
- });
386
-
387
- // Test 16: search_dwt_docs tool
388
- await test('search_dwt_docs finds documentation articles', async () => {
389
- const response = await sendRequest({
390
- jsonrpc: '2.0',
391
- id: 1,
392
- method: 'tools/call',
393
- params: {
394
- name: 'search_dwt_docs',
395
- arguments: { query: 'PDF' }
396
- }
397
- });
398
-
399
- assert(response.result, 'Should have result');
400
- assert(response.result.content, 'Should have content');
401
- const text = response.result.content[0].text;
402
- assert(text.includes('DWT Documentation Search'), 'Should include search header');
403
- assert(text.includes('PDF') || text.includes('pdf'), 'Should find PDF-related articles');
404
- });
405
-
406
- // Test 17: get_dwt_api_doc tool
407
- await test('get_dwt_api_doc returns documentation article', async () => {
408
- const response = await sendRequest({
409
- jsonrpc: '2.0',
410
- id: 1,
411
- method: 'tools/call',
412
- params: {
413
- name: 'get_dwt_api_doc',
414
- arguments: { title: 'OCR' }
415
- }
416
- });
417
-
418
- assert(response.result, 'Should have result');
419
- assert(response.result.content, 'Should have content');
420
- const text = response.result.content[0].text;
421
- // Should return either the article or suggestions
422
- assert(text.includes('OCR') || text.includes('not found'), 'Should handle OCR query');
423
- });
424
-
425
- // Test 18: resources/list returns registered resources
426
- await test('resources/list returns registered resources', async () => {
427
- const response = await sendRequest({
428
- jsonrpc: '2.0',
429
- id: 1,
430
- method: 'resources/list'
431
- });
432
-
433
- assert(response.result, 'Should have result');
434
- assert(response.result.resources, 'Should have resources array');
435
- assert(response.result.resources.length > 0, 'Should have at least one resource');
436
-
437
- // Check for expected resource types
438
- const uris = response.result.resources.map(r => r.uri);
439
- assert(uris.some(u => u.includes('sdk-info')), 'Should have sdk-info resources');
440
- assert(uris.some(u => u.includes('docs/dwt')), 'Should have DWT doc resources');
441
- });
442
-
443
- // Test 19: Invalid tool call returns error
444
- await test('Invalid tool call returns proper error', async () => {
445
- const response = await sendRequest({
446
- jsonrpc: '2.0',
447
- id: 1,
448
- method: 'tools/call',
449
- params: {
450
- name: 'nonexistent_tool',
451
- arguments: {}
452
- }
453
- });
454
-
455
- assert(response.error || (response.result && response.result.isError),
456
- 'Should return error for invalid tool');
457
- });
458
-
459
- // Test 20: Tool with invalid arguments returns error
460
- await test('Tool with missing required arguments returns error', async () => {
461
- const response = await sendRequest({
462
- jsonrpc: '2.0',
463
- id: 1,
464
- method: 'tools/call',
465
- params: {
466
- name: 'get_license_info',
467
- arguments: {} // Missing required platform
468
- }
469
- });
470
-
471
- assert(response.result && response.result.isError,
472
- 'Should return error for missing required argument');
473
- });
474
-
475
- // ============================================
476
- // Test Summary
477
- // ============================================
478
-
479
- console.log('\n' + '='.repeat(50));
480
- console.log('\n📊 Test Summary\n');
481
- console.log(` Total: ${passed + failed}`);
482
- console.log(` Passed: ${passed} ✅`);
483
- console.log(` Failed: ${failed} ❌`);
484
- console.log(` Rate: ${((passed / (passed + failed)) * 100).toFixed(1)}%`);
485
-
486
- if (failed > 0) {
487
- console.log('\n❌ Failed Tests:');
488
- results.filter(r => r.status.includes('FAILED')).forEach(r => {
489
- console.log(` - ${r.name}: ${r.error}`);
490
- });
491
- }
492
-
493
- console.log('\n' + '='.repeat(50));
494
-
495
- // Exit with appropriate code
496
- process.exit(failed > 0 ? 1 : 0);