[UPDATE PRIMITIVE] Fix codeql_database_analyze additionalArgs pass-through#188
Conversation
codeql_database_analyze additionalArgs pass-through
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. Scanned Files
|
There was a problem hiding this comment.
Pull request overview
Fixes how additionalArgs are passed to CLI tool executions so user-supplied flags are forwarded as raw arguments (instead of being transformed into --additionalArgs=<value>), improving correctness for codeql_database_analyze and any other tools that expose additionalArgs.
Changes:
- Extract
additionalArgsfrom the options object before building CodeQL/QLT args, and append them as raw CLI args. - Add unit tests validating
additionalArgspass-through forcodeql_database_analyze, missingadditionalArgs, and a generic CodeQL tool case. - Rebuild the bundled
server/distoutput.
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| server/src/lib/cli-tool-registry.ts | Extracts additionalArgs from options and appends them to the executor arg list as raw CLI flags. |
| server/test/src/lib/cli-tool-registry.test.ts | Adds regression tests for additionalArgs pass-through behavior (currently only for CodeQL path). |
| server/dist/codeql-development-mcp-server.js | Updates bundled output to reflect the new argument-handling logic. |
8a927e0 to
b8a5b1b
Compare
|
@copilot apply changes based on the comments in this thread |
Applied in ab9c9e5. The managed-flag filter now uses a |
…nalArgs=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>
…s 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>
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>
ab9c9e5 to
0979279
Compare
📝 Update Information
Primitive Details
codeql_database_analyze(and all CLI tools withadditionalArgs)additionalArgsin their schemaUpdate Metadata
🎯 Changes Description
Current Behavior
additionalArgs: ["--sarif-include-query-help=always", "--no-sarif-minify"]stays in theoptionsobject and gets processed bybuildCodeQLArgs(), producing invalid CLI arguments:Updated Behavior
additionalArgsis extracted fromoptionsbeforebuildCodeQLArgs()runs. The raw strings are appended after positional args, producing correct CLI output:Additionally, for tools with post-execution processing (
codeql_query_run,codeql_test_run,codeql_database_analyze), internally-managed flags (--logdir,--evaluator-log,--output,--verbosity,--tuple-counting) are filtered fromadditionalArgswith a warning. These flags are set internally and their values are read back by post-processing (e.g., log summary generation, SARIF interpretation). Passing them viaadditionalArgswould create conflicting duplicates and cause post-processing to use stale values. Users should use the corresponding named parameters instead.The managed-flag filter handles both inline (
--flag=value) and space-separated (--flag value) forms. When a managed flag is supplied in space-separated form (e.g.,['--output', '/override.sarif']), both the flag token and the following value token are removed, preventing stray positional arguments from leaking into the CLI invocation.Motivation
Any
--key=valuestyle argument passed viaadditionalArgswas mangled, making the feature unusable for its intended purpose. Additionally, unfiltered pass-through of managed flags could silently break post-execution processing.🔄 Before vs. After Comparison
Functionality Changes
API Changes
No schema changes. The existing
additionalArgs: z.array(z.string()).optional()now works as documented.Output Format Changes
No output format changes.
🧪 Testing & Validation
Test Coverage Updates
additionalArgsnever appears inoptionspassed to CLIadditionalArgshandled gracefully; managed flag filtering validated for both--flag=valueand--flag value(space-separated) formsValidation Scenarios
codeql_database_analyzetest withoutadditionalArgsstill passes--sarif-include-query-help=alwaysand--no-sarif-minifypassed through correctlyadditionalArgsproduces empty array (no-op)--logdir=/override,--evaluator-log=/override.jsonl,--output=/override.sarif,--no-tuple-counting,--verbosity=errorsare filtered fromadditionalArgsfor tools with post-processing; non-managed flags pass through['--output', '/override.sarif'],['--logdir', '/override'],['--verbosity', 'errors']are fully removed (both flag and value tokens) without leaving stray positional argumentsTest Results
codeql_pack_installnetwork failure)📋 Implementation Details
Files Modified
server/src/lib/cli-tool-registry.ts— extractadditionalArgsbefore CLI arg building; filter managed flags for tools with post-processing (handles both inline and space-separated forms)server/test/src/lib/cli-tool-registry.test.ts— 5 new test casesserver/dist/— rebuiltCode Changes Summary
additionalArgsno longer mangled bybuildCodeQLArgsadditionalArgswith warning for tools with post-execution processing, covering both--flag=valueand--flag valueformsDependencies
🔍 Quality Improvements
Bug Fixes
additionalArgsvalues transformed into--additionalArgs=<value>instead of raw pass-throughadditionalArgswas not extracted fromoptionsbeforebuildCodeQLArgs(), which treats all array entries as--key=valuepairsadditionalArgsfromoptions, append as raw args. Filter managed flags (--logdir,--evaluator-log,--output,--verbosity,--tuple-counting) for tools with post-processing to prevent conflicting duplicates and stale post-processing state. The filter uses aforloop over the argv list to handle both--flag=value(inline) and--flag value(space-separated) forms, skipping the following value token in the space-separated case to prevent stray positional arguments.additionalArgsnever appears in the options object passed to the CLI executor; managed flag filtering tests validate both inline and space-separated forms, and both filtered and pass-through args🔗 References
External References
codeql database analyze -h -vvdocuments--sarif-include-query-helpand--no-sarif-minifyflags🚀 Compatibility & Migration
Backward Compatibility
additionalArgsare unaffected; undefinedadditionalArgsproduces an empty array. Managed flags inadditionalArgsare filtered with a warning (not an error), directing users to use the corresponding named parameter.API Evolution
👥 Review Guidelines
For Reviewers
Testing Instructions
📊 Impact Assessment
Server Impact
AI Assistant Impact
codeql database analyzeflags viaadditionalArgs--sarif-include-query-help=alwaysno longer silently fail; managed flags are filtered with a clear warning instead of causing conflicting CLI behavior; space-separated managed flags no longer leave stray values🔄 Deployment Strategy
Rollout Considerations
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.