Skip to content

Commit fdc42c5

Browse files
Copilotdata-douser
andauthored
Add support for rust language (#195)
* Initial plan * Add Rust language support: query packs, TypeScript, scripts, docs, CI Create Rust CodeQL query pack structure with PrintAST, PrintCFG, CallGraphFrom, CallGraphTo, and CallGraphFromTo tool queries. Update all TypeScript source, shell scripts, documentation, skills, and CI/CD configurations to include Rust. Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/1817d842-51f6-4414-8df3-5b40c48bc036 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Fix tests and add query documentation files for Rust - Update workflow-prompts tests to expect 10 languages (was 9) - Replace 'rust' with 'kotlin' as invalid language in tests since 'rust' is now a valid supported language - Add .md documentation files for all 5 Rust tool queries Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/1817d842-51f6-4414-8df3-5b40c48bc036 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Update remaining scripts, workflows, and skills for Rust support Update server-overview.md, setup-packs.sh, upgrade-packs.sh, update-release-version.sh, release-codeql.yml, and skill files to include 'rust' in language lists. Also update help text in install-packs.sh, extract-test-databases.sh, and run-query-unit-tests.sh. Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/1817d842-51f6-4414-8df3-5b40c48bc036 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Plan for addressing review feedback Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/936d5519-c2a3-418b-9d95-555823d3ea7e Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Address review feedback: pin codeql/rust-all, fix queries, populate .expected files, add rust_ast.md resource - Pin codeql/rust-all to 0.2.10 (not '*') matching other language conventions - Fix Rust CallGraph queries: use getName().getText() for string comparison (Rust's getName() returns Name object, not string like Swift's) - Populate all 5 .expected files with actual query test results - Generate codeql-pack.lock.yml for both src and test packs - Create server/src/resources/languages/rust_ast.md AST reference resource - Register Rust AST resource in language-types.ts - Add 'rust' to VSIX bundle-server.js LANGUAGES array - Change 'kotlin' to 'cobol' as invalid language in tests - Update language-resources tests for 9 AST resources (was 8) Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/936d5519-c2a3-418b-9d95-555823d3ea7e Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Add client integration tests for codeql_query_run with Rust language - rust_tools_print_ast: Tests PrintAST query with graphtext format interpretation, including expected graphtext output for AST visualization - rust_call_graph_from_example1: Tests CallGraphFrom query with SARIF format interpretation and external predicates for source function selection Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/ee9dfe2b-a152-4a44-88b9-6e9c2b7bc831 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Fix mcp-prompt-e2e extension integration test * Fix reviewer comments: correct message pattern spacing in query docs, use extensible predicate wording in integration test READMEs, apply codeql query format to all .ql/.qll files, add *.ql and *.qll to .prettierignore Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/b3ea9842-0497-431d-86d2-800c5fd46faa Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Sync server/dist/** after rebase * Fix MatchExpr and ForExpr accessor names in rust_ast.md resource Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/d79c8230-94c3-42ee-8ee7-ec65be88d8e9 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Fix CallGraph queries to use resolved target entities instead of name-based matching Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/8ce53ee0-dea8-4a8f-b300-436d11463003 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> Co-authored-by: Nathan Randall <data-douser@github.com>
1 parent bac94dd commit fdc42c5

File tree

85 files changed

+2729
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+2729
-45
lines changed

.github/skills/create-codeql-query-development-workshop/SKILL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ Include appropriate CodeQL libraries in `codeql-pack.yml`:
398398
- **JavaScript/TypeScript**: `codeql/javascript-all`
399399
- **Python**: `codeql/python-all`
400400
- **Ruby**: `codeql/ruby-all`
401+
- **Rust**: `codeql/rust-all`
401402

402403
### Java-Specific API Notes
403404

.github/skills/upgrade-codeql-cli-and-packs/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Use the `codeql_pack_ls` MCP tool to see what pack versions are installed:
113113
For each `codeql/*-all` pack, verify it was built for a compatible CLI version by checking the `cliVersion` field in its `qlpack.yml`:
114114

115115
```bash
116-
for lang in actions cpp csharp go java javascript python ruby swift; do
116+
for lang in actions cpp csharp go java javascript python ruby rust swift; do
117117
version=$(ls ~/.codeql/packages/codeql/${lang}-all/ | head -1)
118118
echo "$lang-all@$version: $(cat ~/.codeql/packages/codeql/${lang}-all/$version/qlpack.yml | grep cliVersion)"
119119
done

.github/skills/upgrade-codeql-cli-and-packs/verify-pack-compatibility.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ find_extractor_dir() {
5151
}
5252

5353
## Languages to check
54-
LANGUAGES=("actions" "cpp" "csharp" "go" "java" "javascript" "python" "ruby" "swift")
54+
LANGUAGES=("actions" "cpp" "csharp" "go" "java" "javascript" "python" "ruby" "rust" "swift")
5555

5656
## Track overall status
5757
ALL_COMPATIBLE=true

.github/skills/validate-ql-mcp-server-tools-queries/SKILL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The tools queries are available for all CodeQL-supported languages:
3333
| javascript | `server/ql/javascript/tools/` | `.js` |
3434
| python | `server/ql/python/tools/` | `.py` |
3535
| ruby | `server/ql/ruby/tools/` | `.rb` |
36+
| rust | `server/ql/rust/tools/` | `.rs` |
3637
| swift | `server/ql/swift/tools/` | `.swift` |
3738

3839
## Tools Queries Overview

.github/workflows/query-unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
strategy:
4343
fail-fast: false
4444
matrix:
45-
language: ['actions', 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby']
45+
language: ['actions', 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'rust']
4646

4747
steps:
4848
- name: Query Unit Tests - ${{ matrix.language }} - Checkout repository

.github/workflows/release-codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8383
run: |
8484
RELEASE_NAME="${{ steps.version.outputs.release_name }}"
85-
LANGUAGES="actions cpp csharp go java javascript python ruby swift"
85+
LANGUAGES="actions cpp csharp go java javascript python ruby rust swift"
8686
8787
# Prerelease versions (containing a hyphen) require --allow-prerelease
8888
PRERELEASE_FLAG=""
@@ -110,7 +110,7 @@ jobs:
110110
- name: CodeQL - Bundle CodeQL tool query packs
111111
run: |
112112
mkdir -p dist-packs
113-
LANGUAGES="actions cpp csharp go java javascript python ruby swift"
113+
LANGUAGES="actions cpp csharp go java javascript python ruby rust swift"
114114
echo "Bundling CodeQL tool query packs..."
115115
for lang in ${LANGUAGES}; do
116116
PACK_DIR="server/ql/${lang}/tools/src"
@@ -148,6 +148,6 @@ jobs:
148148
echo "### Published CodeQL Packs" >> $GITHUB_STEP_SUMMARY
149149
echo "| Pack | Version |" >> $GITHUB_STEP_SUMMARY
150150
echo "| ---- | ------- |" >> $GITHUB_STEP_SUMMARY
151-
for lang in actions cpp csharp go java javascript python ruby swift; do
151+
for lang in actions cpp csharp go java javascript python ruby rust swift; do
152152
echo "| \`advanced-security/ql-mcp-${lang}-tools-src\` | ${RELEASE_NAME} |" >> $GITHUB_STEP_SUMMARY
153153
done

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,6 @@ jobs:
279279
echo "### Published CodeQL Packs" >> $GITHUB_STEP_SUMMARY
280280
echo "| Pack | Version |" >> $GITHUB_STEP_SUMMARY
281281
echo "| ---- | ------- |" >> $GITHUB_STEP_SUMMARY
282-
for lang in actions cpp csharp go java javascript python ruby swift; do
282+
for lang in actions cpp csharp go java javascript python ruby rust swift; do
283283
echo "| \`advanced-security/ql-mcp-${lang}-tools-src\` | ${RELEASE_NAME} |" >> $GITHUB_STEP_SUMMARY
284284
done

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*.actual
44
*.expected
55
*.log
6+
*.ql
7+
*.qll
68
*.qlref
79
*.testproj/
810
options
@@ -17,6 +19,8 @@ extensions/vscode/test/fixtures/
1719
node_modules
1820
query-results*
1921
server/dist/
22+
server/ql/*/tools/src/*.md
23+
server/ql/*/tools/src/**/*.md
2024
server/ql/*/tools/test/*
2125
workshops/
2226

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Integration Test: codeql_query_run/rust_call_graph_from_example1
2+
3+
## Purpose
4+
5+
Tests the `codeql_query_run` tool with the CallGraphFrom query for Rust language, demonstrating external predicates for source function selection and SARIF format interpretation for call graph visualization.
6+
7+
## Test Scenario
8+
9+
This test validates that the `codeql_query_run` tool can:
10+
11+
1. Accept `queryName` ("CallGraphFrom") and `queryLanguage` ("rust") parameters
12+
2. Accept `sourceFunction` parameter to specify which function's outbound calls to analyze
13+
3. Resolve the query path using `codeql resolve queries` to find the CallGraphFrom.ql query
14+
4. Automatically provide external predicates for the sourceFunction
15+
5. Execute the resolved query against a Rust test database with external predicate data
16+
6. Interpret the .bqrs results using native `codeql bqrs interpret --format=sarif-latest`
17+
7. Generate SARIF format output containing call graph results
18+
8. Return enhanced results confirming the interpretation succeeded
19+
20+
## Required Inputs
21+
22+
The test requires the following inputs in `before/monitoring-state.json`:
23+
24+
- `queryName`: "CallGraphFrom" - Name of the query to resolve and execute
25+
- `queryLanguage`: "rust" - Programming language for query resolution
26+
- `database`: "server/ql/rust/tools/test/CallGraphFrom/CallGraphFrom.testproj" - Path to CodeQL test database
27+
- `sourceFunction`: "source_func" - Source function name to analyze (used as external predicate)
28+
- `output`: "query-results.bqrs" - Output file for binary query results
29+
- `format`: "sarif-latest" - SARIF format for interpreting @kind problem query results
30+
- `interpretedOutput`: "query-results.sarif" - Output file for SARIF format results
31+
- `timeout`: 300000 - Timeout in milliseconds (5 minutes)
32+
33+
The test database is created by running `codeql test extract server/ql/rust/tools/test/CallGraphFrom`.
34+
35+
## Expected Outputs
36+
37+
The test expects the following behavior:
38+
39+
- `monitoring-state.json`: Test execution state showing success
40+
- The tool generates `query-results.bqrs` (binary query results, not committed to repo)
41+
- The tool interprets results using `codeql bqrs interpret --format=sarif-latest`
42+
- The SARIF output contains call graph entries showing calls from `source_func` to `unrelated1` and `unrelated2`
43+
- The monitoring state confirms successful execution and interpretation
44+
45+
## Expected Behavior
46+
47+
The tool should:
48+
49+
1. Resolve "CallGraphFrom" to the absolute path of `server/ql/rust/tools/src/CallGraphFrom/CallGraphFrom.ql`
50+
2. Automatically add external predicate: `sourceFunction=source_func`
51+
3. Execute the query against the provided database with the external predicate data
52+
4. Generate query results in BQRS format
53+
5. Call `codeql bqrs interpret` with format=sarif-latest
54+
6. Generate SARIF output showing calls from the source function
55+
7. Return enhanced output confirming the interpretation succeeded
56+
57+
## External Predicates Integration
58+
59+
This test demonstrates the integration between the MCP server's sourceFunction parameter and CodeQL's extensible predicates system. The CallGraphFrom query uses `extensible predicate sourceFunction(string name)` to receive the function name via data extensions, making it work with any Rust code database.
60+
61+
## Format Parameter
62+
63+
This test uses the `format` parameter which leverages native CodeQL tooling (`codeql bqrs interpret`) to produce SARIF output based on query metadata.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"toolName": "codeql_query_run",
3+
"parameters": {
4+
"queryName": "CallGraphFrom",
5+
"queryLanguage": "rust",
6+
"database": "server/ql/rust/tools/test/CallGraphFrom/CallGraphFrom.testproj",
7+
"sourceFunction": "source_func",
8+
"output": "query-results.bqrs",
9+
"format": "sarif-latest",
10+
"interpretedOutput": "query-results.sarif",
11+
"timeout": 300000
12+
},
13+
"success": true,
14+
"description": "Successfully executed CallGraphFrom (@kind problem) query using query name resolution with external predicates and SARIF format interpretation for Rust language"
15+
}

0 commit comments

Comments
 (0)