Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions server/dist/codeql-development-mcp-server.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions server/dist/codeql-development-mcp-server.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion server/src/lib/language-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { setTimeout, clearTimeout } from 'timers';
import { pathToFileURL } from 'url';
import { delimiter, join } from 'path';
import { logger } from '../utils/logger';
import { getPackageVersion } from '../utils/package-paths';
import { getProjectTmpDir } from '../utils/temp-dir';
import { getResolvedCodeQLDir } from './cli-executor';
import { getPackageVersion } from '../utils/package-paths';

export interface LSPMessage {
jsonrpc: '2.0';
Expand Down
2 changes: 1 addition & 1 deletion server/src/lib/session-data-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,6 @@ function parseBoolEnv(envVar: string | undefined, defaultValue: boolean): boolea

// Export singleton instance with environment variable support
export const sessionDataManager = new SessionDataManager({
storageLocation: process.env.MONITORING_STORAGE_LOCATION || join(getProjectTmpBase(), 'ql-mcp-tracking'),
storageLocation: process.env.MONITORING_STORAGE_LOCATION || join(getProjectTmpBase(), '.ql-mcp-tracking'),
enableMonitoringTools: parseBoolEnv(process.env.ENABLE_MONITORING_TOOLS, false),
});
10 changes: 7 additions & 3 deletions server/src/utils/temp-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { mkdirSync, mkdtempSync } from 'fs';
import { join } from 'path';
import { isAbsolute, join, resolve } from 'path';
import { getPackageRootDir } from './package-paths';

/**
Expand All @@ -17,10 +17,14 @@ import { getPackageRootDir } from './package-paths';
* Resolution order:
* 1. `CODEQL_MCP_TMP_DIR` environment variable β€” for read-only package root
* scenarios (e.g., npm global installs where the package directory is not
* writable).
* writable). Relative paths are resolved against process.cwd().
* 2. `<packageRoot>/.tmp` β€” default; excluded from version control.
*/
const PROJECT_TMP_BASE = process.env.CODEQL_MCP_TMP_DIR || join(getPackageRootDir(), '.tmp');
const PROJECT_TMP_BASE = process.env.CODEQL_MCP_TMP_DIR
? (isAbsolute(process.env.CODEQL_MCP_TMP_DIR)
? process.env.CODEQL_MCP_TMP_DIR
: resolve(process.cwd(), process.env.CODEQL_MCP_TMP_DIR))
: join(getPackageRootDir(), '.tmp');

/**
* Return the project-local `.tmp` base directory, creating it if needed.
Expand Down
103 changes: 103 additions & 0 deletions server/test/src/lib/cli-tool-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,109 @@ describe('registerCLITool handler behavior', () => {
);
});

it('should resolve relative tests parameter against user workspace dir', async () => {
const definition: CLIToolDefinition = {
name: 'codeql_test_run',
description: 'Run tests',
command: 'codeql',
subcommand: 'test run',
inputSchema: {
tests: z.array(z.string())
}
};

registerCLITool(mockServer, definition);

const handler = (mockServer.tool as ReturnType<typeof vi.fn>).mock.calls[0][3];

executeCodeQLCommand.mockResolvedValueOnce({
stdout: 'All tests passed',
stderr: '',
success: true
});

// Test with relative paths
await handler({ tests: ['relative/test1.ql', '/absolute/test2.ql'] });

// executeCodeQLCommand signature: (subcommand, options, additionalArgs, cwd)
const call = executeCodeQLCommand.mock.calls[0];
const positionalArgs = call[2];

// First relative path should be resolved to absolute
expect(positionalArgs[0]).not.toBe('relative/test1.ql');
expect(positionalArgs[0]).toContain('relative/test1.ql');

// Second absolute path should remain unchanged
expect(positionalArgs[1]).toBe('/absolute/test2.ql');
});

it('should resolve relative database parameter against user workspace dir', async () => {
const definition: CLIToolDefinition = {
name: 'codeql_query_run',
description: 'Run query',
command: 'codeql',
subcommand: 'query run',
inputSchema: {
database: z.string(),
query: z.string()
}
};

registerCLITool(mockServer, definition);

const handler = (mockServer.tool as ReturnType<typeof vi.fn>).mock.calls[0][3];

executeCodeQLCommand.mockResolvedValueOnce({
stdout: '{"columns":[]}',
stderr: '',
success: true
});

// Test with relative database path
await handler({ database: 'my-database', query: '/path/to/query.ql' });

// executeCodeQLCommand signature: (subcommand, options, additionalArgs, cwd)
const call = executeCodeQLCommand.mock.calls[0];
const options = call[1];

// Relative database path should be resolved to absolute
expect(options.database).not.toBe('my-database');
expect(options.database).toContain('my-database');
});

it('should resolve relative dir/packDir parameter against user workspace dir', async () => {
const definition: CLIToolDefinition = {
name: 'codeql_pack_install',
description: 'Install packs',
command: 'codeql',
subcommand: 'pack install',
inputSchema: {
dir: z.string()
}
};

registerCLITool(mockServer, definition);

const handler = (mockServer.tool as ReturnType<typeof vi.fn>).mock.calls[0][3];

executeCodeQLCommand.mockResolvedValueOnce({
stdout: 'Installed successfully',
stderr: '',
success: true
});

// Test with relative dir path
await handler({ dir: 'my-pack-dir' });

// executeCodeQLCommand signature: (subcommand, options, additionalArgs, cwd)
const call = executeCodeQLCommand.mock.calls[0];
const cwd = call[3];

// Relative dir should be resolved to absolute for cwd
expect(cwd).not.toBe('my-pack-dir');
expect(cwd).toContain('my-pack-dir');
});

it('should handle dir parameter as positional for pack_ls', async () => {
const definition: CLIToolDefinition = {
name: 'codeql_pack_ls',
Expand Down
Loading