@@ -4,7 +4,7 @@ import MCPConnection from "./MCPConnection";
4
4
5
5
describe ( "MCPConnection" , ( ) => {
6
6
beforeEach ( ( ) => {
7
- jest . clearAllMocks ( ) ;
7
+ jest . restoreAllMocks ( ) ;
8
8
} ) ;
9
9
10
10
describe ( "constructor" , ( ) => {
@@ -173,11 +173,11 @@ describe("MCPConnection", () => {
173
173
} ) ;
174
174
175
175
it ( "should handle custom connection timeout" , async ( ) => {
176
- const conn = new MCPConnection ( { ...options , timeout : 11 } ) ;
176
+ const conn = new MCPConnection ( { ...options , timeout : 1500 } ) ;
177
177
const mockConnect = jest
178
178
. spyOn ( Client . prototype , "connect" )
179
179
. mockImplementation (
180
- ( ) => new Promise ( ( resolve ) => setTimeout ( resolve , 10 ) ) ,
180
+ ( ) => new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ,
181
181
) ;
182
182
183
183
const abortController = new AbortController ( ) ;
@@ -229,6 +229,38 @@ describe("MCPConnection", () => {
229
229
expect ( conn . errors [ 0 ] ) . toContain ( 'command "test-cmd" not found' ) ;
230
230
expect ( mockConnect ) . toHaveBeenCalled ( ) ;
231
231
} ) ;
232
+
233
+ it . skip ( "should include stderr output in error message when stdio command fails" , async ( ) => {
234
+ // Clear any existing mocks to ensure we get real behavior
235
+ jest . restoreAllMocks ( ) ;
236
+
237
+ // Use a command that will definitely fail and produce stderr output
238
+ const failingOptions = {
239
+ name : "failing-mcp" ,
240
+ id : "failing-id" ,
241
+ transport : {
242
+ type : "stdio" as const ,
243
+ command : "node" ,
244
+ args : [
245
+ "-e" ,
246
+ "console.error('Custom error message from stderr'); process.exit(1);" ,
247
+ ] ,
248
+ } ,
249
+ timeout : 5000 , // Give enough time for the command to run and fail
250
+ } ;
251
+
252
+ const conn = new MCPConnection ( failingOptions ) ;
253
+ const abortController = new AbortController ( ) ;
254
+
255
+ await conn . connectClient ( false , abortController . signal ) ;
256
+
257
+ expect ( conn . status ) . toBe ( "error" ) ;
258
+ expect ( conn . errors ) . toHaveLength ( 1 ) ;
259
+ expect ( conn . errors [ 0 ] ) . toContain ( "Failed to connect" ) ;
260
+ expect ( conn . errors [ 0 ] ) . toContain ( "Process output:" ) ;
261
+ expect ( conn . errors [ 0 ] ) . toContain ( "STDERR:" ) ;
262
+ expect ( conn . errors [ 0 ] ) . toContain ( "Custom error message from stderr" ) ;
263
+ } ) ;
232
264
} ) ;
233
265
234
266
describe . skip ( "actually connect to Filesystem MCP" , ( ) => {
0 commit comments