cli-mcp-mapper 1.0.3 → 1.0.4
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/lib.js +4 -1
- package/lib.test.js +23 -4
- package/package.json +1 -1
package/lib.js
CHANGED
|
@@ -86,7 +86,10 @@ export function executeCommand(cmdArray) {
|
|
|
86
86
|
|
|
87
87
|
proc.on("close", (code) => {
|
|
88
88
|
if (code !== 0) {
|
|
89
|
-
|
|
89
|
+
// Resolve with full output instead of rejecting
|
|
90
|
+
// This allows MCP SDK clients to see the actual error details
|
|
91
|
+
const output = `Command exited with code ${code}\n${stdout}${stderr}`;
|
|
92
|
+
resolve(output);
|
|
90
93
|
} else {
|
|
91
94
|
resolve(stdout || stderr);
|
|
92
95
|
}
|
package/lib.test.js
CHANGED
|
@@ -560,10 +560,12 @@ describe('Command Injection Security Tests', () => {
|
|
|
560
560
|
});
|
|
561
561
|
|
|
562
562
|
describe('Error handling', () => {
|
|
563
|
-
it('should
|
|
563
|
+
it('should resolve with exit code info when command fails', async () => {
|
|
564
564
|
const cmd = ['false']; // 'false' command always returns exit code 1
|
|
565
565
|
|
|
566
|
-
await
|
|
566
|
+
const result = await executeCommand(cmd);
|
|
567
|
+
expect(result).toContain('Command exited with code');
|
|
568
|
+
expect(result).toContain('1');
|
|
567
569
|
});
|
|
568
570
|
|
|
569
571
|
it('should reject when command does not exist', async () => {
|
|
@@ -572,11 +574,28 @@ describe('Error handling', () => {
|
|
|
572
574
|
await expect(executeCommand(cmd)).rejects.toThrow('Failed to execute command');
|
|
573
575
|
});
|
|
574
576
|
|
|
575
|
-
it('should
|
|
577
|
+
it('should resolve with stderr content on failure', async () => {
|
|
576
578
|
// Use a command that writes to stderr
|
|
577
579
|
const cmd = ['ls', '/this/path/does/not/exist/12345'];
|
|
578
580
|
|
|
579
|
-
await
|
|
581
|
+
const result = await executeCommand(cmd);
|
|
582
|
+
expect(result).toContain('Command exited with code');
|
|
583
|
+
expect(result.toLowerCase()).toMatch(/no such file or directory|cannot access/);
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
it('should resolve with full output including stderr when command fails with non-zero exit code', async () => {
|
|
587
|
+
// Use a command that will fail and output to stderr
|
|
588
|
+
// This command tries to list a non-existent directory
|
|
589
|
+
const cmd = ['ls', '/this/path/does/not/exist/for/testing/12345'];
|
|
590
|
+
|
|
591
|
+
// The promise should resolve (not reject) with the full output
|
|
592
|
+
const result = await executeCommand(cmd);
|
|
593
|
+
|
|
594
|
+
// Result should contain exit code information
|
|
595
|
+
expect(result).toContain('Command exited with code');
|
|
596
|
+
|
|
597
|
+
// Result should contain stderr output with error message
|
|
598
|
+
expect(result.toLowerCase()).toMatch(/no such file or directory|cannot access/);
|
|
580
599
|
});
|
|
581
600
|
});
|
|
582
601
|
|