1
1
#!/usr/bin/env node --experimental-strip-types
2
- import { spawn } from 'child_process' ;
3
- import readline from 'readline' ;
4
- import { join } from 'path' ;
2
+ import { spawn } from 'child_process'
3
+ import readline from 'readline'
4
+ import { join } from 'path'
5
5
6
6
// Simple JSON-RPC client for testing MCP server
7
7
class SimpleJSONRPCClient {
8
- private process : any ;
9
- private rl : readline . Interface ;
10
- private requestId = 1 ;
11
- private pendingRequests = new Map ( ) ;
8
+ private process : any
9
+ private rl : readline . Interface
10
+ private requestId = 1
11
+ private pendingRequests = new Map ( )
12
12
13
- constructor ( command : string , args : string [ ] = [ ] , env : any = { } ) {
13
+ constructor ( command : string , args : string [ ] = [ ] , env : any = { } ) {
14
14
this . process = spawn ( command , args , {
15
15
stdio : [ 'pipe' , 'pipe' , 'pipe' ] ,
16
16
env : { ...process . env , ...env }
17
- } ) ;
17
+ } )
18
18
19
19
this . rl = readline . createInterface ( {
20
20
input : this . process . stdout ,
21
21
crlfDelay : Infinity
22
- } ) ;
22
+ } )
23
23
24
24
this . rl . on ( 'line' , ( line ) => {
25
25
try {
26
- const response = JSON . parse ( line ) ;
26
+ const response = JSON . parse ( line )
27
27
if ( response . id && this . pendingRequests . has ( response . id ) ) {
28
- const { resolve, reject } = this . pendingRequests . get ( response . id ) ;
29
- this . pendingRequests . delete ( response . id ) ;
28
+ const { resolve, reject } = this . pendingRequests . get ( response . id )
29
+ this . pendingRequests . delete ( response . id )
30
30
31
31
if ( response . error ) {
32
- reject ( response . error ) ;
32
+ reject ( response . error )
33
33
} else {
34
- resolve ( response . result ) ;
34
+ resolve ( response . result )
35
35
}
36
36
} else if ( response . method ) {
37
- console . log ( 'Notification:' , response ) ;
37
+ console . log ( 'Notification:' , response )
38
38
}
39
39
} catch ( e ) {
40
- console . error ( 'Failed to parse response:' , line ) ;
40
+ console . error ( 'Failed to parse response:' , line )
41
41
}
42
- } ) ;
42
+ } )
43
43
44
44
this . process . stderr . on ( 'data' , ( data : Buffer ) => {
45
- console . error ( 'Server stderr:' , data . toString ( ) ) ;
46
- } ) ;
45
+ console . error ( 'Server stderr:' , data . toString ( ) )
46
+ } )
47
47
}
48
48
49
- async sendRequest ( method : string , params : any = { } ) {
50
- const id = this . requestId ++ ;
49
+ async sendRequest ( method : string , params : any = { } ) {
50
+ const id = this . requestId ++
51
51
const request = {
52
52
jsonrpc : '2.0' ,
53
53
id,
54
54
method,
55
55
params
56
- } ;
56
+ }
57
57
58
58
return new Promise ( ( resolve , reject ) => {
59
- this . pendingRequests . set ( id , { resolve, reject } ) ;
60
- this . process . stdin . write ( JSON . stringify ( request ) + '\n' ) ;
61
- } ) ;
59
+ this . pendingRequests . set ( id , { resolve, reject } )
60
+ this . process . stdin . write ( JSON . stringify ( request ) + '\n' )
61
+ } )
62
62
}
63
63
64
- close ( ) {
65
- this . rl . close ( ) ;
66
- this . process . kill ( ) ;
64
+ close ( ) {
65
+ this . rl . close ( )
66
+ this . process . kill ( )
67
67
}
68
68
}
69
69
70
-
71
-
72
- async function main ( ) {
73
- const apiKey = process . env [ 'SOCKET_API_KEY' ] ;
70
+ async function main ( ) {
71
+ const apiKey = process . env [ 'SOCKET_API_KEY' ]
74
72
if ( ! apiKey ) {
75
- console . error ( 'Error: SOCKET_API_KEY environment variable is required' ) ;
76
- process . exit ( 1 ) ;
73
+ console . error ( 'Error: SOCKET_API_KEY environment variable is required' )
74
+ process . exit ( 1 )
77
75
}
78
76
79
- console . log ( 'Starting MCP server debug client...' ) ;
77
+ console . log ( 'Starting MCP server debug client...' )
80
78
81
- const serverPath = join ( import . meta. dirname , '..' , 'index.ts' ) ;
82
- console . log ( `Using server script: ${ serverPath } ` ) ;
79
+ const serverPath = join ( import . meta. dirname , '..' , 'index.ts' )
80
+ console . log ( `Using server script: ${ serverPath } ` )
83
81
84
82
const client = new SimpleJSONRPCClient ( 'node' , [ '--experimental-strip-types' , serverPath ] , {
85
83
SOCKET_API_KEY : apiKey
86
- } ) ;
84
+ } )
87
85
88
86
try {
89
87
// Initialize the connection
90
- console . log ( '\n1. Initializing connection...' ) ;
88
+ console . log ( '\n1. Initializing connection...' )
91
89
const initResult = await client . sendRequest ( 'initialize' , {
92
90
protocolVersion : '0.1.0' ,
93
91
capabilities : { } ,
94
92
clientInfo : {
95
93
name : 'debug-client' ,
96
94
version : '1.0.0'
97
95
}
98
- } ) ;
99
- console . log ( 'Initialize response:' , JSON . stringify ( initResult , null , 2 ) ) ;
96
+ } )
97
+ console . log ( 'Initialize response:' , JSON . stringify ( initResult , null , 2 ) )
100
98
101
99
// List available tools
102
- console . log ( '\n2. Listing available tools...' ) ;
103
- const toolsResult = await client . sendRequest ( 'tools/list' , { } ) ;
104
- console . log ( 'Available tools:' , JSON . stringify ( toolsResult , null , 2 ) ) ;
100
+ console . log ( '\n2. Listing available tools...' )
101
+ const toolsResult = await client . sendRequest ( 'tools/list' , { } )
102
+ console . log ( 'Available tools:' , JSON . stringify ( toolsResult , null , 2 ) )
105
103
106
104
// Call the depscore tool
107
- console . log ( '\n3. Calling depscore tool...' ) ;
105
+ console . log ( '\n3. Calling depscore tool...' )
108
106
const depscoreResult = await client . sendRequest ( 'tools/call' , {
109
107
name : 'depscore' ,
110
108
arguments : {
@@ -116,11 +114,11 @@ async function main() {
116
114
{ depname : 'unknown-package' , ecosystem : 'npm' , version : 'unknown' }
117
115
]
118
116
}
119
- } ) ;
120
- console . log ( 'Depscore result:' , JSON . stringify ( depscoreResult , null , 2 ) ) ;
117
+ } )
118
+ console . log ( 'Depscore result:' , JSON . stringify ( depscoreResult , null , 2 ) )
121
119
122
120
// Test with minimal input
123
- console . log ( '\n4. Testing with minimal input (default to npm)...' ) ;
121
+ console . log ( '\n4. Testing with minimal input (default to npm)...' )
124
122
const minimalResult = await client . sendRequest ( 'tools/call' , {
125
123
name : 'depscore' ,
126
124
arguments : {
@@ -129,28 +127,28 @@ async function main() {
129
127
{ depname : 'typescript' }
130
128
]
131
129
}
132
- } ) ;
133
- console . log ( 'Minimal input result:' , JSON . stringify ( minimalResult , null , 2 ) ) ;
130
+ } )
131
+ console . log ( 'Minimal input result:' , JSON . stringify ( minimalResult , null , 2 ) )
134
132
135
133
// Test error handling
136
- console . log ( '\n5. Testing error handling (empty packages)...' ) ;
134
+ console . log ( '\n5. Testing error handling (empty packages)...' )
137
135
try {
138
136
await client . sendRequest ( 'tools/call' , {
139
137
name : 'depscore' ,
140
138
arguments : {
141
139
packages : [ ]
142
140
}
143
- } ) ;
141
+ } )
144
142
} catch ( error ) {
145
- console . log ( 'Expected error:' , error ) ;
143
+ console . log ( 'Expected error:' , error )
146
144
}
147
145
148
- console . log ( '\nDebug session complete!' ) ;
146
+ console . log ( '\nDebug session complete!' )
149
147
} catch ( error ) {
150
- console . error ( 'Client error:' , error ) ;
148
+ console . error ( 'Client error:' , error )
151
149
} finally {
152
- client . close ( ) ;
150
+ client . close ( )
153
151
}
154
152
}
155
153
156
- main ( ) . catch ( console . error ) ;
154
+ main ( ) . catch ( console . error )
0 commit comments