@memoraone/mcp 0.1.54 → 0.1.55
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/cli.cjs +1 -1
- package/dist/gateway.cjs +48 -15
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
package/dist/gateway.cjs
CHANGED
|
@@ -271,11 +271,17 @@ function getGatewayIssuerUrl(env2 = process.env) {
|
|
|
271
271
|
function getGatewayResourceBaseUrl(env2 = process.env) {
|
|
272
272
|
return `${getGatewayBaseUrl(env2)}${GATEWAY_MCP_PATH}`;
|
|
273
273
|
}
|
|
274
|
-
function getGatewayProtectedResourceMetadataUrl(env2 = process.env) {
|
|
275
|
-
|
|
274
|
+
function getGatewayProtectedResourceMetadataUrl(env2 = process.env, workspaceRoot) {
|
|
275
|
+
const metadataUrl = `${getGatewayBaseUrl(env2)}${GATEWAY_OAUTH_PRM_PATH}`;
|
|
276
|
+
if (workspaceRoot === void 0) {
|
|
277
|
+
return metadataUrl;
|
|
278
|
+
}
|
|
279
|
+
const mcpUrl = buildGatewayMcpUrl(workspaceRoot, env2);
|
|
280
|
+
const queryIndex = mcpUrl.indexOf("?");
|
|
281
|
+
return queryIndex >= 0 ? `${metadataUrl}${mcpUrl.slice(queryIndex)}` : metadataUrl;
|
|
276
282
|
}
|
|
277
|
-
function buildGatewayMcpWwwAuthenticate(env2 = process.env) {
|
|
278
|
-
const metadataUrl = getGatewayProtectedResourceMetadataUrl(env2);
|
|
283
|
+
function buildGatewayMcpWwwAuthenticate(env2 = process.env, workspaceRoot) {
|
|
284
|
+
const metadataUrl = getGatewayProtectedResourceMetadataUrl(env2, workspaceRoot);
|
|
279
285
|
return `Bearer resource_metadata="${metadataUrl}"`;
|
|
280
286
|
}
|
|
281
287
|
function isAllowedOAuthRedirectUri(redirectUri) {
|
|
@@ -11160,9 +11166,9 @@ function opaqueId(prefix) {
|
|
|
11160
11166
|
function delay(ms) {
|
|
11161
11167
|
return new Promise((resolve46) => setTimeout(resolve46, ms));
|
|
11162
11168
|
}
|
|
11163
|
-
function buildProtectedResourceMetadata(env2 = process.env) {
|
|
11169
|
+
function buildProtectedResourceMetadata(env2 = process.env, workspaceRoot) {
|
|
11164
11170
|
return {
|
|
11165
|
-
resource: getGatewayResourceBaseUrl(env2),
|
|
11171
|
+
resource: workspaceRoot === void 0 ? getGatewayResourceBaseUrl(env2) : buildGatewayMcpUrl(workspaceRoot, env2),
|
|
11166
11172
|
authorization_servers: [getGatewayIssuerUrl(env2)]
|
|
11167
11173
|
};
|
|
11168
11174
|
}
|
|
@@ -11287,11 +11293,38 @@ var GatewayOAuthSurface = class {
|
|
|
11287
11293
|
return;
|
|
11288
11294
|
}
|
|
11289
11295
|
}
|
|
11296
|
+
/**
|
|
11297
|
+
* RFC 9728 PRM. Generic probes (no `ws`) advertise the bare /mcp resource.
|
|
11298
|
+
* `?ws=` reuses gateway workspace identity; malformed/nonexistent fail closed.
|
|
11299
|
+
*/
|
|
11300
|
+
async handleProtectedResourceMetadata(res, url) {
|
|
11301
|
+
const wsOrError = getGatewayWsQueryParam(url);
|
|
11302
|
+
if (wsOrError !== null && typeof wsOrError === "object" && wsOrError.ok === false) {
|
|
11303
|
+
json(res, 404, {
|
|
11304
|
+
error: "invalid_request",
|
|
11305
|
+
error_description: "resource workspace is invalid"
|
|
11306
|
+
});
|
|
11307
|
+
return;
|
|
11308
|
+
}
|
|
11309
|
+
if (wsOrError === null) {
|
|
11310
|
+
json(res, 200, buildProtectedResourceMetadata(this.env));
|
|
11311
|
+
return;
|
|
11312
|
+
}
|
|
11313
|
+
const parsed2 = await parseGatewayWorkspaceRoot(wsOrError);
|
|
11314
|
+
if (!parsed2.ok) {
|
|
11315
|
+
json(res, 404, {
|
|
11316
|
+
error: "invalid_request",
|
|
11317
|
+
error_description: "resource workspace is invalid"
|
|
11318
|
+
});
|
|
11319
|
+
return;
|
|
11320
|
+
}
|
|
11321
|
+
json(res, 200, buildProtectedResourceMetadata(this.env, parsed2.workspaceRoot));
|
|
11322
|
+
}
|
|
11290
11323
|
async handleRequest(req, res, url) {
|
|
11291
11324
|
const { pathname } = url;
|
|
11292
11325
|
const method = req.method ?? "GET";
|
|
11293
11326
|
if (method === "GET" && (pathname === GATEWAY_OAUTH_PRM_PATH || pathname === GATEWAY_OAUTH_PRM_ROOT_PATH)) {
|
|
11294
|
-
|
|
11327
|
+
await this.handleProtectedResourceMetadata(res, url);
|
|
11295
11328
|
return true;
|
|
11296
11329
|
}
|
|
11297
11330
|
if (method === "GET" && pathname === GATEWAY_OAUTH_AS_METADATA_PATH) {
|
|
@@ -13582,8 +13615,8 @@ function sendJsonRpcHttpError(res, status, message) {
|
|
|
13582
13615
|
});
|
|
13583
13616
|
res.end(body);
|
|
13584
13617
|
}
|
|
13585
|
-
function sendUnauthorizedChallenge(res, env2) {
|
|
13586
|
-
const challenge = buildGatewayMcpWwwAuthenticate(env2);
|
|
13618
|
+
function sendUnauthorizedChallenge(res, env2, workspaceRoot) {
|
|
13619
|
+
const challenge = buildGatewayMcpWwwAuthenticate(env2, workspaceRoot);
|
|
13587
13620
|
const body = "Unauthorized";
|
|
13588
13621
|
res.writeHead(401, {
|
|
13589
13622
|
"www-authenticate": challenge,
|
|
@@ -13737,7 +13770,7 @@ async function handleAuthenticatedGatewayMcpRequest(req, res, auth, options = {}
|
|
|
13737
13770
|
const binding = await loadGatewayHttpBinding(workspaceRoot, options);
|
|
13738
13771
|
if (!binding) {
|
|
13739
13772
|
await closeGatewayMcpSessionsForWorkspace(workspaceRoot);
|
|
13740
|
-
sendUnauthorizedChallenge(res, env2);
|
|
13773
|
+
sendUnauthorizedChallenge(res, env2, workspaceRoot);
|
|
13741
13774
|
return;
|
|
13742
13775
|
}
|
|
13743
13776
|
const sessionHeader = req.headers["mcp-session-id"];
|
|
@@ -13753,7 +13786,7 @@ async function handleAuthenticatedGatewayMcpRequest(req, res, auth, options = {}
|
|
|
13753
13786
|
return;
|
|
13754
13787
|
}
|
|
13755
13788
|
if (!await ensureBindingStillValid(existing, options)) {
|
|
13756
|
-
sendUnauthorizedChallenge(res, env2);
|
|
13789
|
+
sendUnauthorizedChallenge(res, env2, workspaceRoot);
|
|
13757
13790
|
return;
|
|
13758
13791
|
}
|
|
13759
13792
|
if (method === "POST") {
|
|
@@ -13810,8 +13843,8 @@ function extractBearerToken(authorizationHeader) {
|
|
|
13810
13843
|
const token = match[1];
|
|
13811
13844
|
return token || null;
|
|
13812
13845
|
}
|
|
13813
|
-
function sendUnauthorized(res, env2) {
|
|
13814
|
-
const challenge = buildGatewayMcpWwwAuthenticate(env2);
|
|
13846
|
+
function sendUnauthorized(res, env2, workspaceRoot) {
|
|
13847
|
+
const challenge = buildGatewayMcpWwwAuthenticate(env2, workspaceRoot);
|
|
13815
13848
|
const body = "Unauthorized";
|
|
13816
13849
|
res.writeHead(401, {
|
|
13817
13850
|
"www-authenticate": challenge,
|
|
@@ -13838,7 +13871,7 @@ async function handleGatewayMcpAuthRequest(req, res, url, options = {}) {
|
|
|
13838
13871
|
const canonicalUrl = buildGatewayMcpUrl(parsed2.workspaceRoot, env2);
|
|
13839
13872
|
const token = extractBearerToken(req.headers.authorization);
|
|
13840
13873
|
if (!token) {
|
|
13841
|
-
sendUnauthorized(res, env2);
|
|
13874
|
+
sendUnauthorized(res, env2, parsed2.workspaceRoot);
|
|
13842
13875
|
return true;
|
|
13843
13876
|
}
|
|
13844
13877
|
const verified = await verifyGatewaySetupTicket(
|
|
@@ -13847,7 +13880,7 @@ async function handleGatewayMcpAuthRequest(req, res, url, options = {}) {
|
|
|
13847
13880
|
ticketOptions
|
|
13848
13881
|
);
|
|
13849
13882
|
if (!verified.ok) {
|
|
13850
|
-
sendUnauthorized(res, env2);
|
|
13883
|
+
sendUnauthorized(res, env2, parsed2.workspaceRoot);
|
|
13851
13884
|
return true;
|
|
13852
13885
|
}
|
|
13853
13886
|
await handleAuthenticatedGatewayMcpRequest(
|