Skip to content

Commit cd3f1cc

Browse files
data-douserCopilotCopilot
committed
ql-mcp-client rewrite: Phases 1 & 2 — Replace ql-mcp-client.js with Go implementation (#223)
* Initial plan * Phase 1: Update documentation and GitHub config for Go-based client Update all .github config files, documentation, workflows, and package.json to reflect the intended Go-based ql-mcp-client architecture. No Go source code is introduced — only documentation, config, and a stub Makefile. - Create .github/instructions/client_go.instructions.md for Go conventions - Update client_src_js.instructions.md to Go guidance - Update client_integration_tests.instructions.md for Go test runner - Update agent files to reference Go client instead of JS client - Update ql-mcp-server-fix-build-and-test.prompt.md with make commands - Add actions/setup-go to CI workflows - Rewrite client/README.md and CLI-USAGE.md for gh-ql-mcp-client - Update client/integration-tests/README.md for Go test runner - Update docs/testing.md to describe Go MCP client - Update package.json to use make -C client targets, remove client workspace - Add stub client/Makefile with go.mod-conditional targets Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/f5595942-48af-4847-8d28-fba34a17ba76 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Update client/.gitignore for go ql-mcp-client * Replace JavaScript client with Go binary and integration test runner (#221) * Initial plan * Replace JavaScript client with Go binary and integration test runner - Remove client/src/ directory with all JS files (ql-mcp-client.js and 14 library modules) - Remove client/package.json and client/eslint.config.mjs - Add Go module (go.mod, go.sum) with cobra and mcp-go dependencies - Add CLI entry point (main.go) and root Cobra command (cmd/root.go) - Add CLI helpers (cmd/helpers.go) and integration test command (cmd/integration_tests.go) - Add MCP client library (internal/mcp/client.go) with stdio and HTTP transport - Add integration test runner (internal/testing/runner.go, params.go) - Add comprehensive unit tests for all packages (16 tests, all passing) - Update Makefile to remove go.mod guards (Go source now available) - Update run-integration-tests.sh to build and use Go binary - Update test-config.json logDir paths for custom_log_directory tests Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/8c006672-cf7e-4045-9488-f6d97fafe2f2 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Final validation complete Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/8c006672-cf7e-4045-9488-f6d97fafe2f2 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Revert unrelated go.mod changes in server/ql/go/tools/test/ Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/8c006672-cf7e-4045-9488-f6d97fafe2f2 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Replace actual repo reference with placeholder in helpers_test.go Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/86c1cb26-2977-409f-ace0-aabc4fc9cee7 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> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Nathan Randall <70299490+data-douser@users.noreply.github.com> * Remove client_src_js.instructions.md * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Nathan Randall <70299490+data-douser@users.noreply.github.com> * Address PR review feedback * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Nathan Randall <70299490+data-douser@users.noreply.github.com> * Improve ql-mcp-client from PR feedback * Fix "--no-install-packs" in client integration test runner * Fixes for failing client integration tests * Fix extension mcp-tool-e2e.integration.test.ts * More fixes for PR review feedback * Fix client-integration-tests.yml Windows job * More fixes for PR review feedback * Updates for compatibility with main-merged PRs * Fix client-integration-tests for extract dbs * Address PR review feedback: fix Close() kill, remove enableAnnotationTools setting, record skipped results, fix schema default, clarify changelog Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/a90a53a5-b2ad-4775-8b61-f11d16b33749 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Revert test-integration to skip pack install by default, add test-integration-with-packs for explicit pack setup Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/a90a53a5-b2ad-4775-8b61-f11d16b33749 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Address review thread 4071470992: path check, changelog, timeout help, error message, cross-platform test, output path sandboxing Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/0666a5dd-b460-4e6e-9749-f729c46f0b62 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> --------- Signed-off-by: Nathan Randall <70299490+data-douser@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent fd7f222 commit cd3f1cc

File tree

77 files changed

+3938
-8024
lines changed

Some content is hidden

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

77 files changed

+3938
-8024
lines changed

.github/agents/ql-agent-skills-developer.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,23 @@ All command paths are relative to the root of the `advanced-security/codeql-deve
3232
Get the current list of all tools available in the CodeQL Development MCP Server:
3333

3434
```sh
35-
node client/src/ql-mcp-client.js list tools --format json
35+
gh-ql-mcp-client list tools --format json
36+
```
37+
38+
### List QL MCP Server Prompts
39+
40+
Get the current list of all prompts available in the CodeQL Development MCP Server:
41+
42+
```sh
43+
gh-ql-mcp-client list prompts --format json
44+
```
45+
46+
### List QL MCP Server Resources
47+
48+
Get the current list of all resources available in the CodeQL Development MCP Server:
49+
50+
```sh
51+
gh-ql-mcp-client list resources --format json
3652
```
3753

3854
## References

.github/agents/ql-mcp-tool-developer.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ My `ql-mcp-tool-developer` agent:
3131

3232
- Implements new tools in `server/src/` with TypeScript.
3333
- Creates comprehensive unit tests in `server/test/` for all new/modified tools.
34-
- Validates tool behavior with integration tests using `client/src/ql-mcp-client.js`.
34+
- Validates tool behavior with integration tests using the Go client (`make -C client test-integration`).
3535
- Ensures tools properly handle errors and edge cases.
3636
- Documents tool parameters, return types, and usage patterns.
3737
- Tests MCP server functionality:
3838
- Runs unit tests: `npm test --workspace=server`.
39-
- Runs integration tests: `client/scripts/run-integration-tests.sh`.
40-
- Manually validates tools using: `client/src/ql-mcp-client.js`.
39+
- Runs integration tests: `make -C client test-integration`.
40+
- Manually validates tools using: `gh-ql-mcp-client integration-tests --mode stdio --tools <tool_name>`.
4141
- Verifies server startup/shutdown: `server/dist/codeql-development-mcp-server.js`.
4242
- Maintains server documentation:
4343
- Keeps `server/QL-MCP-SERVER.md` synchronized with tool changes.

.github/agents/ql-mcp-tool-tester.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ My `ql-mcp-tool-tester` agent:
1515
- Focuses specifically on validating the functionality of the tools/primitives of the latest (developer) version of the CodeQL Development MCP Server, using actual CodeQL packs, queries, and query unit tests.
1616
- Utilizes the environment provided by `.github/workflows/copilot-setup-steps.yml` with pre-installed `codeql` CLI.
1717
- Understands how to:
18-
- Use the CodeQL Development MCP **Client** located at `client/src/ql-mcp-client.js` to interact with the MCP server (e.g. start/stop the server, list available tools, list available prompts, list available resources, etc.).
18+
- Use the Go MCP **Client** (`gh-ql-mcp-client`) to interact with the MCP server (e.g. run integration tests, connect over stdio or HTTP).
1919
- Use the Agent Skills defined under `.github/skills/**` for creating, updating, and testing custom CodeQL queries using the tools of the CodeQL Development MCP Server.
2020
- **Validate AST/CFG tools queries** using the [`validate-ql-mcp-server-tools-queries`](../skills/validate-ql-mcp-server-tools-queries/SKILL.md) skill to ensure `PrintAST`, `PrintCFG`, `CallGraphFrom`, and `CallGraphTo` queries return **non-empty, meaningful output**.
2121
- Serially test the "exercises" and/or "solutions" from a given CodeQL development workshop, as long as the workshop uses a directory and file structure compatible with the [`create-codeql-query-development-workshop`](../skills/create-codeql-query-development-workshop/) skill, with the goal of using a known good (e.g. example) workshop to validate MCP tool functionality in complex development scenarios using real CodeQL packs, queries, and query unit tests.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
applyTo: 'client/**/*.go'
3+
description: 'Instructions for MCP client Go source code files.'
4+
---
5+
6+
# Copilot Instructions for `client/**/*.go` code files
7+
8+
## PURPOSE
9+
10+
The `client/` directory implements `gh-ql-mcp-client`, a Go CLI that combines GitHub Code Scanning REST API operations (via `go-gh`) with the CodeQL Development MCP Server's SARIF analysis tools (via `mcp-go`). It serves as both a standalone CLI / `gh` extension for Code Scanning alert lifecycle management and as an integration test runner for MCP server primitives.
11+
12+
## REQUIREMENTS
13+
14+
- ALWAYS use modern Go idioms and standard library conventions.
15+
- ALWAYS follow best practices for implementing secure Go code.
16+
- ALWAYS order imports with standard library first, then external packages, then internal packages.
17+
- ALWAYS follow a test-driven development (TDD) approach — write Go tests before implementing new functionality.
18+
- **ALWAYS run `npm run build-and-test` from the repo root directory and ensure it passes completely before committing any changes. This is MANDATORY and must be verified before every commit.**
19+
- ALWAYS fix lint issues by running `make -C client lint` before committing changes.
20+
- **ALWAYS run `make -C client test-unit` and ensure all Go unit tests pass before committing changes to client code.**
21+
- ALWAYS reference the [client_integration_tests.instructions.md](./client_integration_tests.instructions.md) and [client/integration-tests/README.md](../../client/integration-tests/README.md) files when implementing or modifying integration tests for MCP server primitives.
22+
23+
## PREFERENCES
24+
25+
- PREFER using Cobra subcommands for CLI structure (`client/cmd/`).
26+
- PREFER keeping each command in its own file (e.g., `client/cmd/code_scanning_list_alerts.go`).
27+
- PREFER the `internal/` package layout for non-exported packages (`github/`, `mcp/`, `testing/`).
28+
- PREFER table-driven tests with `t.Run` subtests.
29+
- PREFER simple integration tests with `test-config.json` fixtures over complex programmatic setup.
30+
- PREFER building on the existing integration test approach rather than implementing a new approach.
31+
32+
## CONSTRAINTS
33+
34+
- NEVER leave any trailing whitespace on any line.
35+
- NEVER guess at what an MCP server primitive is supposed to do; instead, look up its source code in `server/src/**/*.ts` files.
36+
- NEVER use `os.TempDir()`, `/tmp`, or any OS-level temporary directory — use the project-local `.tmp/` directory via `{{tmpdir}}` in test fixtures.

.github/instructions/client_integration_tests.instructions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ description: 'Instructions for working with client-side integration tests for th
99

1010
This file contains instructions for working with test files in the `client/integration-tests/` directory of the `codeql-development-mcp-client` repository.
1111

12-
The purpose of the entire `client/**` implementation is to provide integration tests for the MCP server primitives, as implemented in `server/src/**/*.ts` files. The `client/integration-tests/**` directory contains a directory structur that reflects the endpoints of the MCP server primitives under test, where a given parent test directory should contain child/leaf test subdirectories for expected contents of some file(s) "before" versus "after" calling the MCP server primitive (e.g. MCP server tool) under test.
12+
The purpose of the entire `client/**` implementation is to provide integration tests for the MCP server primitives, as implemented in `server/src/**/*.ts` files, and to serve as a Go CLI (`gh-ql-mcp-client`) for Code Scanning alert lifecycle management. The `client/integration-tests/**` directory contains a directory structure that reflects the endpoints of the MCP server primitives under test, where a given parent test directory should contain child/leaf test subdirectories for expected contents of some file(s) "before" versus "after" calling the MCP server primitive (e.g. MCP server tool) under test.
1313

1414
## REQUIREMENTS
1515

1616
- **ALWAYS run `npm run build-and-test` from the repo root directory and ensure it passes completely before committing any changes. This is MANDATORY and must be verified before every commit.**
17-
- **ALWAYS run `npm test` from the `client/` directory and ensure all integration tests pass before committing changes to integration tests.**
17+
- **ALWAYS run `make -C client test` from the repo root directory and ensure all Go unit tests and integration tests pass before committing changes to integration tests.**
1818
- ALWAYS fix lint errors by running `npm run lint:fix` from the repo root directory before committing changes.
19-
- ALWAYS define "before" and "after" files for `monitoring-state.json`, plus any other files used as integration test inputs (before) and outputs (after). If a file is used as an input but is not modified by the MCP server tool under test, then `ex_tool/ex_test/before/example_file.ex` should have identical contents to `ex_tool/ex_test/after/example_file.ex`.
19+
- ALWAYS define `test-config.json` or `before/monitoring-state.json` (with embedded `parameters`) for each test case to supply tool arguments to the Go test runner.
2020
- ALWAYS follow the structure for integration tests as described in the [client/integration-tests/README.md](../../client/integration-tests/README.md) file.
2121
- ALWAYS obey the `Requirements for Integration Tests` as described in the [client/integration-tests/README.md](../../client/integration-tests/README.md) file.
2222

.github/instructions/client_src_js.instructions.md

Lines changed: 0 additions & 32 deletions
This file was deleted.

.github/prompts/ql-mcp-server-fix-build-and-test.prompt.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,49 +58,53 @@ npm run test
5858

5959
#### Starting and Stopping the QL MCP Server for Client Integration Tests
6060

61-
QL MCP Client integration tests require the QL MCP Server to be running. You can start the server in a separate terminal window using:
61+
For HTTP mode integration tests, the QL MCP Server must be running. You can start the server using the shell scripts:
6262

6363
```bash
64-
## From the `client/` directory use `npm run server:start && npm run server:wait`.
65-
## From the root of the repository use:
66-
npm run server:start -w client && npm run server:wait -w client
64+
client/scripts/start-server.sh
65+
client/scripts/wait-for-server.sh
6766
```
6867

69-
To stop the server after running the integration tests, use:
68+
To stop the server after running the integration tests:
7069

7170
```bash
72-
## From the `client/` directory use `npm run server:stop`.
73-
## From the root of the repository use:
74-
npm run server:stop -w client
71+
client/scripts/stop-server.sh
7572
```
7673

74+
For stdio mode, the Go client spawns the server automatically — no manual start/stop is needed.
75+
7776
#### Fixing Client Integration Tests for the QL MCP Server
7877

79-
Client integration tests are executed via the `client/src/ql-mcp-client.js` script.
78+
Client integration tests are executed via the Go binary `gh-ql-mcp-client`.
8079

81-
To get help on using the MCP Client script, including help for the `integration-tests` subcommand, run:
80+
To get help on using the MCP Client binary, including help for the `integration-tests` subcommand, run:
8281

8382
```bash
84-
node src/ql-mcp-client.js --help
83+
gh-ql-mcp-client --help
8584
```
8685

87-
When focusing specifically on fixing client integration tests, it makes more sense to change directories to `cd client/` and then run the integration tests directly using `node src/ql-mcp-client.js integration-tests`.
86+
When focusing specifically on fixing client integration tests, build the binary and run the integration tests directly:
87+
88+
```bash
89+
make -C client build
90+
gh-ql-mcp-client integration-tests --mode stdio --no-install-packs
91+
```
8892

8993
Because integration tests can be time-consuming, you can run specific tests or tools as needed using the following commands:
9094

9195
```bash
9296
# Run all integration tests with default settings
93-
node src/ql-mcp-client.js integration-tests
97+
gh-ql-mcp-client integration-tests --mode stdio --no-install-packs
9498

9599
# Run tests for specific tools
96-
node src/ql-mcp-client.js integration-tests --tools codeql_query_run
100+
gh-ql-mcp-client integration-tests --mode stdio --tools codeql_query_run --no-install-packs
97101

98-
# Run specific tests for a tool with custom timeout
99-
node src/ql-mcp-client.js integration-tests --tools codeql_query_run --tests basic_query_run,javascript_tools_print_ast --timeout 600
102+
# Run specific tests for a tool
103+
gh-ql-mcp-client integration-tests --mode stdio --tools codeql_query_run --tests basic_query_run --no-install-packs
100104
```
101105

102106
## References
103107

104-
- [`package.json`](../../package.json) - The main `package.json` file that defines the `scripts` for building and testing the MCP Server, with references to the `server/` and `client/` workspaces.
108+
- [`package.json`](../../package.json) - The main `package.json` file that defines the `scripts` for building and testing the MCP Server, with references to the `server/` workspace and `make -C client` targets.
105109
- [`server/package.json`](../../server/package.json) - The `package.json` file in the `server/` workspace that defines the build and test scripts specific to the MCP Server.
106-
- [`client/package.json`](../../client/package.json) - The `package.json` file in the `client/` workspace that defines the integration test scripts for the MCP Client.
110+
- [`client/Makefile`](../../client/Makefile) - The Makefile in the `client/` directory that defines build, test, lint, and cross-compile targets for the Go CLI.

.github/workflows/client-integration-tests.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ jobs:
5252
cache: 'npm'
5353
node-version-file: '.node-version'
5454

55+
- name: MCP Integration Tests - Setup Go environment
56+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
57+
with:
58+
go-version-file: 'client/go.mod'
59+
cache-dependency-path: 'client/go.sum'
60+
5561
- name: MCP Integration Tests - Install OS dependencies (Ubuntu)
5662
if: runner.os == 'Linux'
5763
run: sudo apt-get install -y jq
@@ -60,8 +66,8 @@ jobs:
6066
if: runner.os == 'Windows'
6167
run: choco install jq -y
6268

63-
- name: MCP Integration Tests - Install node dependencies for client and server workspaces
64-
run: npm ci --workspace=client && npm ci --workspace=server
69+
- name: MCP Integration Tests - Install node dependencies for server workspace
70+
run: npm ci --workspace=server
6571

6672
- name: MCP Integration Tests - Setup CodeQL environment
6773
uses: ./.github/actions/setup-codeql-environment
@@ -93,7 +99,7 @@ jobs:
9399
run: ./server/scripts/install-packs.sh
94100

95101
## Extract test databases used in the integration tests.
96-
## Defaults to integration scope (javascript/examples only).
102+
## Defaults to integration scope (javascript/examples + all tools databases).
97103
## Query unit tests auto-extract their own databases via `codeql test run`.
98104
- name: MCP Integration Tests - Extract test databases
99105
shell: bash
@@ -109,9 +115,14 @@ jobs:
109115
## Run integration tests. This script builds the server bundle and runs tests.
110116
## We do NOT use 'npm run build-and-test' as it runs query unit tests which
111117
## have a dedicated workflow (query-unit-tests.yml).
118+
##
119+
## On Windows, GNU Make's SHELL := bash resolves to WSL's bash.exe
120+
## (C:\Windows\System32\bash.exe) instead of Git Bash, causing
121+
## "Windows Subsystem for Linux has no installed distributions" errors.
122+
## We override SHELL with the full Git Bash path to avoid this.
112123
- name: MCP Integration Tests - Run integration tests
113124
shell: bash
114-
run: npm run test:integration --workspace=client
125+
run: make -C client test-integration SHELL="$(which bash)"
115126

116127
- name: MCP Integration Tests - Stop the background MCP server process
117128
if: always() && matrix.mcp-mode == 'http'

.github/workflows/lint-and-format.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ jobs:
2525
cache: 'npm'
2626
node-version-file: '.node-version'
2727

28+
- name: Lint and Format - Setup Go
29+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
30+
with:
31+
go-version-file: 'client/go.mod'
32+
cache-dependency-path: 'client/go.sum'
33+
2834
- name: Lint and Format - Install node dependencies for all workspaces
2935
run: npm ci
3036

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ _Changes on `main` since the latest tagged release that have not yet been includ
9090
- `PackInstaller` uses consistent "download" terminology for `codeql pack download` operations with detailed per-language logging. ([#230](https://github.com/advanced-security/codeql-development-mcp-server/pull/230))
9191
- `McpProvider.fireDidChange` debounces rapid-fire notifications and clears pending timers on dispose/restart. ([#230](https://github.com/advanced-security/codeql-development-mcp-server/pull/230))
9292
- File watchers use relative paths in log messages and no longer trigger MCP definition changes for content-only file events. ([#230](https://github.com/advanced-security/codeql-development-mcp-server/pull/230))
93+
- The earlier `codeql-mcp.enableAnnotationTools` setting is no longer applicable and has been removed from the extension as annotation tools are now enabled by default. ([#223](https://github.com/advanced-security/codeql-development-mcp-server/pull/223))
9394

9495
#### Infrastructure & CI/CD
9596

0 commit comments

Comments
 (0)