@codemem/mcp 0.47.0-beta.3 → 0.47.0
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/dist/http.d.ts.map +1 -1
- package/dist/http.js +76 -74
- package/dist/http.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/{server-C-Z_tmAr.js → server-igIo9ay0.js} +21 -16
- package/dist/{server-C-Z_tmAr.js.map → server-igIo9ay0.js.map} +1 -1
- package/dist/stdio.js +33 -16
- package/dist/stdio.js.map +1 -1
- package/dist/tools/search.d.ts.map +1 -1
- package/package.json +4 -3
package/dist/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":";AAEA;;;;;;GAMG;AAGH,OAAO,EAAsC,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAG5E,OAAO,EAAE,WAAW,EAAiB,MAAM,eAAe,CAAC;AAU3D,OAAO,EAGN,KAAK,iBAAiB,EAGtB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAYN,KAAK,qBAAqB,EAC1B,MAAM,YAAY,CAAC;AASpB,eAAO,MAAM,qBAAqB,cAAc,CAAC;AACjD,eAAO,MAAM,qBAAqB,QAAQ,CAAC;AAQ3C,eAAO,MAAM,4BAA4B,QAAkB,CAAC;AAC5D,eAAO,MAAM,kCAAkC,QAAgB,CAAC;AAUhE,MAAM,WAAW,qBAAqB;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAC9C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,iBAAiB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AAS,EAAE,iBAAiB,UAAQ,GAAG,MAAM,CAc/F;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED,wBAAgB,yBAAyB,CACxC,KAAK,qBAA6C,GAChD,OAAO,CAET;AAED,wBAAgB,2BAA2B,CAC1C,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,YAAY,EAAE,MAAM,GAClB,OAAO,CAWT;AAED,wBAAgB,6BAA6B,CAC5C,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,YAAY,EAAE,MAAM,GAClB,OAAO,CAkBT;AAED,wBAAgB,oCAAoC,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAGzF;AA+BD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAO1E;AAED,wBAAsB,yBAAyB,CAC9C,OAAO,GAAE,qBAA0B,GACjC,OAAO,CAAC,oBAAoB,CAAC,CAsQ/B"}
|
package/dist/http.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { n as e, t } from "./server-
|
|
2
|
+
import { n as e, t } from "./server-igIo9ay0.js";
|
|
3
3
|
import { createHash as n, createHmac as r, createPublicKey as i, randomBytes as a, randomUUID as o, timingSafeEqual as s, verify as c } from "node:crypto";
|
|
4
4
|
import { createServer as l } from "node:http";
|
|
5
5
|
import { isIP as u, isIPv6 as d } from "node:net";
|
|
@@ -2851,7 +2851,7 @@ function Un(e) {
|
|
|
2851
2851
|
return t;
|
|
2852
2852
|
}
|
|
2853
2853
|
async function Wn(e = {}) {
|
|
2854
|
-
let n = Ln(e.host ?? process.env.CODEMEM_MCP_HTTP_HOST, e.allowUnsafePublic ?? Rn()), r = Un(e.port ?? process.env.CODEMEM_MCP_HTTP_PORT), i = e.publicUrl ?? process.env.CODEMEM_MCP_HTTP_PUBLIC_URL, a = i ? Pt(i) : void 0, o = new p(e.dbPath ?? m()), s = e.oauthAccessTokenStore ? void 0 : kt(e.oauthStatePath), c = s ?? Tt(), u = s ?? Et(), d = e.oauthAccessTokenStore ?? s ?? Dt(), f = an(), g = rn(), x = a !== void 0 || f !== void 0, S = et(e.auditEmitter ?? rt()), C = /* @__PURE__ */ new Set(), ee =
|
|
2854
|
+
let n = Ln(e.host ?? process.env.CODEMEM_MCP_HTTP_HOST, e.allowUnsafePublic ?? Rn()), r = Un(e.port ?? process.env.CODEMEM_MCP_HTTP_PORT), i = e.publicUrl ?? process.env.CODEMEM_MCP_HTTP_PUBLIC_URL, a = i ? Pt(i) : void 0, o = new p(e.dbPath ?? m()), s = e.oauthAccessTokenStore ? void 0 : kt(e.oauthStatePath), c = s ?? Tt(), u = s ?? Et(), d = e.oauthAccessTokenStore ?? s ?? Dt(), f = an(), g = rn(), x = a !== void 0 || f !== void 0, S = et(e.auditEmitter ?? rt()), C = /* @__PURE__ */ new Set(), ee = rr(), w = null, T = b();
|
|
2855
2855
|
T.disable("x-powered-by"), T.set("trust proxy", "loopback");
|
|
2856
2856
|
let E = l(T);
|
|
2857
2857
|
await new Promise((e, t) => {
|
|
@@ -2862,7 +2862,7 @@ async function Wn(e = {}) {
|
|
|
2862
2862
|
E.off("error", t), e();
|
|
2863
2863
|
});
|
|
2864
2864
|
});
|
|
2865
|
-
let D = a?.href ??
|
|
2865
|
+
let D = a?.href ?? nr(E, n), O = new URL(D), k = sr(O, $(E)), A = new _n({
|
|
2866
2866
|
clientsStore: c,
|
|
2867
2867
|
codeStore: u,
|
|
2868
2868
|
tokenStore: d,
|
|
@@ -2880,31 +2880,31 @@ async function Wn(e = {}) {
|
|
|
2880
2880
|
legacyHeaders: !1,
|
|
2881
2881
|
ipv6Subnet: !1
|
|
2882
2882
|
})), T.use((e, t, n) => {
|
|
2883
|
-
let r = $(E), i =
|
|
2883
|
+
let r = $(E), i = lr(e.path);
|
|
2884
2884
|
if (i === "/mcp") {
|
|
2885
|
-
if (
|
|
2886
|
-
if (
|
|
2885
|
+
if (Kn(e, r, a)) {
|
|
2886
|
+
if (Xn(e, t, a), e.method === "OPTIONS") {
|
|
2887
2887
|
t.status(204).send("");
|
|
2888
2888
|
return;
|
|
2889
2889
|
}
|
|
2890
2890
|
return n();
|
|
2891
2891
|
}
|
|
2892
|
-
|
|
2892
|
+
Qn(e, i, a), t.status(403).type("text/plain").send("Forbidden");
|
|
2893
2893
|
return;
|
|
2894
2894
|
}
|
|
2895
|
-
if (
|
|
2896
|
-
if (
|
|
2897
|
-
if (
|
|
2895
|
+
if (cr(i)) {
|
|
2896
|
+
if (Jn(e, r, a)) {
|
|
2897
|
+
if (Xn(e, t, a), e.method === "OPTIONS") {
|
|
2898
2898
|
t.status(204).send("");
|
|
2899
2899
|
return;
|
|
2900
2900
|
}
|
|
2901
2901
|
return n();
|
|
2902
2902
|
}
|
|
2903
|
-
|
|
2903
|
+
Qn(e, i, a), t.status(403).type("text/plain").send("Forbidden");
|
|
2904
2904
|
return;
|
|
2905
2905
|
}
|
|
2906
2906
|
n();
|
|
2907
|
-
}), T.use(
|
|
2907
|
+
}), T.use(ur(S)), T.get("/oauth/callback", async (e, t) => {
|
|
2908
2908
|
let n = e.socket.remoteAddress ?? void 0;
|
|
2909
2909
|
if (!f) {
|
|
2910
2910
|
S(z("oidc_callback", {
|
|
@@ -2930,7 +2930,7 @@ async function Wn(e = {}) {
|
|
|
2930
2930
|
clientId: r.oauthParams.get("client_id") ?? "",
|
|
2931
2931
|
redirectUri: r.oauthParams.get("redirect_uri") ?? "",
|
|
2932
2932
|
codeChallenge: r.oauthParams.get("code_challenge") ?? "",
|
|
2933
|
-
scopes:
|
|
2933
|
+
scopes: yr(r.oauthParams.get("scope")),
|
|
2934
2934
|
...r.oauthParams.get("resource") ? { resource: r.oauthParams.get("resource") ?? void 0 } : {},
|
|
2935
2935
|
expiresAt: Date.now() + 3e5
|
|
2936
2936
|
});
|
|
@@ -2975,7 +2975,7 @@ async function Wn(e = {}) {
|
|
|
2975
2975
|
let j = x ? h({
|
|
2976
2976
|
verifier: A,
|
|
2977
2977
|
resourceMetadataUrl: te
|
|
2978
|
-
}) : (e, t, n) => n(), M = x ?
|
|
2978
|
+
}) : (e, t, n) => n(), M = x ? _r(S, d) : (e, t, n) => n();
|
|
2979
2979
|
return T.post("/mcp", M, j, b.json({ limit: jn }), async (n, r) => {
|
|
2980
2980
|
n.auth && S(z("bearer", {
|
|
2981
2981
|
outcome: "success",
|
|
@@ -2997,37 +2997,39 @@ async function Wn(e = {}) {
|
|
|
2997
2997
|
} finally {
|
|
2998
2998
|
C.delete(l), await s.close();
|
|
2999
2999
|
}
|
|
3000
|
-
},
|
|
3000
|
+
}, ar), T.all("/mcp", (e, t) => {
|
|
3001
3001
|
t.setHeader("Allow", "POST"), t.status(405).type("text/plain").send("Method not allowed");
|
|
3002
3002
|
}), T.use((e, t) => {
|
|
3003
3003
|
t.status(404).type("text/plain").send("Not found");
|
|
3004
3004
|
}), {
|
|
3005
3005
|
server: E,
|
|
3006
3006
|
store: o,
|
|
3007
|
-
url: `http://${
|
|
3008
|
-
close: () => (w ??= (
|
|
3009
|
-
await Promise.allSettled([...C].map(({ mcpServer: e }) => e.close())), await new Promise((e, t) => {
|
|
3010
|
-
E.close((n) => {
|
|
3011
|
-
if (!n || n.code === "ERR_SERVER_NOT_RUNNING") {
|
|
3012
|
-
e();
|
|
3013
|
-
return;
|
|
3014
|
-
}
|
|
3015
|
-
t(n);
|
|
3016
|
-
}), E.closeAllConnections();
|
|
3017
|
-
}), o.close();
|
|
3018
|
-
})(), w)
|
|
3007
|
+
url: `http://${tr(n)}:${$(E)}/mcp`,
|
|
3008
|
+
close: () => (w ??= Gn(E, C, o), w)
|
|
3019
3009
|
};
|
|
3020
3010
|
}
|
|
3021
|
-
function Gn(e, t, n) {
|
|
3022
|
-
|
|
3011
|
+
async function Gn(e, t, n) {
|
|
3012
|
+
let r = new Promise((t, n) => {
|
|
3013
|
+
e.close((e) => {
|
|
3014
|
+
if (!e || e.code === "ERR_SERVER_NOT_RUNNING") {
|
|
3015
|
+
t();
|
|
3016
|
+
return;
|
|
3017
|
+
}
|
|
3018
|
+
n(e);
|
|
3019
|
+
}), e.closeAllConnections();
|
|
3020
|
+
}), [i] = await Promise.allSettled([r, ...[...t].map(({ mcpServer: e }) => e.close())]);
|
|
3021
|
+
if (await n.closeAsync(), i?.status === "rejected") throw i.reason;
|
|
3022
|
+
}
|
|
3023
|
+
function Kn(e, t, n) {
|
|
3024
|
+
return qn(e, t) ? !0 : n ? er(e.headers.host, n) && Yn(e.headers.origin, n) : !1;
|
|
3023
3025
|
}
|
|
3024
|
-
function
|
|
3026
|
+
function qn(e, t) {
|
|
3025
3027
|
return Vn(e.socket.remoteAddress) && zn(e.headers.host, t) && Bn(e.headers.origin, t);
|
|
3026
3028
|
}
|
|
3027
|
-
function
|
|
3028
|
-
return
|
|
3029
|
+
function Jn(e, t, n) {
|
|
3030
|
+
return qn(e, t) ? !0 : n ? er(e.headers.host, n) && Yn(e.headers.origin, n) : !1;
|
|
3029
3031
|
}
|
|
3030
|
-
function
|
|
3032
|
+
function Yn(e, t) {
|
|
3031
3033
|
if (!e) return !0;
|
|
3032
3034
|
try {
|
|
3033
3035
|
let n = new URL(e);
|
|
@@ -3036,12 +3038,12 @@ function Jn(e, t) {
|
|
|
3036
3038
|
return !1;
|
|
3037
3039
|
}
|
|
3038
3040
|
}
|
|
3039
|
-
function
|
|
3041
|
+
function Xn(e, t, n) {
|
|
3040
3042
|
if (!n) return;
|
|
3041
|
-
let r =
|
|
3043
|
+
let r = Zn(e.headers.origin, n);
|
|
3042
3044
|
r && (t.setHeader("Access-Control-Allow-Origin", r), t.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS"), t.setHeader("Access-Control-Allow-Headers", e.headers["access-control-request-headers"] ?? En), t.setHeader("Access-Control-Max-Age", Dn), t.setHeader("Vary", "Origin"));
|
|
3043
3045
|
}
|
|
3044
|
-
function
|
|
3046
|
+
function Zn(e, t) {
|
|
3045
3047
|
if (e) try {
|
|
3046
3048
|
let n = new URL(e).origin;
|
|
3047
3049
|
if (n === t.origin || Tn.has(n)) return n;
|
|
@@ -3049,7 +3051,7 @@ function Xn(e, t) {
|
|
|
3049
3051
|
return;
|
|
3050
3052
|
}
|
|
3051
3053
|
}
|
|
3052
|
-
function
|
|
3054
|
+
function Qn(e, t, n) {
|
|
3053
3055
|
console.warn(JSON.stringify({
|
|
3054
3056
|
source: "codemem-mcp-http-guard",
|
|
3055
3057
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -3057,16 +3059,16 @@ function Zn(e, t, n) {
|
|
|
3057
3059
|
reason: "host_or_origin_mismatch",
|
|
3058
3060
|
method: e.method,
|
|
3059
3061
|
path: t,
|
|
3060
|
-
host:
|
|
3061
|
-
origin:
|
|
3062
|
+
host: $n(e.headers.host),
|
|
3063
|
+
origin: $n(e.headers.origin),
|
|
3062
3064
|
expectedOrigin: n?.origin,
|
|
3063
3065
|
remoteAddress: e.socket.remoteAddress ?? void 0
|
|
3064
3066
|
}));
|
|
3065
3067
|
}
|
|
3066
|
-
function
|
|
3068
|
+
function $n(e) {
|
|
3067
3069
|
return !e || e.length <= On ? e : `${e.slice(0, On)}…`;
|
|
3068
3070
|
}
|
|
3069
|
-
function
|
|
3071
|
+
function er(e, t) {
|
|
3070
3072
|
let n = Hn(e);
|
|
3071
3073
|
if (!n) return !1;
|
|
3072
3074
|
let r = t.port ? Number(t.port) : t.protocol === "https:" ? 443 : 80, i = t.protocol === "https:" ? 443 : 80, a = n.port ?? i;
|
|
@@ -3076,16 +3078,16 @@ function $(e) {
|
|
|
3076
3078
|
let t = e.address();
|
|
3077
3079
|
return !t || typeof t == "string" ? Cn : t.port;
|
|
3078
3080
|
}
|
|
3079
|
-
function
|
|
3081
|
+
function tr(e) {
|
|
3080
3082
|
return u(e) === 6 ? `[${e}]` : e;
|
|
3081
3083
|
}
|
|
3082
|
-
function
|
|
3083
|
-
return `http://${
|
|
3084
|
+
function nr(e, t) {
|
|
3085
|
+
return `http://${tr(t)}:${$(e)}/mcp`;
|
|
3084
3086
|
}
|
|
3085
|
-
function
|
|
3087
|
+
function rr() {
|
|
3086
3088
|
let t = /* @__PURE__ */ new Map();
|
|
3087
3089
|
return (r) => {
|
|
3088
|
-
if (!r.principal) return
|
|
3090
|
+
if (!r.principal) return ir(o());
|
|
3089
3091
|
for (let [e, n] of t) n.expiresAt <= r.now && t.delete(e);
|
|
3090
3092
|
let i = n("sha256").update(JSON.stringify([
|
|
3091
3093
|
r.endpoint.href,
|
|
@@ -3093,7 +3095,7 @@ function nr() {
|
|
|
3093
3095
|
e(r.requestBody)
|
|
3094
3096
|
])).digest("hex"), a = t.get(i);
|
|
3095
3097
|
if (a) return a.scopeId;
|
|
3096
|
-
let s =
|
|
3098
|
+
let s = ir(JSON.stringify([i, r.now]));
|
|
3097
3099
|
for (t.set(i, {
|
|
3098
3100
|
scopeId: s,
|
|
3099
3101
|
expiresAt: r.now + Mn
|
|
@@ -3105,11 +3107,11 @@ function nr() {
|
|
|
3105
3107
|
return s;
|
|
3106
3108
|
};
|
|
3107
3109
|
}
|
|
3108
|
-
function
|
|
3110
|
+
function ir(e) {
|
|
3109
3111
|
return `mcp-http:${n("sha256").update(e).digest("hex")}`;
|
|
3110
3112
|
}
|
|
3111
|
-
function
|
|
3112
|
-
let i =
|
|
3113
|
+
function ar(e, t, n, r) {
|
|
3114
|
+
let i = or(e);
|
|
3113
3115
|
if (i === null) {
|
|
3114
3116
|
r(e);
|
|
3115
3117
|
return;
|
|
@@ -3123,30 +3125,30 @@ function ir(e, t, n, r) {
|
|
|
3123
3125
|
id: null
|
|
3124
3126
|
});
|
|
3125
3127
|
}
|
|
3126
|
-
function
|
|
3128
|
+
function or(e) {
|
|
3127
3129
|
if (typeof e != "object" || !e) return null;
|
|
3128
3130
|
let t = e;
|
|
3129
3131
|
return t.type === "entity.too.large" ? 413 : t.type === "entity.parse.failed" ? 400 : null;
|
|
3130
3132
|
}
|
|
3131
|
-
function
|
|
3133
|
+
function sr(e, t) {
|
|
3132
3134
|
return e.protocol === "https:" || Z(e.hostname) && Q(e.hostname) !== "::1" ? new URL(e.origin) : new URL(`http://localhost:${t}/`);
|
|
3133
3135
|
}
|
|
3134
|
-
function
|
|
3136
|
+
function cr(e) {
|
|
3135
3137
|
return e === "/register" || e === "/authorize" || e === "/token" || e === "/revoke" || e === "/oauth/callback" || e === "/.well-known/oauth-authorization-server" || e === "/.well-known/oauth-protected-resource/mcp";
|
|
3136
3138
|
}
|
|
3137
|
-
function
|
|
3139
|
+
function lr(e) {
|
|
3138
3140
|
return e.length > 1 ? e.replace(/\/+$/, "") : e;
|
|
3139
3141
|
}
|
|
3140
|
-
function
|
|
3142
|
+
function ur(e) {
|
|
3141
3143
|
return (t, n, r) => {
|
|
3142
3144
|
let i = t.path;
|
|
3143
|
-
if (!
|
|
3145
|
+
if (!dr(i)) return r();
|
|
3144
3146
|
let a, o = n.json.bind(n);
|
|
3145
3147
|
n.json = ((e) => (a = e, o(e))), n.on("finish", () => {
|
|
3146
3148
|
if (i === "/oauth/callback") return;
|
|
3147
|
-
let r =
|
|
3149
|
+
let r = fr(i, t);
|
|
3148
3150
|
if (!r) return;
|
|
3149
|
-
let o =
|
|
3151
|
+
let o = mr(n, a), s = gr(t, a);
|
|
3150
3152
|
e(z(r, {
|
|
3151
3153
|
outcome: o ? "denied" : "success",
|
|
3152
3154
|
...o ? { reason: o } : {},
|
|
@@ -3156,17 +3158,17 @@ function lr(e) {
|
|
|
3156
3158
|
}), r();
|
|
3157
3159
|
};
|
|
3158
3160
|
}
|
|
3159
|
-
function
|
|
3160
|
-
return
|
|
3161
|
+
function dr(e) {
|
|
3162
|
+
return pr(e) !== null;
|
|
3161
3163
|
}
|
|
3162
|
-
function
|
|
3163
|
-
return e === "/token" && t.body?.grant_type === "refresh_token" ? "refresh" :
|
|
3164
|
+
function fr(e, t) {
|
|
3165
|
+
return e === "/token" && t.body?.grant_type === "refresh_token" ? "refresh" : pr(e);
|
|
3164
3166
|
}
|
|
3165
|
-
function
|
|
3167
|
+
function pr(e) {
|
|
3166
3168
|
return e === "/register" ? "registration" : e === "/authorize" ? "authorize" : e === "/token" ? "token" : e === "/revoke" ? "revocation" : null;
|
|
3167
3169
|
}
|
|
3168
|
-
function
|
|
3169
|
-
let n =
|
|
3170
|
+
function mr(e, t) {
|
|
3171
|
+
let n = hr(t);
|
|
3170
3172
|
if (n) return n;
|
|
3171
3173
|
let r = e.getHeader("location");
|
|
3172
3174
|
if (typeof r == "string") try {
|
|
@@ -3175,15 +3177,15 @@ function pr(e, t) {
|
|
|
3175
3177
|
return;
|
|
3176
3178
|
}
|
|
3177
3179
|
}
|
|
3178
|
-
function
|
|
3180
|
+
function hr(e) {
|
|
3179
3181
|
if (typeof e == "object" && e && "error" in e && typeof e.error == "string") return e.error;
|
|
3180
3182
|
}
|
|
3181
|
-
function
|
|
3183
|
+
function gr(e, t) {
|
|
3182
3184
|
return typeof t == "object" && t && "client_id" in t && typeof t.client_id == "string" ? t.client_id : (typeof e.body?.client_id == "string" ? e.body.client_id : void 0) || (typeof e.query.client_id == "string" ? e.query.client_id : void 0);
|
|
3183
3185
|
}
|
|
3184
|
-
function
|
|
3186
|
+
function _r(e, t) {
|
|
3185
3187
|
return (n, r, i) => {
|
|
3186
|
-
let a =
|
|
3188
|
+
let a = vr(n.headers.authorization, t);
|
|
3187
3189
|
a && e(z("bearer", {
|
|
3188
3190
|
outcome: "denied",
|
|
3189
3191
|
reason: a,
|
|
@@ -3191,21 +3193,21 @@ function gr(e, t) {
|
|
|
3191
3193
|
})), i();
|
|
3192
3194
|
};
|
|
3193
3195
|
}
|
|
3194
|
-
function
|
|
3196
|
+
function vr(e, t) {
|
|
3195
3197
|
if (!e) return "missing_authorization_header";
|
|
3196
3198
|
let [n, r, i] = e.trim().split(/\s+/);
|
|
3197
3199
|
if (!n || !r || i || n.toLowerCase() !== "bearer") return "malformed_authorization_header";
|
|
3198
3200
|
let a = t.verifyToken(r);
|
|
3199
3201
|
return a.ok ? null : a.reason;
|
|
3200
3202
|
}
|
|
3201
|
-
function
|
|
3203
|
+
function yr(e) {
|
|
3202
3204
|
return e?.split(/\s+/).map((e) => e.trim()).filter(Boolean) ?? [];
|
|
3203
3205
|
}
|
|
3204
|
-
function
|
|
3206
|
+
function br() {
|
|
3205
3207
|
let e = process.argv[1];
|
|
3206
3208
|
return e ? import.meta.url === f(e).href : !1;
|
|
3207
3209
|
}
|
|
3208
|
-
async function
|
|
3210
|
+
async function xr() {
|
|
3209
3211
|
let e = await Wn();
|
|
3210
3212
|
console.error(`codemem MCP HTTP server listening at ${e.url}`);
|
|
3211
3213
|
let t = async () => {
|
|
@@ -3216,7 +3218,7 @@ async function br() {
|
|
|
3216
3218
|
};
|
|
3217
3219
|
process.on("SIGINT", t), process.on("SIGTERM", t);
|
|
3218
3220
|
}
|
|
3219
|
-
|
|
3221
|
+
br() && xr().catch((e) => {
|
|
3220
3222
|
console.error("codemem MCP HTTP server failed to start:", e), process.exit(1);
|
|
3221
3223
|
});
|
|
3222
3224
|
//#endregion
|