@momeidejiyi/dsh-general-mcp 0.3.0 → 0.3.1

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 (3) hide show
  1. package/lib/index.js +44 -23
  2. package/package.json +1 -1
  3. package/src/index.ts +46 -22
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // @momeidejiyi/dsh-general-mcp@0.3.0 (generated)
1
+ // @momeidejiyi/dsh-general-mcp@0.3.1 (generated)
2
2
 
3
3
  // packages/general-mcp/src/index.ts
4
4
  import { appendFileSync } from "node:fs";
@@ -1053,27 +1053,18 @@ function installRoutes(ctx) {
1053
1053
  return { editor, entry };
1054
1054
  };
1055
1055
  try {
1056
- webServer.register({
1057
- kind: "exact",
1058
- path: "/api/general-mcp/catalog",
1059
- resource: async (request) => {
1060
- const hdr = {
1061
- authorization: request.headers?.get?.("authorization") ?? "",
1062
- origin: request.headers?.get?.("origin") ?? "",
1063
- host: request.headers?.get?.("host") ?? ""
1064
- };
1065
- const allowed = cors(hdr);
1066
- if (request.method === "OPTIONS") {
1067
- return new Response(null, { status: 204, headers: { ...allowed, "cache-control": "no-store" } });
1068
- }
1069
- if (!trusted(hdr)) {
1070
- return new Response("unauthorized", { status: 401, headers: { ...allowed, "cache-control": "no-store" } });
1071
- }
1072
- const url = new URL(request.url);
1073
- const raw = url.searchParams.get("since");
1074
- const since = raw !== null && /^\d+$/.test(raw) ? Number(raw) : -1;
1075
- if (since === live.version) return new Response(null, { status: 304, headers: { ...allowed, "cache-control": "no-store" } });
1076
- return new Response(JSON.stringify({
1056
+ const catalogPayload = (method, rawUrl, headers) => {
1057
+ const allowed = cors({ headers });
1058
+ if (method === "OPTIONS") return { status: 204, headers: { ...allowed }, body: void 0 };
1059
+ if (!trusted({ headers })) return { status: 401, headers: { ...allowed }, body: "unauthorized" };
1060
+ const url = new URL(rawUrl, "http://localhost");
1061
+ const raw = url.searchParams.get("since");
1062
+ const since = raw !== null && /^\d+$/.test(raw) ? Number(raw) : -1;
1063
+ if (since === live.version) return { status: 304, headers: { ...allowed }, body: void 0 };
1064
+ return {
1065
+ status: 200,
1066
+ headers: { ...allowed, "content-type": "application/json; charset=utf-8" },
1067
+ body: JSON.stringify({
1077
1068
  version: live.version,
1078
1069
  timeoutMs: live.timeoutMs,
1079
1070
  retryIntervalMs: live.retryIntervalMs,
@@ -1093,7 +1084,37 @@ function installRoutes(ctx) {
1093
1084
  tools: entry.catalog,
1094
1085
  settings: entry.settings
1095
1086
  }))
1096
- }), { status: 200, headers: { ...allowed, "content-type": "application/json; charset=utf-8", "cache-control": "no-store" } });
1087
+ })
1088
+ };
1089
+ };
1090
+ webServer.register({
1091
+ kind: "exact",
1092
+ path: "/api/general-mcp/catalog",
1093
+ handler: (req, res) => {
1094
+ const out = catalogPayload(
1095
+ req.method ?? "GET",
1096
+ req.url ?? "/",
1097
+ {
1098
+ authorization: String(req.headers?.authorization ?? ""),
1099
+ origin: String(req.headers?.origin ?? ""),
1100
+ host: String(req.headers?.host ?? "")
1101
+ }
1102
+ );
1103
+ res.writeHead(out.status, { "cache-control": "no-store", ...out.headers });
1104
+ if (out.body === void 0) res.end();
1105
+ else res.end(out.body);
1106
+ },
1107
+ resource: async (request) => {
1108
+ const out = catalogPayload(
1109
+ request.method,
1110
+ request.url,
1111
+ {
1112
+ authorization: request.headers?.get?.("authorization") ?? "",
1113
+ origin: request.headers?.get?.("origin") ?? "",
1114
+ host: request.headers?.get?.("host") ?? ""
1115
+ }
1116
+ );
1117
+ return new Response(out.body ?? null, { status: out.status, headers: { "cache-control": "no-store", ...out.headers } });
1097
1118
  }
1098
1119
  });
1099
1120
  webServer.register({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momeidejiyi/dsh-general-mcp",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Single-endpoint MCP bridge for DSH: connects one gateway and registers its tools.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
package/src/index.ts CHANGED
@@ -456,27 +456,20 @@ function installRoutes(ctx: any): void {
456
456
  }
457
457
 
458
458
  try {
459
- webServer.register({
460
- kind: 'exact',
461
- path: '/api/general-mcp/catalog',
462
- resource: async (request: any) => {
463
- const hdr = {
464
- authorization: request.headers?.get?.('authorization') ?? '',
465
- origin: request.headers?.get?.('origin') ?? '',
466
- host: request.headers?.get?.('host') ?? '',
467
- }
468
- const allowed = cors(hdr)
469
- if (request.method === 'OPTIONS') {
470
- return new Response(null, { status: 204, headers: { ...allowed, 'cache-control': 'no-store' } })
471
- }
472
- if (!trusted(hdr)) {
473
- return new Response('unauthorized', { status: 401, headers: { ...allowed, 'cache-control': 'no-store' } })
474
- }
475
- const url = new URL(request.url)
476
- const raw = url.searchParams.get('since')
477
- const since = raw !== null && /^\d+$/.test(raw) ? Number(raw) : -1
478
- if (since === live.version) return new Response(null, { status: 304, headers: { ...allowed, 'cache-control': 'no-store' } })
479
- return new Response(JSON.stringify({
459
+ // Older DSH builds only dispatch "handler" routes; newer ones prefer the
460
+ // Fetch-style "resource". Register both so the catalog works either way.
461
+ const catalogPayload = (method: string, rawUrl: string, headers: Record<string, string>) => {
462
+ const allowed = cors({ headers })
463
+ if (method === 'OPTIONS') return { status: 204, headers: { ...allowed }, body: undefined as string | undefined }
464
+ if (!trusted({ headers })) return { status: 401, headers: { ...allowed }, body: 'unauthorized' }
465
+ const url = new URL(rawUrl, 'http://localhost')
466
+ const raw = url.searchParams.get('since')
467
+ const since = raw !== null && /^\d+$/.test(raw) ? Number(raw) : -1
468
+ if (since === live.version) return { status: 304, headers: { ...allowed }, body: undefined }
469
+ return {
470
+ status: 200,
471
+ headers: { ...allowed, 'content-type': 'application/json; charset=utf-8' },
472
+ body: JSON.stringify({
480
473
  version: live.version,
481
474
  timeoutMs: live.timeoutMs,
482
475
  retryIntervalMs: live.retryIntervalMs,
@@ -496,7 +489,38 @@ function installRoutes(ctx: any): void {
496
489
  tools: entry.catalog,
497
490
  settings: entry.settings,
498
491
  })),
499
- }), { status: 200, headers: { ...allowed, 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' } })
492
+ }),
493
+ }
494
+ }
495
+
496
+ webServer.register({
497
+ kind: 'exact',
498
+ path: '/api/general-mcp/catalog',
499
+ handler: (req: any, res: any) => {
500
+ const out = catalogPayload(
501
+ req.method ?? 'GET',
502
+ req.url ?? '/',
503
+ {
504
+ authorization: String(req.headers?.authorization ?? ''),
505
+ origin: String(req.headers?.origin ?? ''),
506
+ host: String(req.headers?.host ?? ''),
507
+ },
508
+ )
509
+ res.writeHead(out.status, { 'cache-control': 'no-store', ...out.headers })
510
+ if (out.body === undefined) res.end()
511
+ else res.end(out.body)
512
+ },
513
+ resource: async (request: any) => {
514
+ const out = catalogPayload(
515
+ request.method,
516
+ request.url,
517
+ {
518
+ authorization: request.headers?.get?.('authorization') ?? '',
519
+ origin: request.headers?.get?.('origin') ?? '',
520
+ host: request.headers?.get?.('host') ?? '',
521
+ },
522
+ )
523
+ return new Response(out.body ?? null, { status: out.status, headers: { 'cache-control': 'no-store', ...out.headers } })
500
524
  },
501
525
  })
502
526