Skip to content

Commit 7093a4e

Browse files
authored
Improve MCP server integrations with codeql execute *-server servers (#29)
* Add CodeQL background server manager and LSP tools Implements CodeQLServerManager for config-aware lifecycle management of CodeQL's three background servers (language-server, query-server2, cli-server) with session-isolated cache directories and automatic restart on configuration changes. Adds four LSP-based MCP tools: - codeql_lsp_diagnostics (renamed from codeql_language_server_eval) - codeql_lsp_completion - codeql_lsp_definition - codeql_lsp_references Resolves #17 (server manager with config hashing, session isolation, graceful shutdown) and #1 (LSP completion/definition/references tools). * Fix server lifecycle bugs and replace hard-coded startup delays - Fix duplicate --tuple-counting flag when both debug and tupleCounting are set in buildQueryServerArgs - Fix non-awaited force-kill timers in query-server and language-server shutdown methods (process could outlive caller) - Remove redundant process.on SIGINT/SIGTERM handlers from lsp-diagnostics (already handled by shutdownServerManager) - Replace hard-coded setTimeout delays (1.5-2s) in server start() methods with waitForProcessReady utility that resolves on first stderr/stdout output or rejects on spawn failure - Add comprehensive tests for process-ready utility * Fix CI failures and improve LSP tool reliability - Add LSP tools to longRunningTools (300s timeout) in integration test runner to prevent CI timeouts during JVM startup - Convert relative workspace_uri to file:// URIs in lsp-handlers - Replace synchronous readFileSync with async readFile - Add isRunning() guards to LSP feature methods - Guard exit notification in shutdown to prevent "not running" error - Fix semantic_validation test to use resolvable QL code - Centralize logger mock in test/setup.ts (removes 16 per-file mocks) - Add server-manager getLanguageServer/getQueryServer/getCLIServer tests - Clarify --debug/--tuple-counting arg ordering in server-config - Add missing README.md files to integration test directories * Address PR review comments & fix integration tests * Fixes for codeql_lsp_* tool integration tests * Address PR review comments from review #3773277390 - Fix race condition in server-manager getOrRestart: serialize concurrent calls per server type using pendingStarts map with async/await pattern - Fix lsp-handlers filePath docstring: document that relative paths are accepted and resolved against getUserWorkspaceDir() - Fix semantic_validation/syntax_validation READMEs: clarify that before/ after .ql files differ (not identical as previously stated) - Fix semantic_validation/after/monitoring-state.json: update parameter shape to use ql_code matching the codeql_lsp_diagnostics tool contract - Add concurrent access serialization test for server-manager * Address code-quality PR review feedback
1 parent ca58e85 commit 7093a4e

File tree

87 files changed

+12293
-5995
lines changed

Some content is hidden

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

87 files changed

+12293
-5995
lines changed

client/integration-tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Monitoring-based integration tests enable testing of MCP tools that previously c
127127
## Example: Tool with Both File-Based and Monitoring Tests
128128

129129
```text
130-
client/integration-tests/primitives/tools/codeql_language_server_eval/
130+
client/integration-tests/primitives/tools/codeql_lsp_diagnostics/
131131
└── semantic_validation/
132132
├── before/
133133
│ ├── semantic_query.ql # File-based test input

client/integration-tests/primitives/tools/codeql_language_server_eval/semantic_validation/after/monitoring-state.json

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

client/integration-tests/primitives/tools/codeql_language_server_eval/semantic_validation/before/monitoring-state.json

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# `codeql_lsp_completion/basic_completion`
2+
3+
## PURPOSE
4+
5+
Tests that `codeql_lsp_completion` returns targeted completion items for a
6+
member-access expression. The cursor is positioned after `f.getBa` so the
7+
language server should return completions matching the prefix (e.g.
8+
`getBaseName`). Uses `file_content` to provide inline query text, which
9+
avoids disk I/O and produces a small, focused result set.
10+
11+
## INPUTS
12+
13+
- **file_content**: Inline QL with cursor after `f.getBa`
14+
- **file_path**: `server/ql/javascript/examples/src/ExampleQuery1/ExampleQuery1.ql`
15+
- **line**: 3 (`where f.getBa`)
16+
- **character**: 13 (end of `getBa` prefix)
17+
- **workspace_uri**: `server/ql/javascript/examples`
18+
19+
## EXPECTED OUTPUTS
20+
21+
- A list of completion items matching the `getBa` prefix (e.g. `getBaseName`).
22+
- Monitoring state updated to record a successful `codeql_lsp_completion` call.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"sessions": [
3+
{
4+
"id": "integration_test_session",
5+
"calls": [
6+
{
7+
"tool": "codeql_lsp_completion",
8+
"timestamp": "2026-02-08T00:00:00.000Z",
9+
"status": "success"
10+
}
11+
]
12+
}
13+
]
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"sessions": [],
3+
"parameters": {
4+
"file_content": "import javascript\n\nfrom File f\nwhere f.getBa\nselect f",
5+
"file_path": "server/ql/javascript/examples/src/ExampleQuery1/ExampleQuery1.ql",
6+
"line": 3,
7+
"character": 13,
8+
"workspace_uri": "server/ql/javascript/examples"
9+
}
10+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# `codeql_lsp_completion/from_clause_completion`
2+
3+
## PURPOSE
4+
5+
Tests that `codeql_lsp_completion` returns keyword completions when the cursor
6+
is positioned after a partial keyword `wh` following a `from` clause. Uses
7+
`file_content` to provide inline query text, producing a small set of
8+
completions (e.g. `where`) rather than an exhaustive type list.
9+
10+
## INPUTS
11+
12+
- **file_content**: Inline QL with cursor after `wh` prefix
13+
- **file_path**: `server/ql/javascript/examples/src/ExampleQuery1/ExampleQuery1.ql`
14+
- **line**: 3 (after `wh`)
15+
- **character**: 2 (end of `wh` prefix)
16+
- **workspace_uri**: `server/ql/javascript/examples`
17+
18+
## EXPECTED OUTPUTS
19+
20+
- A list of completion items matching the `wh` prefix (e.g. `where`).
21+
- Monitoring state updated to record a successful `codeql_lsp_completion` call.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"sessions": [
3+
{
4+
"id": "integration_test_session",
5+
"calls": [
6+
{
7+
"tool": "codeql_lsp_completion",
8+
"timestamp": "2026-02-08T00:00:00.000Z",
9+
"status": "success"
10+
}
11+
]
12+
}
13+
]
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"sessions": [],
3+
"parameters": {
4+
"file_content": "import javascript\n\nfrom File f\nwh",
5+
"file_path": "server/ql/javascript/examples/src/ExampleQuery1/ExampleQuery1.ql",
6+
"line": 3,
7+
"character": 2,
8+
"workspace_uri": "server/ql/javascript/examples"
9+
}
10+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# `codeql_lsp_definition/basic_definition`
2+
3+
## PURPOSE
4+
5+
Tests that `codeql_lsp_definition` resolves the definition of a type used in a
6+
`from` clause. The cursor is on `File` (line 2, character 7) which should
7+
resolve to the `File` class definition in the JavaScript CodeQL library.
8+
Uses `file_content` to provide inline query text.
9+
10+
## INPUTS
11+
12+
- **file_content**: Inline QL with `from File f` clause
13+
- **file_path**: `server/ql/javascript/examples/src/ExampleQuery1/ExampleQuery1.ql`
14+
- **line**: 2 (on the `File` type in `from File f`)
15+
- **character**: 7 (cursor on `File`)
16+
- **workspace_uri**: `server/ql/javascript/examples`
17+
18+
## EXPECTED OUTPUTS
19+
20+
- One or more definition locations with URIs pointing to `.qll` library files.
21+
- Monitoring state updated to record a successful `codeql_lsp_definition` call.

0 commit comments

Comments
 (0)