Skip to content

Commit ddd4de4

Browse files
Copilotdata-douser
andauthored
Design 1: Populate query_results_cache from database_analyze results
Add cacheDatabaseAnalyzeResults() to auto-cache SARIF output from database_analyze into the query results cache. Update README with new enableAnnotationTools setting documentation. Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/0d52c27d-21be-49ea-bf90-c8fb6f50a3da Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
1 parent 7fd8da3 commit ddd4de4

5 files changed

Lines changed: 130 additions & 3 deletions

File tree

extensions/vscode/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ All settings are under the `codeql-mcp` namespace in VS Code settings:
4545
| `codeql-mcp.serverCommand` | `"node"` | Command to launch the server. Override to `"npx"` or a custom path. |
4646
| `codeql-mcp.serverArgs` | `[]` | Custom args. When empty, the bundled entry point is used. |
4747
| `codeql-mcp.watchCodeqlExtension` | `true` | Watch for databases and results from the CodeQL extension. |
48+
| `codeql-mcp.enableAnnotationTools` | `true` | Enable annotation, audit, and cache tools. |
4849
| `codeql-mcp.additionalEnv` | `{}` | Extra environment variables passed to the server process. |
4950
| `codeql-mcp.additionalDatabaseDirs` | `[]` | Additional directories to search for CodeQL databases. |
5051
| `codeql-mcp.additionalMrvaRunResultsDirs` | `[]` | Additional directories containing MRVA run results. |

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184584,6 +184584,54 @@ Warning: Query processing error - ${error2}`
184584184584
};
184585184585
}
184586184586
}
184587+
function cacheDatabaseAnalyzeResults(params, logger2) {
184588+
try {
184589+
const config2 = sessionDataManager.getConfig();
184590+
if (!config2.enableAnnotationTools) return;
184591+
const outputPath = params.output;
184592+
const format = params.format;
184593+
const dbPath = params.database;
184594+
const queries = params.queries;
184595+
if (!outputPath || !format || !dbPath) return;
184596+
if (!format.includes("sarif")) return;
184597+
let resultContent;
184598+
try {
184599+
resultContent = readFileSync6(outputPath, "utf8");
184600+
} catch {
184601+
return;
184602+
}
184603+
const codeqlVersion = getActualCodeqlVersion();
184604+
const queryName = queries ? basename4(queries, ".qls") : "database-analyze";
184605+
let resultCount = null;
184606+
try {
184607+
const sarif = JSON.parse(resultContent);
184608+
resultCount = sarif?.runs?.[0]?.results?.length ?? null;
184609+
} catch {
184610+
}
184611+
const cacheKey2 = computeQueryCacheKey({
184612+
codeqlVersion,
184613+
databasePath: dbPath,
184614+
outputFormat: format,
184615+
queryPath: queries || "database-analyze"
184616+
});
184617+
const store = sessionDataManager.getStore();
184618+
store.putCacheEntry({
184619+
cacheKey: cacheKey2,
184620+
codeqlVersion,
184621+
databasePath: dbPath,
184622+
interpretedPath: outputPath,
184623+
language: "unknown",
184624+
outputFormat: format,
184625+
queryName,
184626+
queryPath: queries || "database-analyze",
184627+
resultContent,
184628+
resultCount
184629+
});
184630+
logger2.info(`Cached database-analyze results with key: ${cacheKey2} (${resultCount ?? 0} results)`);
184631+
} catch (err) {
184632+
logger2.error("Failed to cache database-analyze results:", err);
184633+
}
184634+
}
184587184635

184588184636
// src/lib/cli-tool-registry.ts
184589184637
init_package_paths();
@@ -187572,6 +187620,9 @@ function registerCLITool(server, definition) {
187572187620
}
187573187621
}
187574187622
}
187623+
if (name === "codeql_database_analyze" && result.success && options.output) {
187624+
cacheDatabaseAnalyzeResults({ ...params, output: options.output, format: options.format }, logger);
187625+
}
187575187626
const processedResult = resultProcessor(result, params);
187576187627
return {
187577187628
content: [{

0 commit comments

Comments
 (0)