@@ -198,8 +198,10 @@ export function registerCLITool(server: McpServer, definition: CLIToolDefinition
198198 positionalArgs = [ ...positionalArgs , ...files as string [ ] ] ;
199199 }
200200
201- // Handle file parameter as positional argument for BQRS tools
202- if ( file && name . startsWith ( 'codeql_bqrs_' ) ) {
201+ // Handle file parameter as positional argument for BQRS tools.
202+ // Check for key presence (not truthiness) so that empty strings
203+ // are caught by the validation below rather than silently skipped.
204+ if ( file !== undefined && name . startsWith ( 'codeql_bqrs_' ) ) {
203205 // Defensive coercion: handle file value that is an actual array
204206 // or a JSON-encoded array string (e.g. '["/path/to/file.bqrs"]')
205207 let cleanFile = Array . isArray ( file ) ? ( file . length > 0 ? String ( file [ 0 ] ) : '' ) : String ( file ) ;
@@ -213,7 +215,7 @@ export function registerCLITool(server: McpServer, definition: CLIToolDefinition
213215 }
214216 } catch { /* not valid JSON — use as-is */ }
215217 }
216- if ( ! cleanFile ) {
218+ if ( ! cleanFile . trim ( ) ) {
217219 throw new Error ( 'The "file" parameter for BQRS tools must be a non-empty string path to a .bqrs file.' ) ;
218220 }
219221 positionalArgs = [ ...positionalArgs , cleanFile ] ;
@@ -399,11 +401,19 @@ export function registerCLITool(server: McpServer, definition: CLIToolDefinition
399401 break ;
400402 }
401403
402- case 'codeql_bqrs_interpret' :
404+ case 'codeql_bqrs_interpret' : {
403405 // Map 'database' to '--source-archive' and '--source-location-prefix'
404- // for codeql bqrs interpret (only when not explicitly provided)
405- if ( options . database ) {
406- const dbPath = resolveDatabasePath ( options . database as string ) ;
406+ // for codeql bqrs interpret (only when not explicitly provided).
407+ // Always delete the synthetic 'database' key to prevent it from
408+ // being forwarded as an unsupported CLI flag.
409+ const dbValue = options . database ;
410+ delete options . database ;
411+ if ( dbValue !== undefined ) {
412+ const dbStr = String ( dbValue ) . trim ( ) ;
413+ if ( ! dbStr ) {
414+ throw new Error ( 'The "database" parameter must be a non-empty path to a CodeQL database.' ) ;
415+ }
416+ const dbPath = resolveDatabasePath ( dbStr ) ;
407417 if ( ! options [ 'source-archive' ] ) {
408418 const srcZipPath = join ( dbPath , 'src.zip' ) ;
409419 const srcDirPath = join ( dbPath , 'src' ) ;
@@ -412,7 +422,6 @@ export function registerCLITool(server: McpServer, definition: CLIToolDefinition
412422 } else if ( existsSync ( srcDirPath ) ) {
413423 options [ 'source-archive' ] = srcDirPath ;
414424 } else {
415- delete options . database ;
416425 throw new Error (
417426 `CodeQL database at "${ dbPath } " does not contain a source archive (expected "src.zip" file or "src" directory).` ,
418427 ) ;
@@ -432,9 +441,9 @@ export function registerCLITool(server: McpServer, definition: CLIToolDefinition
432441 // codeql-database.yml missing or unparseable — skip prefix resolution
433442 }
434443 }
435- delete options . database ;
436444 }
437445 break ;
446+ }
438447
439448 case 'codeql_query_compile' :
440449 case 'codeql_resolve_metadata' :
0 commit comments