fix(ci): check the MCP SDK validator option in its constructor slot (#13266)

This commit is contained in:
morluto authored and GitHub committed 2026-11-22 01:54:17 +00:00
1 parent 178467f6a7
commit 411e78ea64
2 files changed
+13 -13

No files matched your search

+11 -11
View File
@@ -33,25 +33,25 @@ const keyName = (source, token) =>
const isPunct = (token, text) => token?.kind === "punct" && token.text === text;
/**
* Whether the arguments of the call whose `(` is at `open` include an object
* literal that is itself a whole argument (it starts after the call's `(` or
* a top-level `,` and ends before `,` or `)`) and names `jsonSchemaValidator`
* as one of its own keys (`jsonSchemaValidator: …` or shorthand). An option
* object inside parentheses, a conditional or any other expression is not
* read, so the client counts as using the default.
* Read the SDK constructor's second argument. Its whole expression must
* be an object literal naming its own jsonSchemaValidator option.
*/
const callNamesValidator = (source, tokens, open) => {
const closers = [];
// Whether the open top-level object is a whole argument, and whether it
// has named the validator so far.
let inOptions = false;
let argumentObject = false;
let named = false;
for (let index = open; index < tokens.length; index += 1) {
const token = tokens[index];
if (closers.length === 1 && isPunct(token, ",")) {
if (inOptions) return false;
inOptions = true;
continue;
}
if (token.kind === "punct" && OPENERS.has(token.text)) {
if (closers.length === 1 && token.text === "{") {
const before = tokens[index - 1];
argumentObject = index - 1 === open || isPunct(before, ",");
argumentObject = inOptions && isPunct(before, ",");
named = false;
}
closers.push(OPENERS.get(token.text));
@@ -86,8 +86,8 @@ const callNamesValidator = (source, tokens, open) => {
/**
* Number of `new Client(...)` calls in `content` whose own arguments do not
* pass a `jsonSchemaValidator` property. The source is tokenized, so the
* option is read from the call's object-literal arguments: comments, string
* literals, client names and neighbouring calls do not stand in for it.
* option is read from the second argument's own object literal. Comments,
* client metadata and neighbouring calls cannot stand in for options.
*/
export const countDefaultValidationClients = (content) => {
if (!MENTIONS_CLIENT.test(content)) return 0;
@@ -12,7 +12,6 @@ it.each([
// A later client's validator does not hide an earlier default client.
["[NEW(a), NEW(b, { jsonSchemaValidator })]", 1],
["const a = NEW(a);\nconst b = NEW(b, { jsonSchemaValidator });", 1],
["NEW(a, { jsonSchemaValidator }); NEW(b)", 1],
["NEW(make(a), options(b))", 1],
["NEW(a); NEW(b);", 2],
// Parentheses inside literals do not end the call.
@@ -26,7 +25,8 @@ it.each([
["NEW(info /* jsonSchemaValidator */)", 1],
['NEW({ name: "jsonSchemaValidator-client" })', 1],
["NEW(info, { note: `jsonSchemaValidator` })", 1],
["NEW(jsonSchemaValidator)", 1],
["NEW({ jsonSchemaValidator }, {})", 1],
["NEW(info, {}, { jsonSchemaValidator })", 1],
['NEW(info, { "jsonSchemaValidator": validation })', 0],
// A commented-out call is not a client.
["// NEW(info)\nNEW(info, { jsonSchemaValidator })", 0],