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/mcp.cjs
CHANGED
|
@@ -64,13 +64,22 @@ var ERROR_CODES = {
|
|
|
64
64
|
*/
|
|
65
65
|
resourceTooLarge: -32e3,
|
|
66
66
|
/**
|
|
67
|
-
* A known resource that this snapshot does not contain.
|
|
67
|
+
* A known resource that this snapshot does not contain, under a legacy revision.
|
|
68
68
|
*
|
|
69
|
-
* `-32002`
|
|
70
|
-
*
|
|
71
|
-
*
|
|
69
|
+
* `-32002` was the resource-not-found code through protocol revision `2025-11-25`. The
|
|
70
|
+
* `2026-07-28` revision assigns missing resources to `-32602` and says clients SHOULD still
|
|
71
|
+
* accept `-32002` from older servers. The dispatcher therefore chooses by era: `-32602` for
|
|
72
|
+
* modern requests and this code for legacy ones. Answering `-32602` for `snapshot://prompt`
|
|
73
|
+
* in a snapshot generated with `--skip-artifacts prompt` would tell a legacy client its URI
|
|
74
|
+
* was wrong when the artifact had simply been left out.
|
|
72
75
|
*/
|
|
73
76
|
resourceNotFound: -32002,
|
|
77
|
+
/**
|
|
78
|
+
* Streamable HTTP headers that are missing, malformed or disagree with the request body.
|
|
79
|
+
*
|
|
80
|
+
* Protocol revision `2026-07-28` reserves `-32020` for this. The HTTP status is `400`.
|
|
81
|
+
*/
|
|
82
|
+
headerMismatch: -32020,
|
|
74
83
|
/**
|
|
75
84
|
* The server is at its concurrency limit.
|
|
76
85
|
*
|
|
@@ -1961,7 +1970,7 @@ function readConfinedText(baseDir, relativePath, maxBytes) {
|
|
|
1961
1970
|
|
|
1962
1971
|
// src/version.ts
|
|
1963
1972
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
1964
|
-
var GENERATOR_VERSION = "0.20.
|
|
1973
|
+
var GENERATOR_VERSION = "0.20.13";
|
|
1965
1974
|
var SCHEMA_VERSION = "3.0.0";
|
|
1966
1975
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
1967
1976
|
function isOurGeneratorName(name) {
|
|
@@ -7623,7 +7632,7 @@ var readTool = {
|
|
|
7623
7632
|
}
|
|
7624
7633
|
const returnedLines = body.length === 0 ? truncatedByBytes && !clippedInsideLine && window.fromLine <= window.totalLines ? 1 : 0 : body.split("\n").length;
|
|
7625
7634
|
const moreRemain = !clippedInsideLine && !window.pastEnd && (window.truncated || truncatedByBytes);
|
|
7626
|
-
const
|
|
7635
|
+
const header2 = [
|
|
7627
7636
|
`${entry.relativePath} \u2014 ${entry.part}, ${entry.layer}/${entry.kind}, ${entry.language}`,
|
|
7628
7637
|
// The line range is the answer to "where am I in this file", and it is computed from the
|
|
7629
7638
|
// body the window was taken from, so it is just as meaningful for a preview as for a full
|
|
@@ -7638,7 +7647,7 @@ var readTool = {
|
|
|
7638
7647
|
] : [],
|
|
7639
7648
|
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}.`
|
|
7640
7649
|
];
|
|
7641
|
-
const lines = [...
|
|
7650
|
+
const lines = [...header2, "", body];
|
|
7642
7651
|
if (moreRemain) {
|
|
7643
7652
|
const next = window.fromLine + returnedLines;
|
|
7644
7653
|
lines.push("", `Truncated. Call snapshot_read with fromLine=${next} for the rest.`);
|
|
@@ -7930,18 +7939,218 @@ async function runStdioServer(options) {
|
|
|
7930
7939
|
}
|
|
7931
7940
|
|
|
7932
7941
|
// src/auth.ts
|
|
7933
|
-
function parseBearerToken(
|
|
7934
|
-
if (typeof
|
|
7942
|
+
function parseBearerToken(header2) {
|
|
7943
|
+
if (typeof header2 !== "string") return null;
|
|
7935
7944
|
const scheme = "bearer";
|
|
7936
|
-
if (
|
|
7937
|
-
if (
|
|
7945
|
+
if (header2.length <= scheme.length) return null;
|
|
7946
|
+
if (header2.slice(0, scheme.length).toLowerCase() !== scheme) return null;
|
|
7938
7947
|
let index = scheme.length;
|
|
7939
|
-
if (
|
|
7940
|
-
while (index <
|
|
7941
|
-
const token =
|
|
7948
|
+
if (header2[index] !== " " && header2[index] !== " ") return null;
|
|
7949
|
+
while (index < header2.length && (header2[index] === " " || header2[index] === " ")) index += 1;
|
|
7950
|
+
const token = header2.slice(index).trim();
|
|
7942
7951
|
return token.length > 0 ? token : null;
|
|
7943
7952
|
}
|
|
7944
7953
|
|
|
7954
|
+
// src/mcp/http-headers.ts
|
|
7955
|
+
var PROTOCOL_HEADER = "mcp-protocol-version";
|
|
7956
|
+
var METHOD_HEADER = "mcp-method";
|
|
7957
|
+
var NAME_HEADER = "mcp-name";
|
|
7958
|
+
var BASE64_PREFIX = "=?base64?";
|
|
7959
|
+
var BASE64_SUFFIX = "?=";
|
|
7960
|
+
var NAMED_METHODS = /* @__PURE__ */ new Set(["tools/call", "resources/read", "prompts/get"]);
|
|
7961
|
+
function requestId(message) {
|
|
7962
|
+
const raw = message.id;
|
|
7963
|
+
return typeof raw === "string" || typeof raw === "number" ? raw : null;
|
|
7964
|
+
}
|
|
7965
|
+
function header(request, name) {
|
|
7966
|
+
const value = request.headers[name];
|
|
7967
|
+
return typeof value === "string" ? value : null;
|
|
7968
|
+
}
|
|
7969
|
+
function isSafeHeaderValue(value) {
|
|
7970
|
+
return /^[\x20-\x7e\t]+$/.test(value);
|
|
7971
|
+
}
|
|
7972
|
+
function decodeMcpHeaderValue(value) {
|
|
7973
|
+
if (!value.startsWith(BASE64_PREFIX)) {
|
|
7974
|
+
return isSafeHeaderValue(value) ? value : null;
|
|
7975
|
+
}
|
|
7976
|
+
if (!value.endsWith(BASE64_SUFFIX)) return null;
|
|
7977
|
+
const encoded = value.slice(BASE64_PREFIX.length, -BASE64_SUFFIX.length);
|
|
7978
|
+
if (encoded.length === 0 || encoded.length % 4 !== 0) return null;
|
|
7979
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(encoded)) return null;
|
|
7980
|
+
const decoded = Buffer.from(encoded, "base64").toString("utf8");
|
|
7981
|
+
if (Buffer.from(decoded, "utf8").toString("base64") !== encoded) return null;
|
|
7982
|
+
return decoded;
|
|
7983
|
+
}
|
|
7984
|
+
function isModernHttpMessage(request, message) {
|
|
7985
|
+
if (Array.isArray(message)) {
|
|
7986
|
+
return message.some((item) => isModernHttpMessage(request, item));
|
|
7987
|
+
}
|
|
7988
|
+
if (!isJsonObject(message)) return false;
|
|
7989
|
+
if (message.method === "server/discover") return true;
|
|
7990
|
+
const params = isJsonObject(message.params) ? message.params : void 0;
|
|
7991
|
+
const meta = isJsonObject(params?._meta) ? params._meta : void 0;
|
|
7992
|
+
if (meta !== void 0 && (META_KEYS.protocolVersion in meta || META_KEYS.clientCapabilities in meta)) {
|
|
7993
|
+
return true;
|
|
7994
|
+
}
|
|
7995
|
+
return header(request, METHOD_HEADER) !== null || header(request, NAME_HEADER) !== null;
|
|
7996
|
+
}
|
|
7997
|
+
function refuse(id, code, message, data) {
|
|
7998
|
+
return errorResponse(id, code, message, data);
|
|
7999
|
+
}
|
|
8000
|
+
function validateModernHttpHeaders(request, message) {
|
|
8001
|
+
if (!isModernHttpMessage(request, message)) return { modern: false };
|
|
8002
|
+
if (Array.isArray(message)) {
|
|
8003
|
+
return {
|
|
8004
|
+
modern: true,
|
|
8005
|
+
error: refuse(null, ERROR_CODES.invalidRequest, "Batch requests are not supported.")
|
|
8006
|
+
};
|
|
8007
|
+
}
|
|
8008
|
+
if (!isJsonObject(message)) {
|
|
8009
|
+
return {
|
|
8010
|
+
modern: true,
|
|
8011
|
+
error: refuse(null, ERROR_CODES.invalidRequest, "Message is not a JSON object.")
|
|
8012
|
+
};
|
|
8013
|
+
}
|
|
8014
|
+
const id = requestId(message);
|
|
8015
|
+
const method = message.method;
|
|
8016
|
+
const params = isJsonObject(message.params) ? message.params : void 0;
|
|
8017
|
+
if (typeof method !== "string" || method.length === 0) {
|
|
8018
|
+
return {
|
|
8019
|
+
modern: true,
|
|
8020
|
+
error: refuse(id, ERROR_CODES.invalidRequest, 'Message must carry a "method" string.')
|
|
8021
|
+
};
|
|
8022
|
+
}
|
|
8023
|
+
const versionHeader = header(request, PROTOCOL_HEADER);
|
|
8024
|
+
if (versionHeader === null) {
|
|
8025
|
+
return {
|
|
8026
|
+
modern: true,
|
|
8027
|
+
error: refuse(
|
|
8028
|
+
id,
|
|
8029
|
+
ERROR_CODES.headerMismatch,
|
|
8030
|
+
`Header mismatch: ${PROTOCOL_HEADER} is required for a modern request.`
|
|
8031
|
+
)
|
|
8032
|
+
};
|
|
8033
|
+
}
|
|
8034
|
+
if (!isSafeHeaderValue(versionHeader)) {
|
|
8035
|
+
return {
|
|
8036
|
+
modern: true,
|
|
8037
|
+
error: refuse(
|
|
8038
|
+
id,
|
|
8039
|
+
ERROR_CODES.headerMismatch,
|
|
8040
|
+
`Header mismatch: ${PROTOCOL_HEADER} contains invalid characters.`
|
|
8041
|
+
)
|
|
8042
|
+
};
|
|
8043
|
+
}
|
|
8044
|
+
const meta = inspectModernMeta(params);
|
|
8045
|
+
if (meta.kind !== "present") {
|
|
8046
|
+
const missing = meta.kind === "incomplete" ? meta.missing : META_KEYS.protocolVersion;
|
|
8047
|
+
return {
|
|
8048
|
+
modern: true,
|
|
8049
|
+
error: refuse(
|
|
8050
|
+
id,
|
|
8051
|
+
ERROR_CODES.invalidParams,
|
|
8052
|
+
`The request _meta is missing the required key "${missing}".`
|
|
8053
|
+
)
|
|
8054
|
+
};
|
|
8055
|
+
}
|
|
8056
|
+
if (versionHeader !== meta.meta.version) {
|
|
8057
|
+
return {
|
|
8058
|
+
modern: true,
|
|
8059
|
+
error: refuse(
|
|
8060
|
+
id,
|
|
8061
|
+
ERROR_CODES.headerMismatch,
|
|
8062
|
+
`Header mismatch: ${PROTOCOL_HEADER} "${versionHeader}" does not match body value "${meta.meta.version}".`
|
|
8063
|
+
)
|
|
8064
|
+
};
|
|
8065
|
+
}
|
|
8066
|
+
const methodHeader = header(request, METHOD_HEADER);
|
|
8067
|
+
if (methodHeader === null) {
|
|
8068
|
+
return {
|
|
8069
|
+
modern: true,
|
|
8070
|
+
error: refuse(
|
|
8071
|
+
id,
|
|
8072
|
+
ERROR_CODES.headerMismatch,
|
|
8073
|
+
`Header mismatch: ${METHOD_HEADER} is required for a modern request.`
|
|
8074
|
+
)
|
|
8075
|
+
};
|
|
8076
|
+
}
|
|
8077
|
+
if (!isSafeHeaderValue(methodHeader) || methodHeader !== method) {
|
|
8078
|
+
return {
|
|
8079
|
+
modern: true,
|
|
8080
|
+
error: refuse(
|
|
8081
|
+
id,
|
|
8082
|
+
ERROR_CODES.headerMismatch,
|
|
8083
|
+
`Header mismatch: ${METHOD_HEADER} value "${methodHeader}" does not match body value "${method}".`
|
|
8084
|
+
)
|
|
8085
|
+
};
|
|
8086
|
+
}
|
|
8087
|
+
if (NAMED_METHODS.has(method)) {
|
|
8088
|
+
const nameHeader = header(request, NAME_HEADER);
|
|
8089
|
+
if (nameHeader === null) {
|
|
8090
|
+
return {
|
|
8091
|
+
modern: true,
|
|
8092
|
+
error: refuse(
|
|
8093
|
+
id,
|
|
8094
|
+
ERROR_CODES.headerMismatch,
|
|
8095
|
+
`Header mismatch: ${NAME_HEADER} is required for ${method}.`
|
|
8096
|
+
)
|
|
8097
|
+
};
|
|
8098
|
+
}
|
|
8099
|
+
const decoded = decodeMcpHeaderValue(nameHeader);
|
|
8100
|
+
if (decoded === null) {
|
|
8101
|
+
return {
|
|
8102
|
+
modern: true,
|
|
8103
|
+
error: refuse(
|
|
8104
|
+
id,
|
|
8105
|
+
ERROR_CODES.headerMismatch,
|
|
8106
|
+
`Header mismatch: ${NAME_HEADER} contains an invalid value.`
|
|
8107
|
+
)
|
|
8108
|
+
};
|
|
8109
|
+
}
|
|
8110
|
+
const bodyValue = method === "resources/read" ? params?.uri : params?.name;
|
|
8111
|
+
if (typeof bodyValue !== "string") {
|
|
8112
|
+
return {
|
|
8113
|
+
modern: true,
|
|
8114
|
+
error: refuse(
|
|
8115
|
+
id,
|
|
8116
|
+
ERROR_CODES.invalidParams,
|
|
8117
|
+
`${method} requires a "${method === "resources/read" ? "uri" : "name"}" string.`
|
|
8118
|
+
)
|
|
8119
|
+
};
|
|
8120
|
+
}
|
|
8121
|
+
if (decoded !== bodyValue) {
|
|
8122
|
+
return {
|
|
8123
|
+
modern: true,
|
|
8124
|
+
error: refuse(
|
|
8125
|
+
id,
|
|
8126
|
+
ERROR_CODES.headerMismatch,
|
|
8127
|
+
`Header mismatch: ${NAME_HEADER} value "${decoded}" does not match body value "${bodyValue}".`
|
|
8128
|
+
)
|
|
8129
|
+
};
|
|
8130
|
+
}
|
|
8131
|
+
}
|
|
8132
|
+
return { modern: true };
|
|
8133
|
+
}
|
|
8134
|
+
function modernHttpStatus(response) {
|
|
8135
|
+
if (!("error" in response)) return 200;
|
|
8136
|
+
switch (response.error.code) {
|
|
8137
|
+
case ERROR_CODES.headerMismatch:
|
|
8138
|
+
case ERROR_CODES.unsupportedProtocolVersion:
|
|
8139
|
+
case ERROR_CODES.invalidParams:
|
|
8140
|
+
case ERROR_CODES.invalidRequest:
|
|
8141
|
+
case ERROR_CODES.parseError:
|
|
8142
|
+
return 400;
|
|
8143
|
+
case ERROR_CODES.methodNotFound:
|
|
8144
|
+
return 404;
|
|
8145
|
+
case ERROR_CODES.internalError:
|
|
8146
|
+
return 500;
|
|
8147
|
+
case ERROR_CODES.overloaded:
|
|
8148
|
+
return 503;
|
|
8149
|
+
default:
|
|
8150
|
+
return 200;
|
|
8151
|
+
}
|
|
8152
|
+
}
|
|
8153
|
+
|
|
7945
8154
|
// src/mcp/http.ts
|
|
7946
8155
|
var DEFAULT_PORT = 4789;
|
|
7947
8156
|
var DEFAULT_MAX_BODY = 2 * 1024 * 1024;
|
|
@@ -7972,8 +8181,8 @@ function timingSafeEqual2(left, right) {
|
|
|
7972
8181
|
return crypto3__namespace.timingSafeEqual(a, b);
|
|
7973
8182
|
}
|
|
7974
8183
|
function sessionHeader(request) {
|
|
7975
|
-
const
|
|
7976
|
-
return typeof
|
|
8184
|
+
const header2 = request.headers["mcp-session-id"];
|
|
8185
|
+
return typeof header2 === "string" ? header2.trim() : "";
|
|
7977
8186
|
}
|
|
7978
8187
|
function isObject(value) {
|
|
7979
8188
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
@@ -7984,12 +8193,6 @@ function isToolCall(message) {
|
|
|
7984
8193
|
function methodOf(message) {
|
|
7985
8194
|
return isObject(message) && typeof message.method === "string" ? message.method : null;
|
|
7986
8195
|
}
|
|
7987
|
-
function hasModernMeta(message) {
|
|
7988
|
-
const messages = Array.isArray(message) ? message : [message];
|
|
7989
|
-
return messages.some(
|
|
7990
|
-
(item) => isJsonObject(item) && isJsonObject(item.params) && inspectModernMeta(item.params).kind === "present"
|
|
7991
|
-
);
|
|
7992
|
-
}
|
|
7993
8196
|
function createMcpHttpHandler(options) {
|
|
7994
8197
|
const log = options.log ?? ((line) => process.stderr.write(line + "\n"));
|
|
7995
8198
|
const token = options.token;
|
|
@@ -8115,7 +8318,7 @@ function createMcpHttpHandler(options) {
|
|
|
8115
8318
|
return {
|
|
8116
8319
|
"access-control-allow-origin": allowed,
|
|
8117
8320
|
vary: "origin",
|
|
8118
|
-
"access-control-allow-headers": "authorization, content-type, mcp-protocol-version, mcp-session-id",
|
|
8321
|
+
"access-control-allow-headers": "authorization, content-type, mcp-protocol-version, mcp-session-id, mcp-method, mcp-name",
|
|
8119
8322
|
// Without this a browser can send the header but cannot read it: mcp-session-id is not a
|
|
8120
8323
|
// CORS-safelisted response header, so every cross-origin client silently lost its session.
|
|
8121
8324
|
"access-control-expose-headers": "mcp-session-id",
|
|
@@ -8323,6 +8526,12 @@ function createMcpHttpHandler(options) {
|
|
|
8323
8526
|
send(response, 400, { error: "JSON-RPC batch is limited to 100 messages" }, cors);
|
|
8324
8527
|
return;
|
|
8325
8528
|
}
|
|
8529
|
+
const headers = validateModernHttpHeaders(request, message);
|
|
8530
|
+
if (headers.error !== void 0) {
|
|
8531
|
+
send(response, 400, headers.error, cors);
|
|
8532
|
+
return;
|
|
8533
|
+
}
|
|
8534
|
+
const modern = headers.modern;
|
|
8326
8535
|
if (batch.length > 1 && rateLimited(request, batch.length - 1)) {
|
|
8327
8536
|
tooMany(response, cors);
|
|
8328
8537
|
return;
|
|
@@ -8341,6 +8550,8 @@ function createMcpHttpHandler(options) {
|
|
|
8341
8550
|
rememberAnonymous(anonymousKey(request), server);
|
|
8342
8551
|
responseSession = newSessionId();
|
|
8343
8552
|
rememberSession(responseSession, server, Date.now());
|
|
8553
|
+
} else if (modern) {
|
|
8554
|
+
server = createMcp();
|
|
8344
8555
|
} else if (supplied !== "") {
|
|
8345
8556
|
const now = Date.now();
|
|
8346
8557
|
pruneSessions(now);
|
|
@@ -8352,8 +8563,6 @@ function createMcpHttpHandler(options) {
|
|
|
8352
8563
|
existing.lastSeen = now;
|
|
8353
8564
|
server = existing.server;
|
|
8354
8565
|
responseSession = supplied;
|
|
8355
|
-
} else if (hasModernMeta(message)) {
|
|
8356
|
-
server = createMcp();
|
|
8357
8566
|
} else {
|
|
8358
8567
|
server = fallbackServer(request);
|
|
8359
8568
|
}
|
|
@@ -8377,7 +8586,8 @@ function createMcpHttpHandler(options) {
|
|
|
8377
8586
|
send(response, 202, "", sessionHeaders);
|
|
8378
8587
|
return;
|
|
8379
8588
|
}
|
|
8380
|
-
|
|
8589
|
+
const status = modern ? modernHttpStatus(answers[0]) : 200;
|
|
8590
|
+
send(response, status, Array.isArray(message) ? answers : answers[0], sessionHeaders);
|
|
8381
8591
|
})().catch((error) => {
|
|
8382
8592
|
log("mcp/http: " + error.message);
|
|
8383
8593
|
send(response, 500, { jsonrpc: "2.0", id: null, error: { code: -32603, message: "Internal error" } }, cors);
|
|
@@ -8509,7 +8719,7 @@ async function startHttpTransport(options) {
|
|
|
8509
8719
|
if (allowed !== null) {
|
|
8510
8720
|
cors["access-control-allow-origin"] = allowed;
|
|
8511
8721
|
cors.vary = "origin";
|
|
8512
|
-
cors["access-control-allow-headers"] = "authorization, content-type, mcp-protocol-version, mcp-session-id";
|
|
8722
|
+
cors["access-control-allow-headers"] = "authorization, content-type, mcp-protocol-version, mcp-session-id, mcp-method, mcp-name";
|
|
8513
8723
|
cors["access-control-expose-headers"] = "mcp-session-id";
|
|
8514
8724
|
cors["access-control-allow-methods"] = "POST, GET, OPTIONS, DELETE";
|
|
8515
8725
|
cors["access-control-max-age"] = "600";
|
|
@@ -10360,15 +10570,20 @@ function createMcpServer(options) {
|
|
|
10360
10570
|
websiteUrl: options.info.websiteUrl
|
|
10361
10571
|
});
|
|
10362
10572
|
const ok = (id, result, modern) => successResponse(id, result, modern, options.info);
|
|
10573
|
+
const cacheable = (result) => ({
|
|
10574
|
+
...result,
|
|
10575
|
+
cacheScope: "private",
|
|
10576
|
+
ttlMs: 0
|
|
10577
|
+
});
|
|
10363
10578
|
const cancellations = /* @__PURE__ */ new Map();
|
|
10364
10579
|
function handleNotification(method, params) {
|
|
10365
10580
|
if (method === METHOD.initialized && session.era === "legacy") session.ready = true;
|
|
10366
10581
|
if (method === "notifications/cancelled") {
|
|
10367
|
-
const
|
|
10368
|
-
if (typeof
|
|
10369
|
-
const cancel = cancellations.get(
|
|
10582
|
+
const requestId2 = params?.requestId;
|
|
10583
|
+
if (typeof requestId2 === "string" || typeof requestId2 === "number") {
|
|
10584
|
+
const cancel = cancellations.get(requestId2);
|
|
10370
10585
|
if (cancel !== void 0) {
|
|
10371
|
-
cancellations.delete(
|
|
10586
|
+
cancellations.delete(requestId2);
|
|
10372
10587
|
cancel();
|
|
10373
10588
|
}
|
|
10374
10589
|
}
|
|
@@ -10396,15 +10611,11 @@ function createMcpServer(options) {
|
|
|
10396
10611
|
function discover(id) {
|
|
10397
10612
|
return ok(
|
|
10398
10613
|
id,
|
|
10399
|
-
{
|
|
10614
|
+
cacheable({
|
|
10400
10615
|
supportedVersions: [...SUPPORTED_PROTOCOL_VERSIONS],
|
|
10401
10616
|
capabilities: capabilities(),
|
|
10402
|
-
instructions: options.instructions
|
|
10403
|
-
|
|
10404
|
-
// may be cached only by the client that asked, and not at all after this response.
|
|
10405
|
-
cacheScope: "private",
|
|
10406
|
-
ttlMs: 0
|
|
10407
|
-
},
|
|
10617
|
+
instructions: options.instructions
|
|
10618
|
+
}),
|
|
10408
10619
|
true
|
|
10409
10620
|
);
|
|
10410
10621
|
}
|
|
@@ -10418,7 +10629,7 @@ function createMcpServer(options) {
|
|
|
10418
10629
|
annotations: tool.annotations,
|
|
10419
10630
|
_meta: { "codebase-snapshot/cost": tool.cost }
|
|
10420
10631
|
}));
|
|
10421
|
-
return ok(id, { tools }, modern);
|
|
10632
|
+
return ok(id, cacheable({ tools }), modern);
|
|
10422
10633
|
}
|
|
10423
10634
|
async function callTool(id, modern, params) {
|
|
10424
10635
|
const name = params?.name;
|
|
@@ -10494,7 +10705,7 @@ function createMcpServer(options) {
|
|
|
10494
10705
|
}
|
|
10495
10706
|
async function listResources(id, modern) {
|
|
10496
10707
|
const resources = await options.resources.list(options.context);
|
|
10497
|
-
return ok(id, { resources }, modern);
|
|
10708
|
+
return ok(id, cacheable({ resources }), modern);
|
|
10498
10709
|
}
|
|
10499
10710
|
async function readResource(id, modern, params) {
|
|
10500
10711
|
const uri = params?.uri;
|
|
@@ -10506,7 +10717,12 @@ function createMcpServer(options) {
|
|
|
10506
10717
|
contents = await options.resources.read(uri, options.context);
|
|
10507
10718
|
} catch (error) {
|
|
10508
10719
|
if (error instanceof ResourceNotFoundError) {
|
|
10509
|
-
return errorResponse(
|
|
10720
|
+
return errorResponse(
|
|
10721
|
+
id,
|
|
10722
|
+
modern ? ERROR_CODES.invalidParams : ERROR_CODES.resourceNotFound,
|
|
10723
|
+
error.message,
|
|
10724
|
+
{ uri: error.uri }
|
|
10725
|
+
);
|
|
10510
10726
|
}
|
|
10511
10727
|
if (error instanceof ResourceTooLargeError) {
|
|
10512
10728
|
options.context.log(
|
|
@@ -10523,7 +10739,7 @@ function createMcpServer(options) {
|
|
|
10523
10739
|
if (!contents) {
|
|
10524
10740
|
return errorResponse(id, ERROR_CODES.invalidParams, `Unknown resource "${uri}".`);
|
|
10525
10741
|
}
|
|
10526
|
-
return ok(id, { contents: [contents] }, modern);
|
|
10742
|
+
return ok(id, cacheable({ contents: [contents] }), modern);
|
|
10527
10743
|
}
|
|
10528
10744
|
function listPrompts(id, modern) {
|
|
10529
10745
|
const prompts = options.prompts.map((prompt) => ({
|
|
@@ -10532,7 +10748,7 @@ function createMcpServer(options) {
|
|
|
10532
10748
|
description: prompt.description,
|
|
10533
10749
|
arguments: prompt.arguments
|
|
10534
10750
|
}));
|
|
10535
|
-
return ok(id, { prompts }, modern);
|
|
10751
|
+
return ok(id, cacheable({ prompts }), modern);
|
|
10536
10752
|
}
|
|
10537
10753
|
function getPrompt(id, modern, params) {
|
|
10538
10754
|
const name = params?.name;
|
|
@@ -10601,7 +10817,7 @@ function createMcpServer(options) {
|
|
|
10601
10817
|
case METHOD.resourcesRead:
|
|
10602
10818
|
return readResource(id, modern, params);
|
|
10603
10819
|
case METHOD.resourceTemplatesList:
|
|
10604
|
-
return ok(id, { resourceTemplates: options.resources.templates() }, modern);
|
|
10820
|
+
return ok(id, cacheable({ resourceTemplates: options.resources.templates() }), modern);
|
|
10605
10821
|
case METHOD.promptsList:
|
|
10606
10822
|
return listPrompts(id, modern);
|
|
10607
10823
|
case METHOD.promptsGet:
|
package/dist/mcp.d.cts
CHANGED
|
@@ -70,13 +70,22 @@ declare const ERROR_CODES: {
|
|
|
70
70
|
*/
|
|
71
71
|
readonly resourceTooLarge: -32000;
|
|
72
72
|
/**
|
|
73
|
-
* A known resource that this snapshot does not contain.
|
|
73
|
+
* A known resource that this snapshot does not contain, under a legacy revision.
|
|
74
74
|
*
|
|
75
|
-
* `-32002`
|
|
76
|
-
*
|
|
77
|
-
*
|
|
75
|
+
* `-32002` was the resource-not-found code through protocol revision `2025-11-25`. The
|
|
76
|
+
* `2026-07-28` revision assigns missing resources to `-32602` and says clients SHOULD still
|
|
77
|
+
* accept `-32002` from older servers. The dispatcher therefore chooses by era: `-32602` for
|
|
78
|
+
* modern requests and this code for legacy ones. Answering `-32602` for `snapshot://prompt`
|
|
79
|
+
* in a snapshot generated with `--skip-artifacts prompt` would tell a legacy client its URI
|
|
80
|
+
* was wrong when the artifact had simply been left out.
|
|
78
81
|
*/
|
|
79
82
|
readonly resourceNotFound: -32002;
|
|
83
|
+
/**
|
|
84
|
+
* Streamable HTTP headers that are missing, malformed or disagree with the request body.
|
|
85
|
+
*
|
|
86
|
+
* Protocol revision `2026-07-28` reserves `-32020` for this. The HTTP status is `400`.
|
|
87
|
+
*/
|
|
88
|
+
readonly headerMismatch: -32020;
|
|
80
89
|
/**
|
|
81
90
|
* The server is at its concurrency limit.
|
|
82
91
|
*
|
package/dist/mcp.d.ts
CHANGED
|
@@ -70,13 +70,22 @@ declare const ERROR_CODES: {
|
|
|
70
70
|
*/
|
|
71
71
|
readonly resourceTooLarge: -32000;
|
|
72
72
|
/**
|
|
73
|
-
* A known resource that this snapshot does not contain.
|
|
73
|
+
* A known resource that this snapshot does not contain, under a legacy revision.
|
|
74
74
|
*
|
|
75
|
-
* `-32002`
|
|
76
|
-
*
|
|
77
|
-
*
|
|
75
|
+
* `-32002` was the resource-not-found code through protocol revision `2025-11-25`. The
|
|
76
|
+
* `2026-07-28` revision assigns missing resources to `-32602` and says clients SHOULD still
|
|
77
|
+
* accept `-32002` from older servers. The dispatcher therefore chooses by era: `-32602` for
|
|
78
|
+
* modern requests and this code for legacy ones. Answering `-32602` for `snapshot://prompt`
|
|
79
|
+
* in a snapshot generated with `--skip-artifacts prompt` would tell a legacy client its URI
|
|
80
|
+
* was wrong when the artifact had simply been left out.
|
|
78
81
|
*/
|
|
79
82
|
readonly resourceNotFound: -32002;
|
|
83
|
+
/**
|
|
84
|
+
* Streamable HTTP headers that are missing, malformed or disagree with the request body.
|
|
85
|
+
*
|
|
86
|
+
* Protocol revision `2026-07-28` reserves `-32020` for this. The HTTP status is `400`.
|
|
87
|
+
*/
|
|
88
|
+
readonly headerMismatch: -32020;
|
|
80
89
|
/**
|
|
81
90
|
* The server is at its concurrency limit.
|
|
82
91
|
*
|
package/dist/mcp.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import './chunk-WMEZFLUT.js';
|
|
2
|
-
export { ERROR_CODES, LEGACY_PROTOCOL_VERSIONS, MAX_LINE_BYTES, METHOD, MODERN_PROTOCOL_VERSIONS, REPORT_RESOURCE_URIS, RESOURCE_TEMPLATE_URIS, SERVER_INSTRUCTIONS, STATIC_RESOURCE_URIS, SUPPORTED_PROTOCOL_VERSIONS, buildPrompts, buildResourceProvider, buildTools, classifyRequest, coerceNumericStrings, createLineReader, createMcpServer, createServer, createSession, createWriter, findSection, generateInWorker, generateToken, inspectModernMeta, isCommentStrippable, negotiateLegacyVersion, parsePartSections, runStdioServer, startHttpTransport, stripComments, validateArguments, windowText } from './chunk-
|
|
2
|
+
export { ERROR_CODES, LEGACY_PROTOCOL_VERSIONS, MAX_LINE_BYTES, METHOD, MODERN_PROTOCOL_VERSIONS, REPORT_RESOURCE_URIS, RESOURCE_TEMPLATE_URIS, SERVER_INSTRUCTIONS, STATIC_RESOURCE_URIS, SUPPORTED_PROTOCOL_VERSIONS, buildPrompts, buildResourceProvider, buildTools, classifyRequest, coerceNumericStrings, createLineReader, createMcpServer, createServer, createSession, createWriter, findSection, generateInWorker, generateToken, inspectModernMeta, isCommentStrippable, negotiateLegacyVersion, parsePartSections, runStdioServer, startHttpTransport, stripComments, validateArguments, windowText } from './chunk-GNVRD7XS.js';
|
package/docs/cli.md
CHANGED
|
@@ -98,7 +98,7 @@ Exit `0` when the snapshot passes its own integrity check, `1` when it does not.
|
|
|
98
98
|
|
|
99
99
|
```
|
|
100
100
|
πΈ Generating snapshot for: /path/to/repo
|
|
101
|
-
Branch: main (fallback) | Part budget: 300 KB | Generator: 0.20.
|
|
101
|
+
Branch: main (fallback) | Part budget: 300 KB | Generator: 0.20.13 (project dependency ^0.20.13)
|
|
102
102
|
|
|
103
103
|
β
Snapshot generated in 0.14s:
|
|
104
104
|
- Tracked files: 121 included of 128 paths found β 7 skipped (default-ignore 5, binary 1, sensitive-file 1); every one is listed in snapshot/reports/audit.md
|
|
@@ -224,7 +224,7 @@ The whole first run in one command, with defaults and no prompts. This is the sa
|
|
|
224
224
|
π Setup for: /path/to/repo
|
|
225
225
|
β
Created snapshot.config.json (preset: nextjs)
|
|
226
226
|
Added npm scripts: snapshot, snapshot:validate
|
|
227
|
-
Added devDependency: codebase-snapshot ^0.20.
|
|
227
|
+
Added devDependency: codebase-snapshot ^0.20.13
|
|
228
228
|
Added to .gitignore: /snapshot/, /snapshot.tmp/
|
|
229
229
|
β³ Installing dependenciesβ¦
|
|
230
230
|
β
Installed dependencies (npm install, 2.1s)
|
|
@@ -276,7 +276,7 @@ It also has three side effects on files you own, and it says so when it does the
|
|
|
276
276
|
```
|
|
277
277
|
β
Created snapshot.config.json (preset: node-lib)
|
|
278
278
|
Added npm scripts: snapshot, snapshot:validate
|
|
279
|
-
Added devDependency: codebase-snapshot ^0.20.
|
|
279
|
+
Added devDependency: codebase-snapshot ^0.20.13
|
|
280
280
|
Added to .gitignore: /snapshot/, /snapshot.tmp/
|
|
281
281
|
```
|
|
282
282
|
|
|
@@ -426,13 +426,12 @@ agent](agent.md).
|
|
|
426
426
|
Ask the npm registry whether a newer release exists, and print the version it compared against:
|
|
427
427
|
|
|
428
428
|
```bash
|
|
429
|
-
npx codebase-snapshot@0.20.
|
|
430
|
-
npx codebase-snapshot@0.20.
|
|
429
|
+
npx codebase-snapshot@0.20.12 update # is this build current? print the answer
|
|
430
|
+
npx codebase-snapshot@0.20.12 update --format json
|
|
431
431
|
```
|
|
432
432
|
|
|
433
433
|
```text
|
|
434
|
-
|
|
435
|
-
npm install -g codebase-snapshot
|
|
434
|
+
You are on codebase-snapshot 0.20.12, and the registry publishes 0.20.12. No update is available.
|
|
436
435
|
```
|
|
437
436
|
|
|
438
437
|
Exit `0` when the installed version is current, `1` when a newer release exists, `2` when the
|
|
@@ -482,7 +481,9 @@ codebase-snapshot mcp --cwd <path> # serve another repository
|
|
|
482
481
|
Serves the repository to a Model Context Protocol client over stdio: 26 tools, `snapshot://`
|
|
483
482
|
resources and seven prompts. Stdout carries JSON-RPC messages and nothing else; every note goes to
|
|
484
483
|
stderr. It speaks both protocol eras β the legacy `initialize` handshake and the stateless
|
|
485
|
-
`2026-07-28` revision β and answers whichever the client starts with.
|
|
484
|
+
`2026-07-28` revision β and answers whichever the client starts with. With `--http`, modern
|
|
485
|
+
requests carry `MCP-Protocol-Version`, `Mcp-Method` and (for named calls) `Mcp-Name`;
|
|
486
|
+
mismatches are refused with `-32020` before dispatch.
|
|
486
487
|
|
|
487
488
|
`--cwd` is the only directory it will read. A tool's `root` argument can name a sub-directory of it
|
|
488
489
|
and nothing outside, symlinks included. It never installs packages and never writes a config file.
|
package/docs/configuration.md
CHANGED
|
@@ -469,7 +469,7 @@ either.
|
|
|
469
469
|
A credential assigned to a name inside a string is also masked β a connection string is a string:
|
|
470
470
|
|
|
471
471
|
```js
|
|
472
|
-
const dsn = "password
|
|
472
|
+
const dsn = "password=<redacted-example>;host=db.internal";
|
|
473
473
|
```
|
|
474
474
|
|
|
475
475
|
What is left alone is a credential *name* in a literal, with nothing assigned to it:
|
package/docs/deploy.md
CHANGED
|
@@ -61,8 +61,8 @@ After=network.target
|
|
|
61
61
|
Type=oneshot
|
|
62
62
|
User=deploy
|
|
63
63
|
WorkingDirectory=/srv/app
|
|
64
|
-
ExecStart=/usr/bin/npx -y codebase-snapshot@0.20.
|
|
65
|
-
ExecStartPost=/usr/bin/npx -y codebase-snapshot@0.20.
|
|
64
|
+
ExecStart=/usr/bin/npx -y codebase-snapshot@0.20.12 generate --cwd /srv/app
|
|
65
|
+
ExecStartPost=/usr/bin/npx -y codebase-snapshot@0.20.12 validate --cwd /srv/app
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
```ini
|