Skip to content

Commit e60dcfa

Browse files
committed
Fixes for failing client integration tests
1 parent 3fff561 commit e60dcfa

16 files changed

+69
-268
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ _Changes on `main` since the latest tagged release that have not yet been includ
1818
1919
### Highlights
2020

21-
- **Persistent MRVA workflow state and caching** — Introduced a new `SqliteStore` backend plus opt-in annotation, audit, and query result cache tools to support the next phase of MCP-assisted CodeQL development and `seclab-taskflow-agent` integration. ([#169](https://github.com/advanced-security/codeql-development-mcp-server/pull/169))
21+
- **Annotation, audit, cache, and SARIF tools are now always enabled** — Removed the `ENABLE_ANNOTATION_TOOLS` opt-in gate; all annotation, audit, query result cache, and SARIF analysis tools are registered by default. The `ENABLE_ANNOTATION_TOOLS` environment variable is still respected (set to `false` to disable) but defaults to `true`. ([#223](https://github.com/advanced-security/codeql-development-mcp-server/pull/223))
22+
- **Go-based `ql-mcp-client` rewrite** — Replaced the Node.js `ql-mcp-client.js` integration test runner with a Go CLI (`gh-ql-mcp-client`) built with Cobra and `mcp-go`. Adds `list tools/prompts/resources` commands and assertion-based integration test validation. ([#223](https://github.com/advanced-security/codeql-development-mcp-server/pull/223))
23+
- **Persistent MRVA workflow state and caching** — Introduced a new `SqliteStore` backend plus annotation, audit, and query result cache tools to support the next phase of MCP-assisted CodeQL development and `seclab-taskflow-agent` integration. ([#169](https://github.com/advanced-security/codeql-development-mcp-server/pull/169))
2224
- **Rust language support** — Added first-class Rust support with `PrintAST`, `PrintCFG`, `CallGraphFrom`, `CallGraphTo`, and `CallGraphFromTo` queries, bringing the total supported languages to 10. ([#195](https://github.com/advanced-security/codeql-development-mcp-server/pull/195))
2325
- **Bug fixes and design improvements from recent evaluation sessions** — Fixed 5 bugs across `bqrs_interpret`, `bqrs_info`, `annotation_search`, `audit_add_notes`, and `query_results_cache_compare`; added `database_analyze` auto-caching and per-database mutex serialization; auto-enabled annotation tools in VS Code extension. ([#199](https://github.com/advanced-security/codeql-development-mcp-server/pull/199))
2426
- **SARIF analysis tools and cache model improvements** — Added `sarif_list_rules`, `sarif_extract_rule`, `sarif_rule_to_markdown`, `sarif_compare_alerts`, and `sarif_diff_runs` tools for rule-level SARIF extraction, Mermaid dataflow visualization, alert overlap analysis, and cross-run behavioral comparison. Extended cache model with `rule_id` and `run_id` columns; added `ruleId` filter to all cache tools; auto-decompose `database_analyze` SARIF into per-rule cache entries. Added `compare_overlapping_alerts` prompt and updated all SARIF-related prompts with tool recommendations. Extracted shared libraries for database metadata and SARIF rule name resolution. ([#204](https://github.com/advanced-security/codeql-development-mcp-server/pull/204))
@@ -77,6 +79,7 @@ _Changes on `main` since the latest tagged release that have not yet been includ
7779
- `McpProvider.requestRestart()` now invalidates the environment cache and bumps a `+rN` revision suffix so VS Code reliably restarts the MCP server after configuration changes. ([#196](https://github.com/advanced-security/codeql-development-mcp-server/pull/196))
7880
- Cached the extension version in the provider constructor to avoid repeated synchronous reads of `package.json`. ([#196](https://github.com/advanced-security/codeql-development-mcp-server/pull/196))
7981
- New `codeql-mcp.enableAnnotationTools` setting (default: `true`) auto-sets `ENABLE_ANNOTATION_TOOLS` and `MONITORING_STORAGE_LOCATION` environment variables; `additionalEnv` overrides for advanced users. ([#199](https://github.com/advanced-security/codeql-development-mcp-server/pull/199))
82+
- Simplified annotation tool environment: the extension no longer explicitly sets `ENABLE_ANNOTATION_TOOLS` since the server now defaults to `true`. ([#223](https://github.com/advanced-security/codeql-development-mcp-server/pull/223))
8083

8184
#### Infrastructure & CI/CD
8285

client/cmd/integration_tests.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ func runIntegrationTests(cmd *cobra.Command, _ []string) error {
9999
}
100100
fmt.Printf("Working directory: %s\n", repoRoot)
101101

102+
// Set CODEQL_MCP_TMP_DIR so the MCP server subprocess uses the same
103+
// tmp base as the Go runner's {{tmpdir}} placeholder (<repoRoot>/.tmp).
104+
// Without this, the server defaults to <serverPkgRoot>/.tmp (i.e.
105+
// server/.tmp/) which causes log directory validation failures.
106+
tmpBase := filepath.Join(repoRoot, ".tmp")
107+
if os.Getenv("CODEQL_MCP_TMP_DIR") == "" {
108+
os.Setenv("CODEQL_MCP_TMP_DIR", tmpBase)
109+
}
110+
102111
// Connect to MCP server
103112
client := mcpclient.NewClient(mcpclient.Config{
104113
Mode: MCPMode(),

client/scripts/run-integration-tests.sh

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
# Run integration tests - orchestrates the complete test workflow
44
# This script mimics the GitHub Actions workflow for local execution
55
#
6-
# By default, this script runs integration tests in TWO modes:
7-
# 1. Default mode (standard tools) - tests the user experience
8-
# 2. Annotation mode (annotation_*, audit_*, query_results_cache_* tools)
6+
# By default, this script runs integration tests in DEFAULT mode, which
7+
# includes all annotation, audit, cache, and SARIF tools (always enabled).
98
#
109
# Monitoring mode (session_* tools) is disabled by default as those tools
1110
# are deprecated. Set ENABLE_MONITORING_TOOLS=true to also run monitoring tests.
@@ -20,8 +19,8 @@
2019
# unset = skip monitoring mode (default)
2120
#
2221
# Usage:
23-
# ./run-integration-tests.sh # Default + annotation modes
24-
# ENABLE_MONITORING_TOOLS=true ./run-integration-tests.sh # Default + annotation + monitoring
22+
# ./run-integration-tests.sh # Default mode (all tools)
23+
# ENABLE_MONITORING_TOOLS=true ./run-integration-tests.sh # Default + monitoring
2524
# MCP_MODE=http ./run-integration-tests.sh # Run using HTTP transport
2625
# ./run-integration-tests.sh --tools session_end # Filter to specific tools
2726

@@ -39,21 +38,21 @@ export TIMEOUT_SECONDS="${TIMEOUT_SECONDS:-30}"
3938
export URL_SCHEME="${URL_SCHEME:-http}"
4039

4140
# Determine which modes to run.
42-
# By default, run default + annotation modes (monitoring is deprecated).
41+
# Annotation/audit/cache/SARIF tools are always enabled by default.
42+
# Monitoring mode is disabled by default (deprecated).
4343
# Use ENABLE_MONITORING_TOOLS=true to also run monitoring mode.
4444
RUN_DEFAULT_MODE=true
4545
RUN_MONITORING_MODE=false
46-
RUN_ANNOTATION_MODE=true
4746

4847
if [ -n "${ENABLE_MONITORING_TOOLS+x}" ]; then
4948
if [ "$ENABLE_MONITORING_TOOLS" = "true" ]; then
5049
RUN_MONITORING_MODE=true
51-
echo "🔧 Mode: Default + annotation + monitoring (ENABLE_MONITORING_TOOLS=true)"
50+
echo "🔧 Mode: Default + monitoring (ENABLE_MONITORING_TOOLS=true)"
5251
else
53-
echo "🔧 Mode: Default + annotation (monitoring explicitly disabled)"
52+
echo "🔧 Mode: Default (monitoring explicitly disabled)"
5453
fi
5554
else
56-
echo "🔧 Mode: Default + annotation (monitoring disabled by default)"
55+
echo "🔧 Mode: Default (all tools except deprecated monitoring)"
5756
fi
5857

5958
# Check if --no-install-packs was passed
@@ -165,13 +164,6 @@ if [ "$RUN_MONITORING_MODE" = true ]; then
165164
run_tests_in_mode "MONITORING MODE (session_* tools)" "true" "${EXTRA_ARGS[@]}"
166165
fi
167166

168-
if [ "$RUN_ANNOTATION_MODE" = true ]; then
169-
# Annotation mode enables annotation, audit, and cache tools
170-
export ENABLE_ANNOTATION_TOOLS="true"
171-
run_tests_in_mode "ANNOTATION MODE (annotation_*, audit_*, query_results_cache_* tools)" "false" "${EXTRA_ARGS[@]}"
172-
unset ENABLE_ANNOTATION_TOOLS
173-
fi
174-
175167
echo ""
176168
echo "═══════════════════════════════════════════════════════════════"
177169
echo "✅ All integration tests completed successfully!"

extensions/vscode/src/bridge/environment-builder.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,15 @@ export class EnvironmentBuilder extends DisposableObject {
147147
queryDirs.push(...userQueryDirs);
148148
env.CODEQL_QUERY_RUN_RESULTS_DIRS = queryDirs.join(delimiter);
149149

150-
// Annotation, audit, and cache tools enabled by default (Design 5).
151-
// The setting controls ENABLE_ANNOTATION_TOOLS and defaults
152-
// MONITORING_STORAGE_LOCATION to the scratch directory so tools work
153-
// out-of-the-box without manual env var configuration.
150+
// Annotation, audit, cache, and SARIF tools are enabled by default on
151+
// the server. The MONITORING_STORAGE_LOCATION env var tells the server
152+
// where to place its SQLite store; default to the scratch directory so
153+
// tools work out-of-the-box without manual env var configuration.
154154
// Respect values inherited from the extension host process environment;
155-
// only apply defaults when not already defined there. The additionalEnv
156-
// block below still overrides everything for advanced users.
157-
const enableAnnotations = config.get<boolean>('enableAnnotationTools', true);
158-
if (typeof process.env.ENABLE_ANNOTATION_TOOLS === 'string') {
159-
env.ENABLE_ANNOTATION_TOOLS = process.env.ENABLE_ANNOTATION_TOOLS;
160-
} else {
161-
env.ENABLE_ANNOTATION_TOOLS = enableAnnotations ? 'true' : 'false';
162-
}
155+
// the additionalEnv block below still overrides everything for advanced users.
163156
if (typeof process.env.MONITORING_STORAGE_LOCATION === 'string') {
164157
env.MONITORING_STORAGE_LOCATION = process.env.MONITORING_STORAGE_LOCATION;
165-
} else if (enableAnnotations && env.CODEQL_MCP_SCRATCH_DIR) {
158+
} else if (env.CODEQL_MCP_SCRATCH_DIR) {
166159
env.MONITORING_STORAGE_LOCATION = env.CODEQL_MCP_SCRATCH_DIR;
167160
}
168161

extensions/vscode/test/bridge/environment-builder.test.ts

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ describe('EnvironmentBuilder', () => {
273273
expect(() => builder.dispose()).not.toThrow();
274274
});
275275

276-
it('should set ENABLE_ANNOTATION_TOOLS=true by default', async () => {
276+
it('should not set ENABLE_ANNOTATION_TOOLS (server defaults to true)', async () => {
277277
const env = await builder.build();
278-
expect(env.ENABLE_ANNOTATION_TOOLS).toBe('true');
278+
expect(env.ENABLE_ANNOTATION_TOOLS).toBeUndefined();
279279
});
280280

281281
it('should not overwrite MONITORING_STORAGE_LOCATION if already set in parent env', async () => {
@@ -304,33 +304,7 @@ describe('EnvironmentBuilder', () => {
304304
}
305305
});
306306

307-
it('should set ENABLE_ANNOTATION_TOOLS=false when setting is disabled', async () => {
308-
const vscode = await import('vscode');
309-
const originalGetConfig = vscode.workspace.getConfiguration;
310-
311-
try {
312-
vscode.workspace.getConfiguration = () => ({
313-
get: (_key: string, defaultVal?: any) => {
314-
if (_key === 'enableAnnotationTools') return false;
315-
if (_key === 'additionalDatabaseDirs') return [];
316-
if (_key === 'additionalQueryRunResultsDirs') return [];
317-
if (_key === 'additionalMrvaRunResultsDirs') return [];
318-
return defaultVal;
319-
},
320-
has: () => false,
321-
inspect: () => undefined as any,
322-
update: () => Promise.resolve(),
323-
}) as any;
324-
325-
builder.invalidate();
326-
const env = await builder.build();
327-
expect(env.ENABLE_ANNOTATION_TOOLS).toBe('false');
328-
} finally {
329-
vscode.workspace.getConfiguration = originalGetConfig;
330-
}
331-
});
332-
333-
it('should set MONITORING_STORAGE_LOCATION to scratch dir when annotations enabled with workspace', async () => {
307+
it('should set MONITORING_STORAGE_LOCATION to scratch dir when workspace is open', async () => {
334308
const vscode = await import('vscode');
335309
const origFolders = vscode.workspace.workspaceFolders;
336310

@@ -347,14 +321,14 @@ describe('EnvironmentBuilder', () => {
347321
}
348322
});
349323

350-
it('should allow additionalEnv to override ENABLE_ANNOTATION_TOOLS', async () => {
324+
it('should allow additionalEnv to set custom environment variables', async () => {
351325
const vscode = await import('vscode');
352326
const originalGetConfig = vscode.workspace.getConfiguration;
353327

354328
try {
355329
vscode.workspace.getConfiguration = () => ({
356330
get: (_key: string, defaultVal?: any) => {
357-
if (_key === 'additionalEnv') return { ENABLE_ANNOTATION_TOOLS: 'false' };
331+
if (_key === 'additionalEnv') return { MY_CUSTOM_VAR: 'custom-value' };
358332
if (_key === 'additionalDatabaseDirs') return [];
359333
if (_key === 'additionalQueryRunResultsDirs') return [];
360334
if (_key === 'additionalMrvaRunResultsDirs') return [];
@@ -367,29 +341,9 @@ describe('EnvironmentBuilder', () => {
367341

368342
builder.invalidate();
369343
const env = await builder.build();
370-
// additionalEnv comes after the default, so it should override
371-
expect(env.ENABLE_ANNOTATION_TOOLS).toBe('false');
344+
expect(env.MY_CUSTOM_VAR).toBe('custom-value');
372345
} finally {
373346
vscode.workspace.getConfiguration = originalGetConfig;
374347
}
375348
});
376-
377-
it('should preserve ENABLE_ANNOTATION_TOOLS from parent process environment', async () => {
378-
const origValue = process.env.ENABLE_ANNOTATION_TOOLS;
379-
380-
try {
381-
process.env.ENABLE_ANNOTATION_TOOLS = 'false';
382-
383-
builder.invalidate();
384-
const env = await builder.build();
385-
// Inherited process.env value should be preserved
386-
expect(env.ENABLE_ANNOTATION_TOOLS).toBe('false');
387-
} finally {
388-
if (origValue === undefined) {
389-
delete process.env.ENABLE_ANNOTATION_TOOLS;
390-
} else {
391-
process.env.ENABLE_ANNOTATION_TOOLS = origValue;
392-
}
393-
}
394-
});
395349
});

server/dist/codeql-development-mcp-server.js

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -190522,7 +190522,7 @@ function parseBoolEnv(envVar, defaultValue) {
190522190522
var sessionDataManager = new SessionDataManager({
190523190523
storageLocation: process.env.MONITORING_STORAGE_LOCATION || join9(getProjectTmpBase(), ".ql-mcp-tracking"),
190524190524
enableMonitoringTools: parseBoolEnv(process.env.ENABLE_MONITORING_TOOLS, false),
190525-
enableAnnotationTools: parseBoolEnv(process.env.ENABLE_ANNOTATION_TOOLS, false)
190525+
enableAnnotationTools: parseBoolEnv(process.env.ENABLE_ANNOTATION_TOOLS, true)
190526190526
});
190527190527

190528190528
// src/lib/result-processor.ts
@@ -199822,13 +199822,6 @@ function generateListRecommendations(sessions) {
199822199822
// src/tools/annotation-tools.ts
199823199823
init_logger();
199824199824
function registerAnnotationTools(server) {
199825-
const config2 = sessionDataManager.getConfig();
199826-
if (!config2.enableAnnotationTools) {
199827-
logger.info(
199828-
"Annotation tools are disabled (opt-in). Set ENABLE_ANNOTATION_TOOLS=true to enable annotation_* tools."
199829-
);
199830-
return;
199831-
}
199832199825
registerAnnotationCreateTool(server);
199833199826
registerAnnotationGetTool(server);
199834199827
registerAnnotationListTool(server);
@@ -199963,13 +199956,6 @@ function registerAnnotationSearchTool(server) {
199963199956
init_logger();
199964199957
var AUDIT_CATEGORY = "audit-finding";
199965199958
function registerAuditTools(server) {
199966-
const config2 = sessionDataManager.getConfig();
199967-
if (!config2.enableAnnotationTools) {
199968-
logger.info(
199969-
"Audit tools are disabled (opt-in). Set ENABLE_ANNOTATION_TOOLS=true to enable audit_* and annotation_* tools."
199970-
);
199971-
return;
199972-
}
199973199959
registerAuditStoreFindingsTool(server);
199974199960
registerAuditListFindingsTool(server);
199975199961
registerAuditAddNotesTool(server);
@@ -200137,13 +200123,6 @@ function registerAuditClearRepoTool(server) {
200137200123
// src/tools/cache-tools.ts
200138200124
init_logger();
200139200125
function registerCacheTools(server) {
200140-
const config2 = sessionDataManager.getConfig();
200141-
if (!config2.enableAnnotationTools) {
200142-
logger.info(
200143-
"Cache tools are disabled (opt-in). Set ENABLE_ANNOTATION_TOOLS=true to enable query_results_cache_* tools."
200144-
);
200145-
return;
200146-
}
200147200126
registerQueryResultsCacheLookupTool(server);
200148200127
registerQueryResultsCacheRetrieveTool(server);
200149200128
registerQueryResultsCacheClearTool(server);
@@ -200333,13 +200312,6 @@ function registerQueryResultsCacheCompareTool(server) {
200333200312
import { readFileSync as readFileSync13 } from "fs";
200334200313
init_logger();
200335200314
function registerSarifTools(server) {
200336-
const config2 = sessionDataManager.getConfig();
200337-
if (!config2.enableAnnotationTools) {
200338-
logger.info(
200339-
"SARIF tools are disabled (opt-in). Set ENABLE_ANNOTATION_TOOLS=true to enable sarif_* tools."
200340-
);
200341-
return;
200342-
}
200343200315
registerSarifExtractRuleTool(server);
200344200316
registerSarifListRulesTool(server);
200345200317
registerSarifRuleToMarkdownTool(server);

server/dist/codeql-development-mcp-server.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/lib/session-data-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,5 +387,5 @@ function parseBoolEnv(envVar: string | undefined, defaultValue: boolean): boolea
387387
export const sessionDataManager = new SessionDataManager({
388388
storageLocation: process.env.MONITORING_STORAGE_LOCATION || join(getProjectTmpBase(), '.ql-mcp-tracking'),
389389
enableMonitoringTools: parseBoolEnv(process.env.ENABLE_MONITORING_TOOLS, false),
390-
enableAnnotationTools: parseBoolEnv(process.env.ENABLE_ANNOTATION_TOOLS, false),
390+
enableAnnotationTools: parseBoolEnv(process.env.ENABLE_ANNOTATION_TOOLS, true),
391391
});

server/src/tools/annotation-tools.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Annotation Tools — general-purpose notes and bookmarks on any entity.
33
*
4-
* Opt-in via ENABLE_ANNOTATION_TOOLS=true (disabled by default).
4+
* Enabled by default. Can be disabled via ENABLE_ANNOTATION_TOOLS=false.
55
* Uses the shared SqliteStore from the session data manager.
66
*/
77

@@ -14,15 +14,6 @@ import { logger } from '../utils/logger';
1414
* Register all annotation tools with the MCP server.
1515
*/
1616
export function registerAnnotationTools(server: McpServer): void {
17-
const config = sessionDataManager.getConfig();
18-
19-
if (!config.enableAnnotationTools) {
20-
logger.info(
21-
'Annotation tools are disabled (opt-in). Set ENABLE_ANNOTATION_TOOLS=true to enable annotation_* tools.',
22-
);
23-
return;
24-
}
25-
2617
registerAnnotationCreateTool(server);
2718
registerAnnotationGetTool(server);
2819
registerAnnotationListTool(server);

server/src/tools/audit-tools.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
* findings with notes, mirroring the seclab codeql_python MCP server's
66
* SQLite-backed source tracking — but now backed by the shared SqliteStore.
77
*
8-
* Enabled when ENABLE_ANNOTATION_TOOLS=true (disabled by default when annotation tools are off).
9-
* Audit tools are layered on annotations; there is no separate ENABLE_AUDIT_TOOLS flag.
8+
* Enabled by default alongside annotation tools.
109
*/
1110

1211
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
@@ -20,15 +19,6 @@ const AUDIT_CATEGORY = 'audit-finding';
2019
* Register all audit tools with the MCP server.
2120
*/
2221
export function registerAuditTools(server: McpServer): void {
23-
const config = sessionDataManager.getConfig();
24-
25-
if (!config.enableAnnotationTools) {
26-
logger.info(
27-
'Audit tools are disabled (opt-in). Set ENABLE_ANNOTATION_TOOLS=true to enable audit_* and annotation_* tools.',
28-
);
29-
return;
30-
}
31-
3222
registerAuditStoreFindingsTool(server);
3323
registerAuditListFindingsTool(server);
3424
registerAuditAddNotesTool(server);

0 commit comments

Comments
 (0)