@upstash/context7-mcp 2.2.4 → 2.2.5

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.
Files changed (2) hide show
  1. package/dist/index.js +48 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -216,6 +216,49 @@ Do not call this tool more than 3 times per question.`,
216
216
  });
217
217
  return server;
218
218
  }
219
+ const GLOBAL_ALIASES = {
220
+ query: ["userQuery", "question"],
221
+ };
222
+ // Tool-scoped aliases, for keys that are canonical on one tool but a
223
+ // hallucination on another (e.g. `libraryName` is canonical for
224
+ // `resolve-library-id`, so we only rewrite it on `query-docs` calls).
225
+ const TOOL_ALIASES = {
226
+ "query-docs": {
227
+ libraryId: ["context7CompatibleLibraryID", "libraryID", "libraryName"],
228
+ },
229
+ };
230
+ function applyAliases(args, aliases) {
231
+ for (const [canonical, alternatives] of Object.entries(aliases)) {
232
+ if (canonical in args)
233
+ continue;
234
+ for (const alt of alternatives) {
235
+ if (alt in args) {
236
+ args[canonical] = args[alt];
237
+ delete args[alt];
238
+ break;
239
+ }
240
+ }
241
+ }
242
+ }
243
+ // Install BEFORE `server.connect(transport)`: the SDK's `Protocol.connect()`
244
+ // captures the existing `onmessage` and chains its dispatch handler over it,
245
+ // so our hook runs first on every incoming JSON-RPC message.
246
+ function installTransportArgAliasing(transport) {
247
+ transport.onmessage = (message) => {
248
+ const msg = message;
249
+ if (msg.method !== "tools/call")
250
+ return;
251
+ const args = msg.params?.arguments;
252
+ if (!args || typeof args !== "object")
253
+ return;
254
+ const argsRecord = args;
255
+ applyAliases(argsRecord, GLOBAL_ALIASES);
256
+ const toolName = msg.params?.name;
257
+ if (toolName && toolName in TOOL_ALIASES) {
258
+ applyAliases(argsRecord, TOOL_ALIASES[toolName]);
259
+ }
260
+ };
261
+ }
219
262
  async function main() {
220
263
  const transportType = TRANSPORT_TYPE;
221
264
  if (transportType === "http") {
@@ -317,6 +360,7 @@ async function main() {
317
360
  server.close();
318
361
  });
319
362
  await requestContext.run(context, async () => {
363
+ installTransportArgAliasing(transport);
320
364
  await server.connect(transport);
321
365
  await transport.handleRequest(req, res, req.body);
322
366
  });
@@ -412,6 +456,9 @@ async function main() {
412
456
  }
413
457
  else {
414
458
  stdioApiKey = cliOptions.apiKey || process.env.CONTEXT7_API_KEY;
459
+ process.stdin.on("end", () => process.exit(0));
460
+ process.stdin.on("close", () => process.exit(0));
461
+ process.on("SIGHUP", () => process.exit(0));
415
462
  const transport = new StdioServerTransport();
416
463
  const server = createMcpServer();
417
464
  // Capture client info from MCP initialize handshake (stdio only — HTTP
@@ -425,6 +472,7 @@ async function main() {
425
472
  };
426
473
  }
427
474
  };
475
+ installTransportArgAliasing(transport);
428
476
  await server.connect(transport);
429
477
  console.error(`Context7 Documentation MCP Server v${SERVER_VERSION} running on stdio`);
430
478
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upstash/context7-mcp",
3
- "version": "2.2.4",
3
+ "version": "2.2.5",
4
4
  "mcpName": "io.github.upstash/context7",
5
5
  "description": "MCP server for Context7",
6
6
  "repository": {