@socketsecurity/mcp 0.0.17 → 0.0.18
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/CHANGELOG.md +19 -0
- package/README.md +221 -184
- package/dist/index.cjs +58128 -0
- package/dist/index.d.ts +4 -0
- package/hooks/socket-gate/README.md +117 -0
- package/hooks/socket-gate/index.mts +289 -0
- package/hooks/socket-gate/socket-gate.cjs +1047 -0
- package/package.json +90 -65
- package/index.d.ts +0 -3
- package/index.d.ts.map +0 -1
- package/index.js +0 -460
- package/mock-client/debug-client.d.ts +0 -3
- package/mock-client/debug-client.d.ts.map +0 -1
- package/mock-client/debug-client.js +0 -134
- package/mock-client/http-client.d.ts +0 -3
- package/mock-client/http-client.d.ts.map +0 -1
- package/mock-client/http-client.js +0 -123
- package/mock-client/stdio-client.d.ts +0 -3
- package/mock-client/stdio-client.d.ts.map +0 -1
- package/mock-client/stdio-client.js +0 -52
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node --experimental-strip-types
|
|
2
|
-
import { spawn } from 'child_process';
|
|
3
|
-
import readline from 'readline';
|
|
4
|
-
import { join } from 'path';
|
|
5
|
-
class SimpleJSONRPCClient {
|
|
6
|
-
process;
|
|
7
|
-
rl;
|
|
8
|
-
requestId = 1;
|
|
9
|
-
pendingRequests = new Map();
|
|
10
|
-
constructor(command, args = [], env = {}) {
|
|
11
|
-
this.process = spawn(command, args, {
|
|
12
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
13
|
-
env: { ...process.env, ...env }
|
|
14
|
-
});
|
|
15
|
-
this.rl = readline.createInterface({
|
|
16
|
-
input: this.process.stdout,
|
|
17
|
-
crlfDelay: Infinity
|
|
18
|
-
});
|
|
19
|
-
this.rl.on('line', (line) => {
|
|
20
|
-
try {
|
|
21
|
-
const response = JSON.parse(line);
|
|
22
|
-
if (response.id && this.pendingRequests.has(response.id)) {
|
|
23
|
-
const { resolve, reject } = this.pendingRequests.get(response.id);
|
|
24
|
-
this.pendingRequests.delete(response.id);
|
|
25
|
-
if (response.error) {
|
|
26
|
-
reject(response.error);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
resolve(response.result);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
else if (response.method) {
|
|
33
|
-
console.log('Notification:', response);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
console.error('Failed to parse response:', line);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
this.process.stderr.on('data', (data) => {
|
|
41
|
-
console.error('Server stderr:', data.toString());
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
async sendRequest(method, params = {}) {
|
|
45
|
-
const id = this.requestId++;
|
|
46
|
-
const request = {
|
|
47
|
-
jsonrpc: '2.0',
|
|
48
|
-
id,
|
|
49
|
-
method,
|
|
50
|
-
params
|
|
51
|
-
};
|
|
52
|
-
return new Promise((resolve, reject) => {
|
|
53
|
-
this.pendingRequests.set(id, { resolve, reject });
|
|
54
|
-
this.process.stdin.write(JSON.stringify(request) + '\n');
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
close() {
|
|
58
|
-
this.rl.close();
|
|
59
|
-
this.process.kill();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
async function main() {
|
|
63
|
-
const apiKey = process.env['SOCKET_API_KEY'];
|
|
64
|
-
if (!apiKey) {
|
|
65
|
-
console.error('Error: SOCKET_API_KEY environment variable is required');
|
|
66
|
-
process.exit(1);
|
|
67
|
-
}
|
|
68
|
-
console.log('Starting MCP server debug client...');
|
|
69
|
-
const serverPath = join(import.meta.dirname, '..', 'index.ts');
|
|
70
|
-
console.log(`Using server script: ${serverPath}`);
|
|
71
|
-
const client = new SimpleJSONRPCClient('node', ['--experimental-strip-types', serverPath], {
|
|
72
|
-
SOCKET_API_KEY: apiKey
|
|
73
|
-
});
|
|
74
|
-
try {
|
|
75
|
-
console.log('\n1. Initializing connection...');
|
|
76
|
-
const initResult = await client.sendRequest('initialize', {
|
|
77
|
-
protocolVersion: '0.1.0',
|
|
78
|
-
capabilities: {},
|
|
79
|
-
clientInfo: {
|
|
80
|
-
name: 'debug-client',
|
|
81
|
-
version: '1.0.0'
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
console.log('Initialize response:', JSON.stringify(initResult, null, 2));
|
|
85
|
-
console.log('\n2. Listing available tools...');
|
|
86
|
-
const toolsResult = await client.sendRequest('tools/list', {});
|
|
87
|
-
console.log('Available tools:', JSON.stringify(toolsResult, null, 2));
|
|
88
|
-
console.log('\n3. Calling depscore tool...');
|
|
89
|
-
const depscoreResult = await client.sendRequest('tools/call', {
|
|
90
|
-
name: 'depscore',
|
|
91
|
-
arguments: {
|
|
92
|
-
packages: [
|
|
93
|
-
{ depname: 'express', ecosystem: 'npm', version: '5.0.1' },
|
|
94
|
-
{ depname: 'lodash', ecosystem: 'npm', version: '4.17.21' },
|
|
95
|
-
{ depname: 'react', ecosystem: 'npm', version: '18.2.0' },
|
|
96
|
-
{ depname: 'flask', ecosystem: 'pypi', version: '2.3.2' },
|
|
97
|
-
{ depname: 'unknown-package', ecosystem: 'npm', version: 'unknown' }
|
|
98
|
-
]
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
console.log('Depscore result:', JSON.stringify(depscoreResult, null, 2));
|
|
102
|
-
console.log('\n4. Testing with minimal input (default to npm)...');
|
|
103
|
-
const minimalResult = await client.sendRequest('tools/call', {
|
|
104
|
-
name: 'depscore',
|
|
105
|
-
arguments: {
|
|
106
|
-
packages: [
|
|
107
|
-
{ depname: 'axios' },
|
|
108
|
-
{ depname: 'typescript' }
|
|
109
|
-
]
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
console.log('Minimal input result:', JSON.stringify(minimalResult, null, 2));
|
|
113
|
-
console.log('\n5. Testing error handling (empty packages)...');
|
|
114
|
-
try {
|
|
115
|
-
await client.sendRequest('tools/call', {
|
|
116
|
-
name: 'depscore',
|
|
117
|
-
arguments: {
|
|
118
|
-
packages: []
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
catch (error) {
|
|
123
|
-
console.log('Expected error:', error);
|
|
124
|
-
}
|
|
125
|
-
console.log('\nDebug session complete!');
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
console.error('Client error:', error);
|
|
129
|
-
}
|
|
130
|
-
finally {
|
|
131
|
-
client.close();
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
main().catch(console.error);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["http-client.ts"],"names":[],"mappings":""}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node --experimental-strip-types
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
async function parseResponse(response) {
|
|
4
|
-
const contentType = response.headers.get('content-type');
|
|
5
|
-
const text = await response.text();
|
|
6
|
-
if (contentType?.includes('text/event-stream')) {
|
|
7
|
-
const dataMatch = text.match(/data: (.+)/);
|
|
8
|
-
if (dataMatch) {
|
|
9
|
-
return JSON.parse(dataMatch[1]);
|
|
10
|
-
}
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
return JSON.parse(text);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
async function testHTTPMode() {
|
|
18
|
-
const baseUrl = (process.env['MCP_URL'] || 'http://localhost:3000').replace(/\/$/, '');
|
|
19
|
-
console.log('Testing Socket MCP in HTTP mode...');
|
|
20
|
-
console.log(`Server URL: ${baseUrl}`);
|
|
21
|
-
try {
|
|
22
|
-
console.log('\n1. Initializing connection...');
|
|
23
|
-
const initRequest = {
|
|
24
|
-
jsonrpc: '2.0',
|
|
25
|
-
id: 1,
|
|
26
|
-
method: 'initialize',
|
|
27
|
-
params: {
|
|
28
|
-
protocolVersion: '0.1.0',
|
|
29
|
-
capabilities: {},
|
|
30
|
-
clientInfo: {
|
|
31
|
-
name: 'http-debug-client',
|
|
32
|
-
version: '1.0.0'
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const initResponse = await fetch(`${baseUrl}/`, {
|
|
37
|
-
method: 'POST',
|
|
38
|
-
headers: {
|
|
39
|
-
'Content-Type': 'application/json',
|
|
40
|
-
Accept: 'application/json, text/event-stream',
|
|
41
|
-
'User-Agent': 'socket-mcp-debug-client/1.0.0'
|
|
42
|
-
},
|
|
43
|
-
body: JSON.stringify(initRequest)
|
|
44
|
-
});
|
|
45
|
-
const initResult = await parseResponse(initResponse);
|
|
46
|
-
console.log('Initialize response:', JSON.stringify(initResult, null, 2));
|
|
47
|
-
console.log('Initialized (stateless)');
|
|
48
|
-
console.log('\n2. Listing available tools...');
|
|
49
|
-
const toolsRequest = {
|
|
50
|
-
jsonrpc: '2.0',
|
|
51
|
-
id: 2,
|
|
52
|
-
method: 'tools/list',
|
|
53
|
-
params: {}
|
|
54
|
-
};
|
|
55
|
-
const toolsResponse = await fetch(`${baseUrl}/`, {
|
|
56
|
-
method: 'POST',
|
|
57
|
-
headers: {
|
|
58
|
-
'Content-Type': 'application/json',
|
|
59
|
-
Accept: 'application/json, text/event-stream'
|
|
60
|
-
},
|
|
61
|
-
body: JSON.stringify(toolsRequest)
|
|
62
|
-
});
|
|
63
|
-
const toolsResult = await parseResponse(toolsResponse);
|
|
64
|
-
console.log('Available tools:', JSON.stringify(toolsResult, null, 2));
|
|
65
|
-
if (!toolsResult ||
|
|
66
|
-
!toolsResult.result ||
|
|
67
|
-
!Array.isArray(toolsResult.result.tools) ||
|
|
68
|
-
!toolsResult.result.tools.some((tool) => tool.name === 'depscore')) {
|
|
69
|
-
throw new Error('depscore tool not found in available tools');
|
|
70
|
-
}
|
|
71
|
-
console.log('\n3. Calling depscore tool...');
|
|
72
|
-
const depscoreRequest = {
|
|
73
|
-
jsonrpc: '2.0',
|
|
74
|
-
id: 3,
|
|
75
|
-
method: 'tools/call',
|
|
76
|
-
params: {
|
|
77
|
-
name: 'depscore',
|
|
78
|
-
arguments: {
|
|
79
|
-
packages: [
|
|
80
|
-
{ depname: 'express', ecosystem: 'npm', version: '4.18.2' },
|
|
81
|
-
{ depname: 'fastapi', ecosystem: 'pypi', version: '0.100.0' },
|
|
82
|
-
{ depname: 'react', ecosystem: 'npm', version: '18.2.0' }
|
|
83
|
-
]
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
const depscoreResponse = await fetch(`${baseUrl}/`, {
|
|
88
|
-
method: 'POST',
|
|
89
|
-
headers: {
|
|
90
|
-
'Content-Type': 'application/json',
|
|
91
|
-
Accept: 'application/json, text/event-stream'
|
|
92
|
-
},
|
|
93
|
-
body: JSON.stringify(depscoreRequest)
|
|
94
|
-
});
|
|
95
|
-
const depscoreResult = await parseResponse(depscoreResponse);
|
|
96
|
-
console.log('Depscore result:', JSON.stringify(depscoreResult, null, 2));
|
|
97
|
-
console.log('\n4. HTTP mode test complete (no sessions)');
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
console.error('Error:', error);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (process.argv.includes('--help')) {
|
|
104
|
-
const serverScript = join(import.meta.dirname, '..', 'index.ts');
|
|
105
|
-
console.log(`
|
|
106
|
-
Socket MCP HTTP Client Debugger
|
|
107
|
-
|
|
108
|
-
Usage:
|
|
109
|
-
# Start the MCP server in HTTP mode first:
|
|
110
|
-
MCP_HTTP_MODE=true SOCKET_API_KEY=your-api-key node --experimental-strip-types ${serverScript}
|
|
111
|
-
|
|
112
|
-
# Then run this client:
|
|
113
|
-
node --experimental-strip-types ./mock-client/http-client.ts
|
|
114
|
-
|
|
115
|
-
Environment variables:
|
|
116
|
-
MCP_URL - Server URL (default: http://localhost:3000)
|
|
117
|
-
|
|
118
|
-
Example:
|
|
119
|
-
MCP_URL=http://localhost:8080 node --experimental-strip-types ./mock-client/http-client.ts
|
|
120
|
-
`);
|
|
121
|
-
process.exit(0);
|
|
122
|
-
}
|
|
123
|
-
testHTTPMode().catch(console.error);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stdio-client.d.ts","sourceRoot":"","sources":["stdio-client.ts"],"names":[],"mappings":""}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node --experimental-strip-types
|
|
2
|
-
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
3
|
-
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
4
|
-
import { join } from 'path';
|
|
5
|
-
async function main() {
|
|
6
|
-
const serverPath = join(import.meta.dirname, '..', 'index.ts');
|
|
7
|
-
console.log(`Using server script: ${serverPath}`);
|
|
8
|
-
const transport = new StdioClientTransport({
|
|
9
|
-
command: 'node',
|
|
10
|
-
args: ['--experimental-strip-types', serverPath],
|
|
11
|
-
env: {
|
|
12
|
-
...Object.fromEntries(Object.entries(process.env).filter(([, value]) => value !== undefined)),
|
|
13
|
-
SOCKET_API_KEY: process.env['SOCKET_API_KEY'] || ''
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
const client = new Client({
|
|
17
|
-
name: 'test-mcp-client',
|
|
18
|
-
version: '1.0.0'
|
|
19
|
-
}, {
|
|
20
|
-
capabilities: {}
|
|
21
|
-
});
|
|
22
|
-
try {
|
|
23
|
-
await client.connect(transport);
|
|
24
|
-
console.log('Connected to MCP server');
|
|
25
|
-
const tools = await client.listTools();
|
|
26
|
-
console.log('Available tools:', tools.tools.map(t => t.name));
|
|
27
|
-
const testPackages = [
|
|
28
|
-
{ depname: 'express', ecosystem: 'npm', version: '4.18.2' },
|
|
29
|
-
{ depname: 'lodash', ecosystem: 'npm', version: '4.17.21' },
|
|
30
|
-
{ depname: 'react', ecosystem: 'npm', version: '18.2.0' },
|
|
31
|
-
{ depname: 'requests', ecosystem: 'pypi', version: '2.31.0' },
|
|
32
|
-
{ depname: 'unknown-package', ecosystem: 'npm', version: 'unknown' }
|
|
33
|
-
];
|
|
34
|
-
console.log('\nTesting depscore with packages:', testPackages);
|
|
35
|
-
const result = await client.callTool({
|
|
36
|
-
name: 'depscore',
|
|
37
|
-
arguments: {
|
|
38
|
-
packages: testPackages
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
console.log('\nDepscore results:');
|
|
42
|
-
console.log(JSON.stringify(result, null, 2));
|
|
43
|
-
await client.close();
|
|
44
|
-
console.log('\nClient closed successfully');
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
console.error('Error:', error);
|
|
48
|
-
await client.close();
|
|
49
|
-
process.exit(1);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
main().catch(console.error);
|