cprime-supergateway 3.4.3 → 3.4.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.
|
@@ -8,6 +8,8 @@ import { getVersion } from '../lib/getVersion.js';
|
|
|
8
8
|
import { onSignals } from '../lib/onSignals.js';
|
|
9
9
|
import { serializeCorsOrigin } from '../lib/serializeCorsOrigin.js';
|
|
10
10
|
import { EncryptionService } from '../services/encryptionService.js';
|
|
11
|
+
import { initMongoClient } from '../lib/initMongoClient.js';
|
|
12
|
+
import { McpServerLogRepository } from '../lib/mcpServerLogRepository.js';
|
|
11
13
|
const encryptionService = new EncryptionService('env');
|
|
12
14
|
const plaintext = await encryptionService.decryptText(process.env.ENCRYPTED_ENV ?? '', process.env.AAD_JSON ? JSON.parse(process.env.AAD_JSON) : {});
|
|
13
15
|
let decryptedEnvs = {};
|
|
@@ -34,6 +36,8 @@ export async function stdioToSse(args) {
|
|
|
34
36
|
logger.info(` - CORS: ${corsOrigin ? `enabled (${serializeCorsOrigin({ corsOrigin })})` : 'disabled'}`);
|
|
35
37
|
logger.info(` - Health endpoints: ${healthEndpoints.length ? healthEndpoints.join(', ') : '(none)'}`);
|
|
36
38
|
onSignals({ logger });
|
|
39
|
+
const mongoClient = initMongoClient();
|
|
40
|
+
const mcpServerLogRepository = new McpServerLogRepository(mongoClient, process.env.MONGO_DB ?? 'localhost', process.env.LOGS_COLLECTION ?? 'mcp_server_logs');
|
|
37
41
|
const child = spawn(stdioCmd, {
|
|
38
42
|
shell: true,
|
|
39
43
|
env: { ...process.env, ...decryptedEnvs },
|
|
@@ -72,10 +76,28 @@ export async function stdioToSse(args) {
|
|
|
72
76
|
await server.connect(sseTransport);
|
|
73
77
|
const sessionId = sseTransport.sessionId;
|
|
74
78
|
if (sessionId) {
|
|
75
|
-
sessions[sessionId] = {
|
|
79
|
+
sessions[sessionId] = {
|
|
80
|
+
transport: sseTransport,
|
|
81
|
+
response: res,
|
|
82
|
+
ip: req.ip ?? '',
|
|
83
|
+
userId: req.query.userId ?? '',
|
|
84
|
+
};
|
|
76
85
|
}
|
|
77
86
|
sseTransport.onmessage = (msg) => {
|
|
78
87
|
logger.info(`SSE → Child (session ${sessionId}): ${JSON.stringify(msg)}`);
|
|
88
|
+
mcpServerLogRepository
|
|
89
|
+
.insert({
|
|
90
|
+
ip: req.ip ?? '',
|
|
91
|
+
userId: req.query.userId ?? '',
|
|
92
|
+
sessionId,
|
|
93
|
+
type: 'rpc',
|
|
94
|
+
data: msg,
|
|
95
|
+
createdAt: new Date(),
|
|
96
|
+
updatedAt: new Date(),
|
|
97
|
+
})
|
|
98
|
+
.catch((err) => {
|
|
99
|
+
logger.error(`Failed to insert log:`, JSON.stringify(err));
|
|
100
|
+
});
|
|
79
101
|
child.stdin.write(JSON.stringify(msg) + '\n');
|
|
80
102
|
};
|
|
81
103
|
sseTransport.onclose = () => {
|
|
@@ -129,6 +151,19 @@ export async function stdioToSse(args) {
|
|
|
129
151
|
for (const [sid, session] of Object.entries(sessions)) {
|
|
130
152
|
try {
|
|
131
153
|
session.transport.send(jsonMsg);
|
|
154
|
+
mcpServerLogRepository
|
|
155
|
+
.insert({
|
|
156
|
+
ip: session.ip,
|
|
157
|
+
userId: session.userId,
|
|
158
|
+
sessionId: sid,
|
|
159
|
+
type: 'system',
|
|
160
|
+
data: line,
|
|
161
|
+
createdAt: new Date(),
|
|
162
|
+
updatedAt: new Date(),
|
|
163
|
+
})
|
|
164
|
+
.catch((err) => {
|
|
165
|
+
logger.error(`Failed to insert log:`, JSON.stringify(err));
|
|
166
|
+
});
|
|
132
167
|
}
|
|
133
168
|
catch (err) {
|
|
134
169
|
logger.error(`Failed to send to session ${sid}:`, err);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class McpServerLogRepository {
|
|
2
|
+
client;
|
|
3
|
+
collection;
|
|
4
|
+
constructor(client, dbName = 'local', collectionName = 'mcp_server_logs') {
|
|
5
|
+
this.client = client;
|
|
6
|
+
this.collection = this.client.db(dbName).collection(collectionName);
|
|
7
|
+
}
|
|
8
|
+
insert(data) {
|
|
9
|
+
return this.collection.insertOne(data);
|
|
10
|
+
}
|
|
11
|
+
update(sessionId, update) {
|
|
12
|
+
return this.collection.updateOne({ sessionId, 'data.id': update.id }, {
|
|
13
|
+
$set: {
|
|
14
|
+
'data.result': update.result,
|
|
15
|
+
'data.error': update.error,
|
|
16
|
+
updatedAt: new Date(),
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cprime-supergateway",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.4",
|
|
4
4
|
"description": "Run MCP stdio servers over SSE, Streamable HTTP or visa versa",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
],
|
|
17
17
|
"type": "module",
|
|
18
18
|
"bin": {
|
|
19
|
-
"supergateway": "dist/index.js"
|
|
19
|
+
"cprime-supergateway": "dist/index.js"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "tsc -p tsconfig.build.json",
|