codebase-snapshot 0.20.12 → 0.20.13
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/CHANGELOG.md +11 -0
- package/README.md +8 -3
- package/dist/bin.js +272 -56
- package/dist/{chunk-TUKY6KLH.js → chunk-GNVRD7XS.js} +274 -58
- package/dist/cli.cjs +272 -56
- package/dist/cli.js +2 -2
- package/dist/index.cjs +281 -57
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +260 -44
- package/dist/mcp.d.cts +13 -4
- package/dist/mcp.d.ts +13 -4
- package/dist/mcp.js +1 -1
- package/docs/cli.md +9 -8
- package/docs/configuration.md +1 -1
- package/docs/deploy.md +2 -2
- package/docs/mcp.md +47 -25
- package/docs/migration.md +7 -2
- package/docs/security-review.md +12 -1
- package/package.json +2 -1
package/dist/cli.cjs
CHANGED
|
@@ -2584,7 +2584,7 @@ function verifySnapshotSignature(snapshotDir) {
|
|
|
2584
2584
|
|
|
2585
2585
|
// src/version.ts
|
|
2586
2586
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
2587
|
-
var GENERATOR_VERSION = "0.20.
|
|
2587
|
+
var GENERATOR_VERSION = "0.20.13";
|
|
2588
2588
|
var SCHEMA_VERSION = "3.0.0";
|
|
2589
2589
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
2590
2590
|
function isOurGeneratorName(name) {
|
|
@@ -10865,7 +10865,7 @@ function assembleGroup(group, index, total, contentFingerprint) {
|
|
|
10865
10865
|
}
|
|
10866
10866
|
const pathLines = group.sections.map((s) => displayPath(s.file.relativePath));
|
|
10867
10867
|
const listFence = fenceForText(pathLines.join("\n"), 3);
|
|
10868
|
-
const
|
|
10868
|
+
const header2 = [
|
|
10869
10869
|
`# Codebase Snapshot Part ${zeroPad(index + 1)} of ${zeroPad(total)}`,
|
|
10870
10870
|
"",
|
|
10871
10871
|
`- Previous: ${prev}`,
|
|
@@ -10886,7 +10886,7 @@ function assembleGroup(group, index, total, contentFingerprint) {
|
|
|
10886
10886
|
"## Contents",
|
|
10887
10887
|
""
|
|
10888
10888
|
].join("\n");
|
|
10889
|
-
const assembled = (
|
|
10889
|
+
const assembled = (header2 + group.sections.map((s) => s.text).join("")).replace(
|
|
10890
10890
|
/\r\n|\r/g,
|
|
10891
10891
|
"\n"
|
|
10892
10892
|
);
|
|
@@ -11531,10 +11531,10 @@ function headerPaths(value) {
|
|
|
11531
11531
|
}
|
|
11532
11532
|
function diffSectionPaths(body) {
|
|
11533
11533
|
const paths = /* @__PURE__ */ new Set();
|
|
11534
|
-
let
|
|
11534
|
+
let header2 = null;
|
|
11535
11535
|
for (const line of body.split("\n")) {
|
|
11536
11536
|
if (line.startsWith("diff --git ")) {
|
|
11537
|
-
|
|
11537
|
+
header2 = line.slice("diff --git ".length);
|
|
11538
11538
|
continue;
|
|
11539
11539
|
}
|
|
11540
11540
|
if (line.startsWith("+++ ")) {
|
|
@@ -11547,8 +11547,8 @@ function diffSectionPaths(body) {
|
|
|
11547
11547
|
if (path29 !== null) paths.add(path29);
|
|
11548
11548
|
}
|
|
11549
11549
|
}
|
|
11550
|
-
if (paths.size === 0 &&
|
|
11551
|
-
for (const path29 of headerPaths(
|
|
11550
|
+
if (paths.size === 0 && header2 !== null) {
|
|
11551
|
+
for (const path29 of headerPaths(header2)) paths.add(path29);
|
|
11552
11552
|
}
|
|
11553
11553
|
return [...paths];
|
|
11554
11554
|
}
|
|
@@ -12926,13 +12926,22 @@ var ERROR_CODES = {
|
|
|
12926
12926
|
*/
|
|
12927
12927
|
resourceTooLarge: -32e3,
|
|
12928
12928
|
/**
|
|
12929
|
-
* A known resource that this snapshot does not contain.
|
|
12929
|
+
* A known resource that this snapshot does not contain, under a legacy revision.
|
|
12930
12930
|
*
|
|
12931
|
-
* `-32002`
|
|
12932
|
-
*
|
|
12933
|
-
*
|
|
12931
|
+
* `-32002` was the resource-not-found code through protocol revision `2025-11-25`. The
|
|
12932
|
+
* `2026-07-28` revision assigns missing resources to `-32602` and says clients SHOULD still
|
|
12933
|
+
* accept `-32002` from older servers. The dispatcher therefore chooses by era: `-32602` for
|
|
12934
|
+
* modern requests and this code for legacy ones. Answering `-32602` for `snapshot://prompt`
|
|
12935
|
+
* in a snapshot generated with `--skip-artifacts prompt` would tell a legacy client its URI
|
|
12936
|
+
* was wrong when the artifact had simply been left out.
|
|
12934
12937
|
*/
|
|
12935
12938
|
resourceNotFound: -32002,
|
|
12939
|
+
/**
|
|
12940
|
+
* Streamable HTTP headers that are missing, malformed or disagree with the request body.
|
|
12941
|
+
*
|
|
12942
|
+
* Protocol revision `2026-07-28` reserves `-32020` for this. The HTTP status is `400`.
|
|
12943
|
+
*/
|
|
12944
|
+
headerMismatch: -32020,
|
|
12936
12945
|
/**
|
|
12937
12946
|
* The server is at its concurrency limit.
|
|
12938
12947
|
*
|
|
@@ -16272,7 +16281,7 @@ var readTool = {
|
|
|
16272
16281
|
}
|
|
16273
16282
|
const returnedLines = body.length === 0 ? truncatedByBytes && !clippedInsideLine && window.fromLine <= window.totalLines ? 1 : 0 : body.split("\n").length;
|
|
16274
16283
|
const moreRemain = !clippedInsideLine && !window.pastEnd && (window.truncated || truncatedByBytes);
|
|
16275
|
-
const
|
|
16284
|
+
const header2 = [
|
|
16276
16285
|
`${entry.relativePath} \u2014 ${entry.part}, ${entry.layer}/${entry.kind}, ${entry.language}`,
|
|
16277
16286
|
// The line range is the answer to "where am I in this file", and it is computed from the
|
|
16278
16287
|
// body the window was taken from, so it is just as meaningful for a preview as for a full
|
|
@@ -16287,7 +16296,7 @@ var readTool = {
|
|
|
16287
16296
|
] : [],
|
|
16288
16297
|
window.totalLines === 0 ? "This file is empty." : window.pastEnd ? `This file has ${window.totalLines} line(s); fromLine=${window.fromLine} is past its end.` : clippedInsideLine ? `Line ${window.fromLine} of ${window.totalLines}: this line is longer than one result can carry, so this page ends mid-line.` : `Lines ${window.fromLine}\u2013${window.fromLine + returnedLines - 1} of ${window.totalLines}.`
|
|
16289
16298
|
];
|
|
16290
|
-
const lines = [...
|
|
16299
|
+
const lines = [...header2, "", body];
|
|
16291
16300
|
if (moreRemain) {
|
|
16292
16301
|
const next = window.fromLine + returnedLines;
|
|
16293
16302
|
lines.push("", `Truncated. Call snapshot_read with fromLine=${next} for the rest.`);
|
|
@@ -18257,15 +18266,20 @@ function createMcpServer(options) {
|
|
|
18257
18266
|
websiteUrl: options.info.websiteUrl
|
|
18258
18267
|
});
|
|
18259
18268
|
const ok = (id, result, modern) => successResponse(id, result, modern, options.info);
|
|
18269
|
+
const cacheable = (result) => ({
|
|
18270
|
+
...result,
|
|
18271
|
+
cacheScope: "private",
|
|
18272
|
+
ttlMs: 0
|
|
18273
|
+
});
|
|
18260
18274
|
const cancellations = /* @__PURE__ */ new Map();
|
|
18261
18275
|
function handleNotification(method, params) {
|
|
18262
18276
|
if (method === METHOD3.initialized && session.era === "legacy") session.ready = true;
|
|
18263
18277
|
if (method === "notifications/cancelled") {
|
|
18264
|
-
const
|
|
18265
|
-
if (typeof
|
|
18266
|
-
const cancel = cancellations.get(
|
|
18278
|
+
const requestId2 = params?.requestId;
|
|
18279
|
+
if (typeof requestId2 === "string" || typeof requestId2 === "number") {
|
|
18280
|
+
const cancel = cancellations.get(requestId2);
|
|
18267
18281
|
if (cancel !== void 0) {
|
|
18268
|
-
cancellations.delete(
|
|
18282
|
+
cancellations.delete(requestId2);
|
|
18269
18283
|
cancel();
|
|
18270
18284
|
}
|
|
18271
18285
|
}
|
|
@@ -18293,15 +18307,11 @@ function createMcpServer(options) {
|
|
|
18293
18307
|
function discover(id) {
|
|
18294
18308
|
return ok(
|
|
18295
18309
|
id,
|
|
18296
|
-
{
|
|
18310
|
+
cacheable({
|
|
18297
18311
|
supportedVersions: [...SUPPORTED_PROTOCOL_VERSIONS],
|
|
18298
18312
|
capabilities: capabilities(),
|
|
18299
|
-
instructions: options.instructions
|
|
18300
|
-
|
|
18301
|
-
// may be cached only by the client that asked, and not at all after this response.
|
|
18302
|
-
cacheScope: "private",
|
|
18303
|
-
ttlMs: 0
|
|
18304
|
-
},
|
|
18313
|
+
instructions: options.instructions
|
|
18314
|
+
}),
|
|
18305
18315
|
true
|
|
18306
18316
|
);
|
|
18307
18317
|
}
|
|
@@ -18315,7 +18325,7 @@ function createMcpServer(options) {
|
|
|
18315
18325
|
annotations: tool.annotations,
|
|
18316
18326
|
_meta: { "codebase-snapshot/cost": tool.cost }
|
|
18317
18327
|
}));
|
|
18318
|
-
return ok(id, { tools }, modern);
|
|
18328
|
+
return ok(id, cacheable({ tools }), modern);
|
|
18319
18329
|
}
|
|
18320
18330
|
async function callTool(id, modern, params) {
|
|
18321
18331
|
const name = params?.name;
|
|
@@ -18391,7 +18401,7 @@ function createMcpServer(options) {
|
|
|
18391
18401
|
}
|
|
18392
18402
|
async function listResources(id, modern) {
|
|
18393
18403
|
const resources = await options.resources.list(options.context);
|
|
18394
|
-
return ok(id, { resources }, modern);
|
|
18404
|
+
return ok(id, cacheable({ resources }), modern);
|
|
18395
18405
|
}
|
|
18396
18406
|
async function readResource(id, modern, params) {
|
|
18397
18407
|
const uri = params?.uri;
|
|
@@ -18403,7 +18413,12 @@ function createMcpServer(options) {
|
|
|
18403
18413
|
contents = await options.resources.read(uri, options.context);
|
|
18404
18414
|
} catch (error) {
|
|
18405
18415
|
if (error instanceof ResourceNotFoundError) {
|
|
18406
|
-
return errorResponse(
|
|
18416
|
+
return errorResponse(
|
|
18417
|
+
id,
|
|
18418
|
+
modern ? ERROR_CODES.invalidParams : ERROR_CODES.resourceNotFound,
|
|
18419
|
+
error.message,
|
|
18420
|
+
{ uri: error.uri }
|
|
18421
|
+
);
|
|
18407
18422
|
}
|
|
18408
18423
|
if (error instanceof ResourceTooLargeError) {
|
|
18409
18424
|
options.context.log(
|
|
@@ -18420,7 +18435,7 @@ function createMcpServer(options) {
|
|
|
18420
18435
|
if (!contents) {
|
|
18421
18436
|
return errorResponse(id, ERROR_CODES.invalidParams, `Unknown resource "${uri}".`);
|
|
18422
18437
|
}
|
|
18423
|
-
return ok(id, { contents: [contents] }, modern);
|
|
18438
|
+
return ok(id, cacheable({ contents: [contents] }), modern);
|
|
18424
18439
|
}
|
|
18425
18440
|
function listPrompts(id, modern) {
|
|
18426
18441
|
const prompts = options.prompts.map((prompt) => ({
|
|
@@ -18429,7 +18444,7 @@ function createMcpServer(options) {
|
|
|
18429
18444
|
description: prompt.description,
|
|
18430
18445
|
arguments: prompt.arguments
|
|
18431
18446
|
}));
|
|
18432
|
-
return ok(id, { prompts }, modern);
|
|
18447
|
+
return ok(id, cacheable({ prompts }), modern);
|
|
18433
18448
|
}
|
|
18434
18449
|
function getPrompt(id, modern, params) {
|
|
18435
18450
|
const name = params?.name;
|
|
@@ -18498,7 +18513,7 @@ function createMcpServer(options) {
|
|
|
18498
18513
|
case METHOD3.resourcesRead:
|
|
18499
18514
|
return readResource(id, modern, params);
|
|
18500
18515
|
case METHOD3.resourceTemplatesList:
|
|
18501
|
-
return ok(id, { resourceTemplates: options.resources.templates() }, modern);
|
|
18516
|
+
return ok(id, cacheable({ resourceTemplates: options.resources.templates() }), modern);
|
|
18502
18517
|
case METHOD3.promptsList:
|
|
18503
18518
|
return listPrompts(id, modern);
|
|
18504
18519
|
case METHOD3.promptsGet:
|
|
@@ -18804,18 +18819,218 @@ async function runStdioServer(options) {
|
|
|
18804
18819
|
}
|
|
18805
18820
|
|
|
18806
18821
|
// src/auth.ts
|
|
18807
|
-
function parseBearerToken(
|
|
18808
|
-
if (typeof
|
|
18822
|
+
function parseBearerToken(header2) {
|
|
18823
|
+
if (typeof header2 !== "string") return null;
|
|
18809
18824
|
const scheme = "bearer";
|
|
18810
|
-
if (
|
|
18811
|
-
if (
|
|
18825
|
+
if (header2.length <= scheme.length) return null;
|
|
18826
|
+
if (header2.slice(0, scheme.length).toLowerCase() !== scheme) return null;
|
|
18812
18827
|
let index = scheme.length;
|
|
18813
|
-
if (
|
|
18814
|
-
while (index <
|
|
18815
|
-
const token =
|
|
18828
|
+
if (header2[index] !== " " && header2[index] !== " ") return null;
|
|
18829
|
+
while (index < header2.length && (header2[index] === " " || header2[index] === " ")) index += 1;
|
|
18830
|
+
const token = header2.slice(index).trim();
|
|
18816
18831
|
return token.length > 0 ? token : null;
|
|
18817
18832
|
}
|
|
18818
18833
|
|
|
18834
|
+
// src/mcp/http-headers.ts
|
|
18835
|
+
var PROTOCOL_HEADER = "mcp-protocol-version";
|
|
18836
|
+
var METHOD_HEADER = "mcp-method";
|
|
18837
|
+
var NAME_HEADER = "mcp-name";
|
|
18838
|
+
var BASE64_PREFIX = "=?base64?";
|
|
18839
|
+
var BASE64_SUFFIX = "?=";
|
|
18840
|
+
var NAMED_METHODS = /* @__PURE__ */ new Set(["tools/call", "resources/read", "prompts/get"]);
|
|
18841
|
+
function requestId(message) {
|
|
18842
|
+
const raw = message.id;
|
|
18843
|
+
return typeof raw === "string" || typeof raw === "number" ? raw : null;
|
|
18844
|
+
}
|
|
18845
|
+
function header(request, name) {
|
|
18846
|
+
const value = request.headers[name];
|
|
18847
|
+
return typeof value === "string" ? value : null;
|
|
18848
|
+
}
|
|
18849
|
+
function isSafeHeaderValue(value) {
|
|
18850
|
+
return /^[\x20-\x7e\t]+$/.test(value);
|
|
18851
|
+
}
|
|
18852
|
+
function decodeMcpHeaderValue(value) {
|
|
18853
|
+
if (!value.startsWith(BASE64_PREFIX)) {
|
|
18854
|
+
return isSafeHeaderValue(value) ? value : null;
|
|
18855
|
+
}
|
|
18856
|
+
if (!value.endsWith(BASE64_SUFFIX)) return null;
|
|
18857
|
+
const encoded = value.slice(BASE64_PREFIX.length, -BASE64_SUFFIX.length);
|
|
18858
|
+
if (encoded.length === 0 || encoded.length % 4 !== 0) return null;
|
|
18859
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(encoded)) return null;
|
|
18860
|
+
const decoded = Buffer.from(encoded, "base64").toString("utf8");
|
|
18861
|
+
if (Buffer.from(decoded, "utf8").toString("base64") !== encoded) return null;
|
|
18862
|
+
return decoded;
|
|
18863
|
+
}
|
|
18864
|
+
function isModernHttpMessage(request, message) {
|
|
18865
|
+
if (Array.isArray(message)) {
|
|
18866
|
+
return message.some((item) => isModernHttpMessage(request, item));
|
|
18867
|
+
}
|
|
18868
|
+
if (!isJsonObject(message)) return false;
|
|
18869
|
+
if (message.method === "server/discover") return true;
|
|
18870
|
+
const params = isJsonObject(message.params) ? message.params : void 0;
|
|
18871
|
+
const meta = isJsonObject(params?._meta) ? params._meta : void 0;
|
|
18872
|
+
if (meta !== void 0 && (META_KEYS.protocolVersion in meta || META_KEYS.clientCapabilities in meta)) {
|
|
18873
|
+
return true;
|
|
18874
|
+
}
|
|
18875
|
+
return header(request, METHOD_HEADER) !== null || header(request, NAME_HEADER) !== null;
|
|
18876
|
+
}
|
|
18877
|
+
function refuse(id, code, message, data) {
|
|
18878
|
+
return errorResponse(id, code, message, data);
|
|
18879
|
+
}
|
|
18880
|
+
function validateModernHttpHeaders(request, message) {
|
|
18881
|
+
if (!isModernHttpMessage(request, message)) return { modern: false };
|
|
18882
|
+
if (Array.isArray(message)) {
|
|
18883
|
+
return {
|
|
18884
|
+
modern: true,
|
|
18885
|
+
error: refuse(null, ERROR_CODES.invalidRequest, "Batch requests are not supported.")
|
|
18886
|
+
};
|
|
18887
|
+
}
|
|
18888
|
+
if (!isJsonObject(message)) {
|
|
18889
|
+
return {
|
|
18890
|
+
modern: true,
|
|
18891
|
+
error: refuse(null, ERROR_CODES.invalidRequest, "Message is not a JSON object.")
|
|
18892
|
+
};
|
|
18893
|
+
}
|
|
18894
|
+
const id = requestId(message);
|
|
18895
|
+
const method = message.method;
|
|
18896
|
+
const params = isJsonObject(message.params) ? message.params : void 0;
|
|
18897
|
+
if (typeof method !== "string" || method.length === 0) {
|
|
18898
|
+
return {
|
|
18899
|
+
modern: true,
|
|
18900
|
+
error: refuse(id, ERROR_CODES.invalidRequest, 'Message must carry a "method" string.')
|
|
18901
|
+
};
|
|
18902
|
+
}
|
|
18903
|
+
const versionHeader = header(request, PROTOCOL_HEADER);
|
|
18904
|
+
if (versionHeader === null) {
|
|
18905
|
+
return {
|
|
18906
|
+
modern: true,
|
|
18907
|
+
error: refuse(
|
|
18908
|
+
id,
|
|
18909
|
+
ERROR_CODES.headerMismatch,
|
|
18910
|
+
`Header mismatch: ${PROTOCOL_HEADER} is required for a modern request.`
|
|
18911
|
+
)
|
|
18912
|
+
};
|
|
18913
|
+
}
|
|
18914
|
+
if (!isSafeHeaderValue(versionHeader)) {
|
|
18915
|
+
return {
|
|
18916
|
+
modern: true,
|
|
18917
|
+
error: refuse(
|
|
18918
|
+
id,
|
|
18919
|
+
ERROR_CODES.headerMismatch,
|
|
18920
|
+
`Header mismatch: ${PROTOCOL_HEADER} contains invalid characters.`
|
|
18921
|
+
)
|
|
18922
|
+
};
|
|
18923
|
+
}
|
|
18924
|
+
const meta = inspectModernMeta(params);
|
|
18925
|
+
if (meta.kind !== "present") {
|
|
18926
|
+
const missing = meta.kind === "incomplete" ? meta.missing : META_KEYS.protocolVersion;
|
|
18927
|
+
return {
|
|
18928
|
+
modern: true,
|
|
18929
|
+
error: refuse(
|
|
18930
|
+
id,
|
|
18931
|
+
ERROR_CODES.invalidParams,
|
|
18932
|
+
`The request _meta is missing the required key "${missing}".`
|
|
18933
|
+
)
|
|
18934
|
+
};
|
|
18935
|
+
}
|
|
18936
|
+
if (versionHeader !== meta.meta.version) {
|
|
18937
|
+
return {
|
|
18938
|
+
modern: true,
|
|
18939
|
+
error: refuse(
|
|
18940
|
+
id,
|
|
18941
|
+
ERROR_CODES.headerMismatch,
|
|
18942
|
+
`Header mismatch: ${PROTOCOL_HEADER} "${versionHeader}" does not match body value "${meta.meta.version}".`
|
|
18943
|
+
)
|
|
18944
|
+
};
|
|
18945
|
+
}
|
|
18946
|
+
const methodHeader = header(request, METHOD_HEADER);
|
|
18947
|
+
if (methodHeader === null) {
|
|
18948
|
+
return {
|
|
18949
|
+
modern: true,
|
|
18950
|
+
error: refuse(
|
|
18951
|
+
id,
|
|
18952
|
+
ERROR_CODES.headerMismatch,
|
|
18953
|
+
`Header mismatch: ${METHOD_HEADER} is required for a modern request.`
|
|
18954
|
+
)
|
|
18955
|
+
};
|
|
18956
|
+
}
|
|
18957
|
+
if (!isSafeHeaderValue(methodHeader) || methodHeader !== method) {
|
|
18958
|
+
return {
|
|
18959
|
+
modern: true,
|
|
18960
|
+
error: refuse(
|
|
18961
|
+
id,
|
|
18962
|
+
ERROR_CODES.headerMismatch,
|
|
18963
|
+
`Header mismatch: ${METHOD_HEADER} value "${methodHeader}" does not match body value "${method}".`
|
|
18964
|
+
)
|
|
18965
|
+
};
|
|
18966
|
+
}
|
|
18967
|
+
if (NAMED_METHODS.has(method)) {
|
|
18968
|
+
const nameHeader = header(request, NAME_HEADER);
|
|
18969
|
+
if (nameHeader === null) {
|
|
18970
|
+
return {
|
|
18971
|
+
modern: true,
|
|
18972
|
+
error: refuse(
|
|
18973
|
+
id,
|
|
18974
|
+
ERROR_CODES.headerMismatch,
|
|
18975
|
+
`Header mismatch: ${NAME_HEADER} is required for ${method}.`
|
|
18976
|
+
)
|
|
18977
|
+
};
|
|
18978
|
+
}
|
|
18979
|
+
const decoded = decodeMcpHeaderValue(nameHeader);
|
|
18980
|
+
if (decoded === null) {
|
|
18981
|
+
return {
|
|
18982
|
+
modern: true,
|
|
18983
|
+
error: refuse(
|
|
18984
|
+
id,
|
|
18985
|
+
ERROR_CODES.headerMismatch,
|
|
18986
|
+
`Header mismatch: ${NAME_HEADER} contains an invalid value.`
|
|
18987
|
+
)
|
|
18988
|
+
};
|
|
18989
|
+
}
|
|
18990
|
+
const bodyValue = method === "resources/read" ? params?.uri : params?.name;
|
|
18991
|
+
if (typeof bodyValue !== "string") {
|
|
18992
|
+
return {
|
|
18993
|
+
modern: true,
|
|
18994
|
+
error: refuse(
|
|
18995
|
+
id,
|
|
18996
|
+
ERROR_CODES.invalidParams,
|
|
18997
|
+
`${method} requires a "${method === "resources/read" ? "uri" : "name"}" string.`
|
|
18998
|
+
)
|
|
18999
|
+
};
|
|
19000
|
+
}
|
|
19001
|
+
if (decoded !== bodyValue) {
|
|
19002
|
+
return {
|
|
19003
|
+
modern: true,
|
|
19004
|
+
error: refuse(
|
|
19005
|
+
id,
|
|
19006
|
+
ERROR_CODES.headerMismatch,
|
|
19007
|
+
`Header mismatch: ${NAME_HEADER} value "${decoded}" does not match body value "${bodyValue}".`
|
|
19008
|
+
)
|
|
19009
|
+
};
|
|
19010
|
+
}
|
|
19011
|
+
}
|
|
19012
|
+
return { modern: true };
|
|
19013
|
+
}
|
|
19014
|
+
function modernHttpStatus(response) {
|
|
19015
|
+
if (!("error" in response)) return 200;
|
|
19016
|
+
switch (response.error.code) {
|
|
19017
|
+
case ERROR_CODES.headerMismatch:
|
|
19018
|
+
case ERROR_CODES.unsupportedProtocolVersion:
|
|
19019
|
+
case ERROR_CODES.invalidParams:
|
|
19020
|
+
case ERROR_CODES.invalidRequest:
|
|
19021
|
+
case ERROR_CODES.parseError:
|
|
19022
|
+
return 400;
|
|
19023
|
+
case ERROR_CODES.methodNotFound:
|
|
19024
|
+
return 404;
|
|
19025
|
+
case ERROR_CODES.internalError:
|
|
19026
|
+
return 500;
|
|
19027
|
+
case ERROR_CODES.overloaded:
|
|
19028
|
+
return 503;
|
|
19029
|
+
default:
|
|
19030
|
+
return 200;
|
|
19031
|
+
}
|
|
19032
|
+
}
|
|
19033
|
+
|
|
18819
19034
|
// src/mcp/http.ts
|
|
18820
19035
|
var DEFAULT_PORT = 4789;
|
|
18821
19036
|
var DEFAULT_MAX_BODY = 2 * 1024 * 1024;
|
|
@@ -18846,8 +19061,8 @@ function timingSafeEqual2(left, right) {
|
|
|
18846
19061
|
return crypto__namespace.timingSafeEqual(a, b);
|
|
18847
19062
|
}
|
|
18848
19063
|
function sessionHeader(request) {
|
|
18849
|
-
const
|
|
18850
|
-
return typeof
|
|
19064
|
+
const header2 = request.headers["mcp-session-id"];
|
|
19065
|
+
return typeof header2 === "string" ? header2.trim() : "";
|
|
18851
19066
|
}
|
|
18852
19067
|
function isObject(value) {
|
|
18853
19068
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -18858,12 +19073,6 @@ function isToolCall(message) {
|
|
|
18858
19073
|
function methodOf(message) {
|
|
18859
19074
|
return isObject(message) && typeof message.method === "string" ? message.method : null;
|
|
18860
19075
|
}
|
|
18861
|
-
function hasModernMeta(message) {
|
|
18862
|
-
const messages = Array.isArray(message) ? message : [message];
|
|
18863
|
-
return messages.some(
|
|
18864
|
-
(item) => isJsonObject(item) && isJsonObject(item.params) && inspectModernMeta(item.params).kind === "present"
|
|
18865
|
-
);
|
|
18866
|
-
}
|
|
18867
19076
|
function createMcpHttpHandler(options) {
|
|
18868
19077
|
const log = options.log ?? ((line) => process.stderr.write(line + "\n"));
|
|
18869
19078
|
const token = options.token;
|
|
@@ -18989,7 +19198,7 @@ function createMcpHttpHandler(options) {
|
|
|
18989
19198
|
return {
|
|
18990
19199
|
"access-control-allow-origin": allowed,
|
|
18991
19200
|
vary: "origin",
|
|
18992
|
-
"access-control-allow-headers": "authorization, content-type, mcp-protocol-version, mcp-session-id",
|
|
19201
|
+
"access-control-allow-headers": "authorization, content-type, mcp-protocol-version, mcp-session-id, mcp-method, mcp-name",
|
|
18993
19202
|
// Without this a browser can send the header but cannot read it: mcp-session-id is not a
|
|
18994
19203
|
// CORS-safelisted response header, so every cross-origin client silently lost its session.
|
|
18995
19204
|
"access-control-expose-headers": "mcp-session-id",
|
|
@@ -19197,6 +19406,12 @@ function createMcpHttpHandler(options) {
|
|
|
19197
19406
|
send(response, 400, { error: "JSON-RPC batch is limited to 100 messages" }, cors);
|
|
19198
19407
|
return;
|
|
19199
19408
|
}
|
|
19409
|
+
const headers = validateModernHttpHeaders(request, message);
|
|
19410
|
+
if (headers.error !== void 0) {
|
|
19411
|
+
send(response, 400, headers.error, cors);
|
|
19412
|
+
return;
|
|
19413
|
+
}
|
|
19414
|
+
const modern = headers.modern;
|
|
19200
19415
|
if (batch.length > 1 && rateLimited(request, batch.length - 1)) {
|
|
19201
19416
|
tooMany(response, cors);
|
|
19202
19417
|
return;
|
|
@@ -19215,6 +19430,8 @@ function createMcpHttpHandler(options) {
|
|
|
19215
19430
|
rememberAnonymous(anonymousKey(request), server);
|
|
19216
19431
|
responseSession = newSessionId();
|
|
19217
19432
|
rememberSession(responseSession, server, Date.now());
|
|
19433
|
+
} else if (modern) {
|
|
19434
|
+
server = createMcp();
|
|
19218
19435
|
} else if (supplied !== "") {
|
|
19219
19436
|
const now = Date.now();
|
|
19220
19437
|
pruneSessions(now);
|
|
@@ -19226,8 +19443,6 @@ function createMcpHttpHandler(options) {
|
|
|
19226
19443
|
existing.lastSeen = now;
|
|
19227
19444
|
server = existing.server;
|
|
19228
19445
|
responseSession = supplied;
|
|
19229
|
-
} else if (hasModernMeta(message)) {
|
|
19230
|
-
server = createMcp();
|
|
19231
19446
|
} else {
|
|
19232
19447
|
server = fallbackServer(request);
|
|
19233
19448
|
}
|
|
@@ -19251,7 +19466,8 @@ function createMcpHttpHandler(options) {
|
|
|
19251
19466
|
send(response, 202, "", sessionHeaders);
|
|
19252
19467
|
return;
|
|
19253
19468
|
}
|
|
19254
|
-
|
|
19469
|
+
const status = modern ? modernHttpStatus(answers[0]) : 200;
|
|
19470
|
+
send(response, status, Array.isArray(message) ? answers : answers[0], sessionHeaders);
|
|
19255
19471
|
})().catch((error) => {
|
|
19256
19472
|
log("mcp/http: " + error.message);
|
|
19257
19473
|
send(response, 500, { jsonrpc: "2.0", id: null, error: { code: -32603, message: "Internal error" } }, cors);
|
|
@@ -19383,7 +19599,7 @@ async function startHttpTransport(options) {
|
|
|
19383
19599
|
if (allowed !== null) {
|
|
19384
19600
|
cors["access-control-allow-origin"] = allowed;
|
|
19385
19601
|
cors.vary = "origin";
|
|
19386
|
-
cors["access-control-allow-headers"] = "authorization, content-type, mcp-protocol-version, mcp-session-id";
|
|
19602
|
+
cors["access-control-allow-headers"] = "authorization, content-type, mcp-protocol-version, mcp-session-id, mcp-method, mcp-name";
|
|
19387
19603
|
cors["access-control-expose-headers"] = "mcp-session-id";
|
|
19388
19604
|
cors["access-control-allow-methods"] = "POST, GET, OPTIONS, DELETE";
|
|
19389
19605
|
cors["access-control-max-age"] = "600";
|
|
@@ -21434,13 +21650,13 @@ function auditSnapshot(options) {
|
|
|
21434
21650
|
const text2 = partTexts.get(part.filename);
|
|
21435
21651
|
const sections = partSections.get(part.filename);
|
|
21436
21652
|
if (text2 === void 0 || sections === void 0) continue;
|
|
21437
|
-
const
|
|
21438
|
-
if (
|
|
21439
|
-
if (Number(
|
|
21440
|
-
structureProblems.push(part.filename + " says part " +
|
|
21653
|
+
const header2 = /^# Codebase Snapshot Part (\d+) of (\d+)$/m.exec(text2);
|
|
21654
|
+
if (header2 !== null) {
|
|
21655
|
+
if (Number(header2[1]) !== part.index) {
|
|
21656
|
+
structureProblems.push(part.filename + " says part " + header2[1] + ", the manifest says " + part.index);
|
|
21441
21657
|
}
|
|
21442
|
-
if (Number(
|
|
21443
|
-
structureProblems.push(part.filename + " says " +
|
|
21658
|
+
if (Number(header2[2]) !== manifest.parts.length) {
|
|
21659
|
+
structureProblems.push(part.filename + " says " + header2[2] + " parts, the manifest holds " + manifest.parts.length);
|
|
21444
21660
|
}
|
|
21445
21661
|
}
|
|
21446
21662
|
const filesLine = /^- Files: (\d+)$/m.exec(text2);
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './chunk-WMEZFLUT.js';
|
|
2
|
-
import { shouldCheck, checkForUpdate, GENERATOR_VERSION, cacheFilePath, formatUpdateNotice, installKind, buildAgentContract, startWebServer, startHttpTransport, buildTools, runStdioServer, parseRemoteSource, assertPublicHost, cloneRepository, makeCloneDirectory, loadConfigFileDetailed, resolveConfig, validateSnapshot, readConfinedText, auditSnapshot, describeManifestShapeProblem, explainPath, compareManifests, loadManifest, renderDiffText, generateSnapshot, getGitInfo, loadSigningKey, SIGNATURE_FILE, formatNumber, isDiscoveryMode, ARTIFACT_NAMES, COMMAND_OPTION_SCOPE, commandsForOption, getPreset, unknownPresetMessage, GENERATOR_NAME, runInit, installPreCommitHook, PromptCancelled, SKILL_NAME, renderSkill, resolveLatest, isNewer, updateCommand, findConfigFile, planFirstRun, isEffectivelyEmpty, isInteractive, defaultIO, hasPriorSnapshot, DEFAULT_ANSWERS, firstRunMessage, stripJsonComments, parseByteSize, gitignorePath, appendGitignoreEntries, escapeControls, runWithStdoutCapture, MIN_MAX_PART_TOKENS, MIN_MAX_PART_BYTES, renderContractText, renderExplainText } from './chunk-
|
|
3
|
-
export { buildAgentContract } from './chunk-
|
|
2
|
+
import { shouldCheck, checkForUpdate, GENERATOR_VERSION, cacheFilePath, formatUpdateNotice, installKind, buildAgentContract, startWebServer, startHttpTransport, buildTools, runStdioServer, parseRemoteSource, assertPublicHost, cloneRepository, makeCloneDirectory, loadConfigFileDetailed, resolveConfig, validateSnapshot, readConfinedText, auditSnapshot, describeManifestShapeProblem, explainPath, compareManifests, loadManifest, renderDiffText, generateSnapshot, getGitInfo, loadSigningKey, SIGNATURE_FILE, formatNumber, isDiscoveryMode, ARTIFACT_NAMES, COMMAND_OPTION_SCOPE, commandsForOption, getPreset, unknownPresetMessage, GENERATOR_NAME, runInit, installPreCommitHook, PromptCancelled, SKILL_NAME, renderSkill, resolveLatest, isNewer, updateCommand, findConfigFile, planFirstRun, isEffectivelyEmpty, isInteractive, defaultIO, hasPriorSnapshot, DEFAULT_ANSWERS, firstRunMessage, stripJsonComments, parseByteSize, gitignorePath, appendGitignoreEntries, escapeControls, runWithStdoutCapture, MIN_MAX_PART_TOKENS, MIN_MAX_PART_BYTES, renderContractText, renderExplainText } from './chunk-GNVRD7XS.js';
|
|
3
|
+
export { buildAgentContract } from './chunk-GNVRD7XS.js';
|
|
4
4
|
import { spawnSync } from 'child_process';
|
|
5
5
|
import * as fs2 from 'fs';
|
|
6
6
|
import * as path2 from 'path';
|