@meldocio/mcp-stdio-proxy 1.0.2 → 1.0.3
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/bin/meldoc-mcp-proxy.js +50 -8
- package/package.json +1 -1
package/bin/meldoc-mcp-proxy.js
CHANGED
|
@@ -18,7 +18,7 @@ const JSON_RPC_ERROR_CODES = {
|
|
|
18
18
|
const token = process.env.MELDOC_MCP_TOKEN;
|
|
19
19
|
const apiUrl = process.env.MELDOC_API_URL || 'https://api.meldoc.io';
|
|
20
20
|
const rpcEndpoint = `${apiUrl}/mcp/v1/rpc`;
|
|
21
|
-
const REQUEST_TIMEOUT =
|
|
21
|
+
const REQUEST_TIMEOUT = 25000; // 25 seconds (less than Claude Desktop's 30s timeout)
|
|
22
22
|
|
|
23
23
|
// Validate token
|
|
24
24
|
if (!token) {
|
|
@@ -86,8 +86,11 @@ function handleLine(line) {
|
|
|
86
86
|
const request = JSON.parse(line);
|
|
87
87
|
handleRequest(request);
|
|
88
88
|
} catch (parseError) {
|
|
89
|
-
// Invalid JSON -
|
|
90
|
-
|
|
89
|
+
// Invalid JSON - try to extract id from the raw line if possible
|
|
90
|
+
// For parse errors, we can't reliably get the id, so we skip the response
|
|
91
|
+
// to avoid Zod validation errors in Claude Desktop (it doesn't accept id: null)
|
|
92
|
+
// This is acceptable per JSON-RPC spec - parse errors can be ignored if id is unknown
|
|
93
|
+
console.error(`Parse error: ${parseError.message}`, { to: 'stderr' });
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
|
|
@@ -131,11 +134,16 @@ async function handleRequest(request) {
|
|
|
131
134
|
const method = req.method;
|
|
132
135
|
if (method === 'initialize') {
|
|
133
136
|
handleInitialize(req);
|
|
134
|
-
} else if (method === 'initialized') {
|
|
137
|
+
} else if (method === 'initialized' || method === 'notifications/initialized') {
|
|
138
|
+
// Notification - no response needed
|
|
139
|
+
continue;
|
|
140
|
+
} else if (method === 'notifications/cancelled') {
|
|
135
141
|
// Notification - no response needed
|
|
136
142
|
continue;
|
|
137
143
|
} else if (method === 'ping') {
|
|
138
144
|
handlePing(req);
|
|
145
|
+
} else if (method === 'resources/list') {
|
|
146
|
+
handleResourcesList(req);
|
|
139
147
|
} else {
|
|
140
148
|
// Forward to backend
|
|
141
149
|
await processSingleRequest(req);
|
|
@@ -157,15 +165,22 @@ async function handleRequest(request) {
|
|
|
157
165
|
if (method === 'initialize') {
|
|
158
166
|
handleInitialize(request);
|
|
159
167
|
return;
|
|
160
|
-
} else if (method === 'initialized') {
|
|
168
|
+
} else if (method === 'initialized' || method === 'notifications/initialized') {
|
|
161
169
|
// Notification - no response needed per MCP spec
|
|
162
170
|
return;
|
|
171
|
+
} else if (method === 'notifications/cancelled') {
|
|
172
|
+
// Notification - no response needed
|
|
173
|
+
return;
|
|
163
174
|
} else if (method === 'ping') {
|
|
164
175
|
handlePing(request);
|
|
165
176
|
return;
|
|
177
|
+
} else if (method === 'resources/list') {
|
|
178
|
+
// Return empty resources list (resources not supported yet)
|
|
179
|
+
handleResourcesList(request);
|
|
180
|
+
return;
|
|
166
181
|
}
|
|
167
182
|
|
|
168
|
-
// All other methods (tools/*,
|
|
183
|
+
// All other methods (tools/*, etc.) are forwarded to backend
|
|
169
184
|
await processSingleRequest(request);
|
|
170
185
|
}
|
|
171
186
|
|
|
@@ -185,7 +200,7 @@ function handleInitialize(request) {
|
|
|
185
200
|
},
|
|
186
201
|
serverInfo: {
|
|
187
202
|
name: '@meldocio/mcp-stdio-proxy',
|
|
188
|
-
version: '1.0.
|
|
203
|
+
version: '1.0.2'
|
|
189
204
|
}
|
|
190
205
|
}
|
|
191
206
|
};
|
|
@@ -212,6 +227,25 @@ function handlePing(request) {
|
|
|
212
227
|
}
|
|
213
228
|
}
|
|
214
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Handle resources/list method
|
|
232
|
+
* Returns empty list as resources are not supported yet
|
|
233
|
+
*/
|
|
234
|
+
function handleResourcesList(request) {
|
|
235
|
+
const response = {
|
|
236
|
+
jsonrpc: '2.0',
|
|
237
|
+
id: request.id,
|
|
238
|
+
result: {
|
|
239
|
+
resources: []
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
process.stdout.write(JSON.stringify(response) + '\n');
|
|
244
|
+
if (process.stdout.isTTY) {
|
|
245
|
+
process.stdout.flush();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
215
249
|
/**
|
|
216
250
|
* Process a single JSON-RPC request
|
|
217
251
|
* Forwards the request to the backend MCP API
|
|
@@ -302,9 +336,17 @@ async function processSingleRequest(request) {
|
|
|
302
336
|
* Send JSON-RPC error response
|
|
303
337
|
*/
|
|
304
338
|
function sendError(id, code, message) {
|
|
339
|
+
// Only send error response if id is defined (not for notifications)
|
|
340
|
+
// Claude Desktop's Zod schema doesn't accept null for id
|
|
341
|
+
if (id === undefined || id === null) {
|
|
342
|
+
// For notifications or parse errors without id, don't send response
|
|
343
|
+
// or send without id field
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
|
|
305
347
|
const errorResponse = {
|
|
306
348
|
jsonrpc: '2.0',
|
|
307
|
-
id: id
|
|
349
|
+
id: id,
|
|
308
350
|
error: {
|
|
309
351
|
code: code,
|
|
310
352
|
message: message
|