You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: extensions/vscode/package.json
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -108,6 +108,11 @@
108
108
"default": "latest",
109
109
"description": "The npm version of codeql-development-mcp-server to install. Use 'latest' for the most recent release."
110
110
},
111
+
"codeql-mcp.scratchDir": {
112
+
"type": "string",
113
+
"default": ".codeql/ql-mcp",
114
+
"markdownDescription": "Workspace-relative path for the ql-mcp scratch directory used for temporary files (query logs, external predicates, etc). The `.codeql/` parent is shared with other CodeQL CLI commands like `codeql pack bundle`. Set to an absolute path to override workspace-relative resolution."
if (hasFallback || !isQuotedString || HEX_ESCAPE_REGEXP.test(name)) {
34651
34651
params["filename*"] = name;
@@ -57007,6 +57007,26 @@ init_package_paths();
57007
57007
init_temp_dir();
57008
57008
import { writeFileSync as writeFileSync2, rmSync, existsSync as existsSync4, mkdirSync as mkdirSync5, readdirSync as readdirSync2, statSync as statSync2 } from "fs";
57009
57009
import { basename as basename2, dirname as dirname4, isAbsolute as isAbsolute4, join as join6, resolve as resolve4 } from "path";
57010
+
function resolveDatabasePath(dbPath) {
57011
+
if (existsSync4(join6(dbPath, "codeql-database.yml"))) {
57012
+
return dbPath;
57013
+
}
57014
+
try {
57015
+
const entries = readdirSync2(dbPath);
57016
+
for (const entry of entries) {
57017
+
const candidate = join6(dbPath, entry);
57018
+
try {
57019
+
if (statSync2(candidate).isDirectory() && existsSync4(join6(candidate, "codeql-database.yml"))) {
hints.push("No test directory found. To run this query you will need a user-provided database (databasePath). Test-driven profiling is not available without tests.");
60748
+
} else if (testCodePaths.length === 0) {
60749
+
hints.push("Test directory exists but contains no test source code files. Consider creating test code to enable test-driven workflows.");
60750
+
}
60751
+
if (!expectedResultsPath.exists && testDirectory.exists) {
60752
+
hints.push("No .expected file found. Run codeql_test_run to generate initial expected results, then verify them.");
60753
+
}
60754
+
if (!documentationPath.exists) {
60755
+
hints.push("No query documentation (.md) file found. Use the document_codeql_query prompt to generate one.");
60756
+
}
60740
60757
return {
60741
60758
queryName,
60742
60759
language: detectedLanguage,
@@ -60759,6 +60776,7 @@ async function findCodeQLQueryFiles(queryFilePath, language, resolveMetadata = t
60759
60776
testDatabaseDir: testDatabasePath.path
60760
60777
}
60761
60778
},
60779
+
hints,
60762
60780
metadata,
60763
60781
missingFiles,
60764
60782
packMetadata,
@@ -62884,13 +62902,14 @@ var codeqlResolveTestsTool = {
62884
62902
62885
62903
// src/tools/codeql/search-ql-code.ts
62886
62904
import { createReadStream as createReadStream3, lstatSync, readdirSync as readdirSync8, readFileSync as readFileSync9, realpathSync } from "fs";
62887
-
import { extname as extname2, join as join15, resolve as resolve9 } from "path";
62905
+
import { basename as basename6, extname as extname2, join as join15, resolve as resolve9 } from "path";
62888
62906
import { createInterface as createInterface3 } from "readline";
62889
62907
init_logger();
62890
62908
var MAX_FILE_SIZE_BYTES = 5 * 1024 * 1024;
62891
62909
var MAX_FILES_TRAVERSED = 1e4;
62892
62910
var MAX_CONTEXT_LINES = 50;
62893
62911
var MAX_MAX_RESULTS = 1e4;
62912
+
var SKIP_DIRS2 = /* @__PURE__ */ new Set([".codeql", "node_modules", ".git"]);
62894
62913
function collectFiles(paths, extensions, fileCount) {
62895
62914
const files = [];
62896
62915
const visitedDirs = /* @__PURE__ */ new Set();
@@ -62909,6 +62928,7 @@ function collectFiles(paths, extensions, fileCount) {
62909
62928
}
62910
62929
fileCount.value++;
62911
62930
} else if (stat.isDirectory()) {
62931
+
if (SKIP_DIRS2.has(basename6(p))) return;
62912
62932
let realPath;
62913
62933
try {
62914
62934
realPath = realpathSync(p);
@@ -63066,7 +63086,7 @@ function registerSearchQlCodeTool(server) {
@@ -64185,7 +64205,7 @@ function registerLanguageResources(server) {
64185
64205
}
64186
64206
64187
64207
// src/prompts/workflow-prompts.ts
64188
-
import { basename as basename6 } from "path";
64208
+
import { basename as basename7 } from "path";
64189
64209
64190
64210
// src/prompts/document-codeql-query.prompt.md
64191
64211
var document_codeql_query_prompt_default = '---\nagent: agent\n---\n\n# Document a CodeQL Query\n\nThis prompt guides you through creating or updating documentation for a CodeQL query file. The documentation is stored as a sibling file to the query with a standardized markdown format.\n\n## Purpose\n\nThe `document_codeql_query` prompt creates/updates **query documentation files** for a specific version of a CodeQL query. Documentation files are stored alongside the query file and provide concise yet comprehensive information about what the query does.\n\nFor creating **workshop learning content** with detailed explanations and visual diagrams, use the `explain_codeql_query` prompt instead.\n\n## Required Inputs\n\n- **queryPath**: Path to the CodeQL query file (`.ql` or `.qlref`)\n- **language**: Target programming language (actions, cpp, csharp, go, java, javascript, python, ruby, swift)\n\n## Documentation File Conventions\n\n### File Location and Naming\n\nFor a query file `QueryFileBaseName.ql`, the documentation file should be:\n\n- **Primary**: `QueryFileBaseName.md` (markdown format, preferred)\n- **Legacy**: `QueryFileBaseName.qhelp` (XML-based query help format)\n\nDocumentation files are **siblings** to the query file (same directory).\n\n### Handling Existing Documentation\n\n1. **No documentation exists**: Create new `QueryFileBaseName.md` file\n2. **`.md` file exists**: Update the existing markdown file\n3. **`.qhelp` file exists**: Use #codeql_generate_query-help tool to convert to markdown, then update\n\n## Workflow Checklist\n\nUse the following MCP server tools to gather context before creating documentation:\n\n### Phase 1: Query Discovery\n\n- [ ] **Step 1: Locate query files**\n - Tool: #find_codeql_query_files\n - Parameters: `queryPath` = provided query path\n - Gather: Query source file path, existing documentation files, test files\n - Check: Does `QueryFileBaseName.md` or `QueryFileBaseName.qhelp` exist?\n\n- [ ] **Step 2: Read query metadata**\n - Tool: #codeql_resolve_metadata\n - Parameters: `query` = query file path\n - Gather: @name, @description, @kind, @id, @tags, @precision, @severity\n\n### Phase 2: Convert Existing qhelp (if needed)\n\n- [ ] **Step 3: Convert qhelp to markdown** (only if `.qhelp` exists)\n - Tool: #codeql_generate_query-help\n - Parameters: `query` = query file path, `format` = "markdown"\n - Use output as starting point for updated documentation\n\n### Phase 3: Gather Query Context\n\n- [ ] **Step 4: Validate query structure**\n - Tool: #validate_codeql_query\n - Parameters: `query` = query source code\n - Gather: Structural validation, suggestions\n - Note: This is a heuristic check only \u2014 for full validation, use #codeql_query_compile\n\n- [ ] **Step 5: Explore query types** (if deeper understanding needed)\n - Tool: #codeql_lsp_definition \u2014 navigate to class/predicate definitions\n - Tool: #codeql_lsp_completion \u2014 explore member predicates on types used in the query\n - Parameters: `file_path`, `line` (0-based), `character` (0-based), `workspace_uri` (pack root)\n - Run #codeql_pack_install first \u2014 LSP tools require resolved dependencies\n\n- [ ] **Step 6: Run tests** (if tests exist from Step 1)\n - Tool: #codeql_test_run\n - Parameters: `tests` = test directories\n - Gather: Pass/fail status, confirms query behavior\n\n### Phase 4: Create/Update Documentation\n\nBased on gathered context, create or update the documentation file.\n\n## Documentation Format\n\nThe documentation file (`QueryFileBaseName.md`) should follow this standardized format with these sections:\n\n### Section 1: Title and Description\n\n- H1 heading with the query name from @name metadata\n- One paragraph description from @description, expanded if needed\n\n### Section 2: Metadata Table\n\nA table with these rows:\n\n- ID: The @id value in backticks\n- Kind: The @kind value (problem, path-problem, etc.)\n- Severity: The @severity value\n- Precision: The @precision value\n- Tags: The @tags values\n\n### Section 3: Overview\n\nConcise explanation of what vulnerability/issue this query detects and why it matters. 2-4 sentences.\n\n### Section 4: Recommendation\n\nBrief guidance on how developers should fix issues flagged by this query. Include code patterns to use or avoid.\n\n### Section 5: Example\n\nTwo subsections:\n\n- **Vulnerable Code**: A code block showing a pattern that would be flagged by this query\n- **Fixed Code**: A code block showing the corrected version of the code\n\nUse the appropriate language identifier for the code blocks (e.g., `javascript`, `python`, `java`).\n\n### Section 6: References\n\nA list of links to:\n\n- Relevant CWE if security query\n- Relevant documentation or standards\n- CodeQL documentation for related concepts\n\n## Output Actions\n\nAfter generating documentation content:\n\n1. **For new documentation**: Create the file at `[QueryDirectory]/QueryFileBaseName.md`\n2. **For existing `.md` file**: Update the file with new content, preserving any custom sections\n3. **For existing `.qhelp` file**: Create new `.md` file (keeping `.qhelp` for backward compatibility)\n\n## Important Notes\n\n- **Be concise**: Documentation should be brief but complete. This is reference documentation, not tutorial content.\n- **Keep it current**: Documentation should reflect the current behavior of the query.\n- **Use examples from tests**: If unit tests exist, use those code patterns as examples.\n- **Standard format**: Always use the format above for consistency across all query documentation.\n- **Metadata accuracy**: Ensure documented metadata matches actual query metadata.\n- **For workshops**: Use `explain_codeql_query` prompt when creating workshop content that requires deeper explanations and visual diagrams.\n';
0 commit comments