Error in user YAML: (<unknown>): found character that cannot start any token while scanning for the next token at line 1 column 10
---
applyTo: `server/ql/*/tools/**'
description: 'Instructions for organizing CodeQL queries and query unit tests for all code languages supported by the CodeQL MCP server tools.'
---
The purpose of the server/ql/<language>/tools/ implementation is to provide language-specific CodeQL queries that are used by MCP server tools, along with comprehensive unit tests to ensure query correctness and reliability.
Each language directory follows a standardized structure that enables automatic discovery and testing through the server/scripts/run-query-unit-tests.sh script.
- ALWAYS run
npm run build-and-testfrom the repo root directory and ensure it passes completely before committing any changes. This is MANDATORY and must be verified before every commit. - ALWAYS run
./server/scripts/run-query-unit-tests.shfrom the repo root directory and ensure all CodeQL query unit tests pass before committing changes to query files or tests. - ALWAYS fix lint errors by running
npm run lint:fixfrom the repo root directory before committing changes. - ALWAYS follow the directory structure documented in server/ql/README.md.
- ALWAYS place query implementation files in
tools/src/<query-name>/subdirectories. - ALWAYS place corresponding test files in
tools/test/<query-name>/subdirectories. - ALWAYS include proper CodeQL query metadata using
@name,@description,@id,@kind, and@tagsannotations. - ALWAYS create a
.mdquery documentation file alongside every.qlquery intools/src/<query-name>/(e.g.,PrintAST.mdnext toPrintAST.ql). This is enforced by thequery-documentation.test.tsunit test. - ALWAYS use the existing
server/ql/*/tools/src/PrintCFG/PrintCFG.mdfiles as the canonical style reference for@kind graphquery documentation. These docs describe the structural output (nodes/edges) rather than flagging problems, so code examples should illustrate what structure the query visualizes — not whether code is compliant or non-compliant. - ALWAYS create
.qlreffiles that reference the correct query path relative to the tools directory. - ALWAYS create
.expectedfiles with the expected output for each test case. - ALWAYS implement test code source files that test both the query's ability to ignore
COMPLIANTcode patterns AND to detectNON_COMPLIANTcode patterns for detection-style queries (@kind problem/@kind path-problem). - ALWAYS comment test cases as either
COMPLIANT(i.e. query should not match) orNON-COMPLIANT(i.e. query should match) for detection-style queries. - ALWAYS omit
COMPLIANTandNON_COMPLIANTannotations from@kind graphquery documentation and test code, because these queries produce structural output (ASTs, CFGs, call graphs) rather than detecting problems. - ALWAYS use the
server/scripts/install-packs.shscript to install dependencies for CodeQL packs defined under theserver/ql/*/language/tools/directories. - ALWAYS use explicit version numbers in
codeql-pack.ymlfiles; never use wildcards (*). - ALWAYS set
ql-mcp-*pack versions to match the CodeQL CLI version from.codeql-version(without thevprefix). - ALWAYS refer to the upgrade-codeql-cli-and-packs skill when updating CodeQL CLI or pack versions.
- PREFER organizing complex queries into multiple helper predicates for better readability and maintainability.
- PREFER maintaining the existing set of queries; do not add your own unless explicitly required for some new functionality.
- PREFER implementation consistency across all supported
server/ql/<language>/languages, using the same query name across all languages for consistency and prioritizing breadth of language support over depth of queries per language. - PREFER short yet descriptive query names that clearly indicate their purpose and scope.
- PREFER using external predicates (like
selectedSourceFiles()) to make queries configurable for MCP server tool usage. - PREFER including fallback logic for unit testing when external predicates are not available.
- NEVER leave any trailing whitespace on any line.
- NEVER create queries without corresponding unit tests.
- NEVER modify query behavior without updating the corresponding
.expectedfiles. - NEVER use hardcoded file paths in queries; use configurable predicates or relative path matching.
- NEVER create test files that depend on external resources not included in the test directory.
- NEVER commit query files that fail CodeQL compilation or unit tests.
- NEVER create
.qlreffiles with incorrect paths or missing target queries. - NEVER mix different query purposes within a single query file.
- NEVER omit required CodeQL query metadata annotations.
- NEVER omit query documentation (
.md) for any query published in atools/src/pack directory. - NEVER create test cases that don't actually exercise the query logic being tested.