@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.
- package/lib/index.js +44 -23
- package/package.json +1 -1
- package/src/index.ts +46 -22
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @momeidejiyi/dsh-general-mcp@0.3.
|
|
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
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
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
|
-
})
|
|
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
package/src/index.ts
CHANGED
|
@@ -456,27 +456,20 @@ function installRoutes(ctx: any): void {
|
|
|
456
456
|
}
|
|
457
457
|
|
|
458
458
|
try {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}
|
|
472
|
-
|
|
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
|
-
}),
|
|
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
|
|