11#!/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'
55
66// Simple JSON-RPC client for testing MCP server
77class 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 ( )
1212
13- constructor ( command : string , args : string [ ] = [ ] , env : any = { } ) {
13+ constructor ( command : string , args : string [ ] = [ ] , env : any = { } ) {
1414 this . process = spawn ( command , args , {
1515 stdio : [ 'pipe' , 'pipe' , 'pipe' ] ,
1616 env : { ...process . env , ...env }
17- } ) ;
17+ } )
1818
1919 this . rl = readline . createInterface ( {
2020 input : this . process . stdout ,
2121 crlfDelay : Infinity
22- } ) ;
22+ } )
2323
2424 this . rl . on ( 'line' , ( line ) => {
2525 try {
26- const response = JSON . parse ( line ) ;
26+ const response = JSON . parse ( line )
2727 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 )
3030
3131 if ( response . error ) {
32- reject ( response . error ) ;
32+ reject ( response . error )
3333 } else {
34- resolve ( response . result ) ;
34+ resolve ( response . result )
3535 }
3636 } else if ( response . method ) {
37- console . log ( 'Notification:' , response ) ;
37+ console . log ( 'Notification:' , response )
3838 }
3939 } catch ( e ) {
40- console . error ( 'Failed to parse response:' , line ) ;
40+ console . error ( 'Failed to parse response:' , line )
4141 }
42- } ) ;
42+ } )
4343
4444 this . process . stderr . on ( 'data' , ( data : Buffer ) => {
45- console . error ( 'Server stderr:' , data . toString ( ) ) ;
46- } ) ;
45+ console . error ( 'Server stderr:' , data . toString ( ) )
46+ } )
4747 }
4848
49- async sendRequest ( method : string , params : any = { } ) {
50- const id = this . requestId ++ ;
49+ async sendRequest ( method : string , params : any = { } ) {
50+ const id = this . requestId ++
5151 const request = {
5252 jsonrpc : '2.0' ,
5353 id,
5454 method,
5555 params
56- } ;
56+ }
5757
5858 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+ } )
6262 }
6363
64- close ( ) {
65- this . rl . close ( ) ;
66- this . process . kill ( ) ;
64+ close ( ) {
65+ this . rl . close ( )
66+ this . process . kill ( )
6767 }
6868}
6969
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' ]
7472 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 )
7775 }
7876
79- console . log ( 'Starting MCP server debug client...' ) ;
77+ console . log ( 'Starting MCP server debug client...' )
8078
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 } ` )
8381
8482 const client = new SimpleJSONRPCClient ( 'node' , [ '--experimental-strip-types' , serverPath ] , {
8583 SOCKET_API_KEY : apiKey
86- } ) ;
84+ } )
8785
8886 try {
8987 // Initialize the connection
90- console . log ( '\n1. Initializing connection...' ) ;
88+ console . log ( '\n1. Initializing connection...' )
9189 const initResult = await client . sendRequest ( 'initialize' , {
9290 protocolVersion : '0.1.0' ,
9391 capabilities : { } ,
9492 clientInfo : {
9593 name : 'debug-client' ,
9694 version : '1.0.0'
9795 }
98- } ) ;
99- console . log ( 'Initialize response:' , JSON . stringify ( initResult , null , 2 ) ) ;
96+ } )
97+ console . log ( 'Initialize response:' , JSON . stringify ( initResult , null , 2 ) )
10098
10199 // 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 ) )
105103
106104 // Call the depscore tool
107- console . log ( '\n3. Calling depscore tool...' ) ;
105+ console . log ( '\n3. Calling depscore tool...' )
108106 const depscoreResult = await client . sendRequest ( 'tools/call' , {
109107 name : 'depscore' ,
110108 arguments : {
@@ -116,11 +114,11 @@ async function main() {
116114 { depname : 'unknown-package' , ecosystem : 'npm' , version : 'unknown' }
117115 ]
118116 }
119- } ) ;
120- console . log ( 'Depscore result:' , JSON . stringify ( depscoreResult , null , 2 ) ) ;
117+ } )
118+ console . log ( 'Depscore result:' , JSON . stringify ( depscoreResult , null , 2 ) )
121119
122120 // 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)...' )
124122 const minimalResult = await client . sendRequest ( 'tools/call' , {
125123 name : 'depscore' ,
126124 arguments : {
@@ -129,28 +127,28 @@ async function main() {
129127 { depname : 'typescript' }
130128 ]
131129 }
132- } ) ;
133- console . log ( 'Minimal input result:' , JSON . stringify ( minimalResult , null , 2 ) ) ;
130+ } )
131+ console . log ( 'Minimal input result:' , JSON . stringify ( minimalResult , null , 2 ) )
134132
135133 // Test error handling
136- console . log ( '\n5. Testing error handling (empty packages)...' ) ;
134+ console . log ( '\n5. Testing error handling (empty packages)...' )
137135 try {
138136 await client . sendRequest ( 'tools/call' , {
139137 name : 'depscore' ,
140138 arguments : {
141139 packages : [ ]
142140 }
143- } ) ;
141+ } )
144142 } catch ( error ) {
145- console . log ( 'Expected error:' , error ) ;
143+ console . log ( 'Expected error:' , error )
146144 }
147145
148- console . log ( '\nDebug session complete!' ) ;
146+ console . log ( '\nDebug session complete!' )
149147 } catch ( error ) {
150- console . error ( 'Client error:' , error ) ;
148+ console . error ( 'Client error:' , error )
151149 } finally {
152- client . close ( ) ;
150+ client . close ( )
153151 }
154152}
155153
156- main ( ) . catch ( console . error ) ;
154+ main ( ) . catch ( console . error )
0 commit comments