Skip to content

Commit de78423

Browse files
Copilotdata-douser
andauthored
[UPDATE PRIMITIVE] Fix codeql_database_analyze additionalArgs pass-through (#188)
* Initial plan * fix: extract additionalArgs as raw CLI arguments instead of --additionalArgs=value Previously, `additionalArgs` (e.g., `["--sarif-include-query-help=always"]`) stayed in the options object and was processed by `buildCodeQLArgs` into `--additionalArgs=--sarif-include-query-help=always`, which is invalid. Now `additionalArgs` is extracted from options before CLI arg building and appended as raw arguments after positional args, so args like `--sarif-include-query-help=always` and `--no-sarif-minify` are passed through correctly to the `codeql` CLI. Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/ff382e0c-2894-422a-a9c8-22c431c9a77a Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * fix: filter managed CLI flags from additionalArgs to prevent conflicts with post-processing For tools with post-execution processing (query run, test run, database analyze), flags like --logdir, --evaluator-log, --output, --verbosity, and --tuple-counting are set internally and read back after execution. If these appear in additionalArgs, they would create conflicting duplicates and break post-processing. Now they are filtered out with a warning directing the user to use the corresponding named parameter. Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/dd017a82-a805-40c8-bb2f-4eae0678766d Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Sync server/dist/** * fix: handle space-separated managed flags in additionalArgs filtering Replace .filter() with a for-loop that also skips the following value token when a managed flag is supplied in space-separated form (e.g. ['--output', '/override.sarif']) instead of inline form (e.g. ['--output=/override.sarif']). This prevents stray positional arguments from leaking into the CLI invocation. Add test coverage for the space-separated form. Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/fb3b1eea-290e-4eaa-bf2b-26b1521e5a58 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Sync package-lock.json && server/dist/** * Update .vscodeignore --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> Co-authored-by: Nathan Randall <data-douser@github.com>
1 parent 39b7e80 commit de78423

File tree

6 files changed

+344
-38
lines changed

6 files changed

+344
-38
lines changed

extensions/vscode/.vscodeignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ esbuild.config.js
1616
coverage/**
1717

1818
# Build artifacts that shouldn't be in the VSIX
19-
.tmp/**
19+
**/.codeql/**
20+
**/.tmp/**
2021
**/*.test.ts
2122
**/*.test.js
2223
**/*.test.cjs
2324
**/*.map
24-
dist/test/**
25+
**/dist/test/**
2526

2627
# Bundled server: exclude test/examples content
2728
server/ql/*/tools/test/**

package-lock.json

Lines changed: 22 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/dist/codeql-development-mcp-server.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58042,6 +58042,34 @@ function registerCLITool(server, definition) {
5804258042
mkdirSync5(outputDir, { recursive: true });
5804358043
}
5804458044
}
58045+
const rawAdditionalArgs = Array.isArray(options.additionalArgs) ? options.additionalArgs : [];
58046+
delete options.additionalArgs;
58047+
const managedFlagNames = /* @__PURE__ */ new Set([
58048+
"evaluator-log",
58049+
"logdir",
58050+
"output",
58051+
"tuple-counting",
58052+
"verbosity"
58053+
]);
58054+
const userAdditionalArgs = queryLogDir ? (() => {
58055+
const filteredAdditionalArgs = [];
58056+
for (let i = 0; i < rawAdditionalArgs.length; i += 1) {
58057+
const arg = rawAdditionalArgs[i];
58058+
const m = arg.match(/^--(?:no-)?([^=]+)(?:=.*)?$/);
58059+
if (m && managedFlagNames.has(m[1])) {
58060+
logger.warn(
58061+
`Ignoring "${arg}" from additionalArgs for ${name}: this flag is managed internally. Use the corresponding named parameter instead.`
58062+
);
58063+
const hasInlineValue = arg.includes("=");
58064+
if (!hasInlineValue && i + 1 < rawAdditionalArgs.length) {
58065+
i += 1;
58066+
}
58067+
continue;
58068+
}
58069+
filteredAdditionalArgs.push(arg);
58070+
}
58071+
return filteredAdditionalArgs;
58072+
})() : rawAdditionalArgs;
5804558073
let result;
5804658074
if (command === "codeql") {
5804758075
let cwd;
@@ -58058,9 +58086,9 @@ function registerCLITool(server, definition) {
5805858086
if (name === "codeql_test_run") {
5805958087
options["keep-databases"] = true;
5806058088
}
58061-
result = await executeCodeQLCommand(subcommand, options, positionalArgs, cwd);
58089+
result = await executeCodeQLCommand(subcommand, options, [...positionalArgs, ...userAdditionalArgs], cwd);
5806258090
} else if (command === "qlt") {
58063-
result = await executeQLTCommand(subcommand, options, positionalArgs);
58091+
result = await executeQLTCommand(subcommand, options, [...positionalArgs, ...userAdditionalArgs]);
5806458092
} else {
5806558093
throw new Error(`Unsupported command: ${command}`);
5806658094
}

server/dist/codeql-development-mcp-server.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/lib/cli-tool-registry.ts

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,62 @@ export function registerCLITool(server: McpServer, definition: CLIToolDefinition
474474
}
475475
}
476476

477+
// Extract additionalArgs from options so they are passed as raw CLI
478+
// arguments instead of being transformed into --additionalArgs=value
479+
// by buildCodeQLArgs.
480+
const rawAdditionalArgs = Array.isArray(options.additionalArgs)
481+
? options.additionalArgs as string[]
482+
: [];
483+
delete options.additionalArgs;
484+
485+
// For tools with post-execution processing (query run, test run,
486+
// database analyze), certain CLI flags are set internally and their
487+
// values are read back after execution (e.g. --evaluator-log for log
488+
// summary generation, --output for SARIF interpretation). If a user
489+
// passes these flags via additionalArgs the CLI would receive
490+
// conflicting duplicates and the post-processing would use stale
491+
// values from the options object. Filter them out and log a warning
492+
// directing the user to the corresponding named parameter instead.
493+
const managedFlagNames = new Set([
494+
'evaluator-log',
495+
'logdir',
496+
'output',
497+
'tuple-counting',
498+
'verbosity',
499+
]);
500+
const userAdditionalArgs = queryLogDir
501+
? (() => {
502+
const filteredAdditionalArgs: string[] = [];
503+
504+
for (let i = 0; i < rawAdditionalArgs.length; i += 1) {
505+
const arg = rawAdditionalArgs[i];
506+
const m = arg.match(/^--(?:no-)?([^=]+)(?:=.*)?$/);
507+
508+
if (m && managedFlagNames.has(m[1])) {
509+
logger.warn(
510+
`Ignoring "${arg}" from additionalArgs for ${name}: ` +
511+
'this flag is managed internally. Use the corresponding named parameter instead.'
512+
);
513+
514+
// Always skip the managed flag itself. If it is provided in
515+
// space-separated form (e.g. ["--output", "file.sarif"]),
516+
// also skip the following token as its value so it does not
517+
// become a stray positional argument.
518+
const hasInlineValue = arg.includes('=');
519+
if (!hasInlineValue && i + 1 < rawAdditionalArgs.length) {
520+
i += 1;
521+
}
522+
523+
continue;
524+
}
525+
526+
filteredAdditionalArgs.push(arg);
527+
}
528+
529+
return filteredAdditionalArgs;
530+
})()
531+
: rawAdditionalArgs;
532+
477533
let result: CLIExecutionResult;
478534

479535
if (command === 'codeql') {
@@ -507,9 +563,9 @@ export function registerCLITool(server: McpServer, definition: CLIToolDefinition
507563
options['keep-databases'] = true;
508564
}
509565

510-
result = await executeCodeQLCommand(subcommand, options, positionalArgs, cwd);
566+
result = await executeCodeQLCommand(subcommand, options, [...positionalArgs, ...userAdditionalArgs], cwd);
511567
} else if (command === 'qlt') {
512-
result = await executeQLTCommand(subcommand, options, positionalArgs);
568+
result = await executeQLTCommand(subcommand, options, [...positionalArgs, ...userAdditionalArgs]);
513569
} else {
514570
throw new Error(`Unsupported command: ${command}`);
515571
}

0 commit comments

Comments
 (0)