Skip to content

Add the CodeQL MCP server and a query contributor agent for Copilot - #270

Merged
felickz merged 4 commits into
mainfrom
agents/codeql-mcp-server
Nov 26, 2026
Merged

felickz merged 4 commits into
mainfrom
agents/codeql-mcp-server

Conversation

@felickz

@felickz felickz commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: c6c4a192688caba03874c47800c0912bf947ddf0

Dimension Assessment Rationale
Change confidence 8/10 ↑ All checks passed on bb1f4b4, and the later commits change only the profile. The checks of c6c4a19 are pending.
↑ Locally, through server 2.27.4: a C# query of this repository compiled, the call graph queries ran with the selectors the profile names, and codeql_database_create built a JavaScript database.
↓ Profiles load from the default branch, so no session has started ql-mcp with this profile yet.
↓ codeql_database_create for C# failed locally on Windows inside the server, while the CLI in the shell built the same database. Untested on the Linux runner.

What this changes

  • Setup steps (.github/workflows/copilot-setup-steps.yml): after the existing steps, install Node.js 26, the CodeQL Development MCP server 2.27.4 and the dependencies of its tool query packs, then print the CLI and server paths and git status.
  • Agent profile (.github/agents/query-contributor.agent.md, new): a custom agent for query, library, data extension and test work. It starts the server (ql-mcp) for its own sessions and holds this repository's rules for that work: layout, ids and metadata, security or audit, what the suites and configs do with a query, tests first, data extensions, performance, and what never goes into a pull request.

Why

The coding agent here has the CodeQL CLI but none of the CodeQL development tools: AST printing, quick evaluation of a predicate, the QL language server, query profiling. And every delegated task has to restate the conventions of this repository. The profile gives a task both, so query work can be delegated with a short issue.

Design

  • The profile and the repository's MCP settings hold the same ql-mcp (see MCP Setup below). GitHub applies the settings after the profile, so keep the two the same. Copilot code review also reads the settings, but skips the server's tools, because none of them is marked read-only.
  • Version 2.27.4, the newest release that is not newer than .codeqlversion (there is no 2.27.5). Its tool query packs pin the library versions of their release, one older than this repository's (for example codeql/csharp-all 7.4.2 against 7.4.3). They go into the package cache next to them, and every pack here keeps resolving the version its lock file pins. The setup run shows the checkout clean after both installs.
  • CODEQL_PATH points the server at the pinned CLI in codeql_home. Without it the server looks for the CodeQL distribution of the VS Code extension before the PATH, and the runner's tool cache holds another CodeQL version (2.27.6 today). The value is the checkout path on a GitHub-hosted runner, which the setup run printed. Setup steps run only in sessions on GitHub Actions: assigning an issue to Copilot runs there, while a cloud sandbox session gets neither the CLI nor the server. The profile tells the agent to stop when the CLI is missing.
  • All tools of the server (tools: ["*"]), including codeql_database_create to build databases for testing.
  • CODEQL_MCP_WORKSPACE is the checkout, against which the server resolves relative paths. Without it the server uses its own working directory.
  • CODEQL_MCP_SCAN_EXCLUDE_DIRS is codeql_home, the CLI download. Not codeql: the exclusion matches a directory name at any depth, and the shared library packs (codeql/dataflow, codeql/util, codeql/ssa and others) and the Rust, Ruby, Swift and Actions library packs keep their modules under codeql/ directories.
  • Node.js 26 is on the PATH for the later steps and the session. CodeQL asks for Node.js 14 or later. A JavaScript test of this repository (javascript/test/audit/CWE-078) passes with Node.js 26 on the PATH.

Cost

The new steps took 65 seconds in the setup run (Node.js 4 s, server and tool packs 61 s), against 3 minutes 6 seconds for the existing steps. They run before every session of the coding agent and also before every Copilot code review, which runs these setup steps too.

How it was checked

  • Copilot Setup Steps on this branch (run): green. Ten of ten tool packs installed, no warning, codeql is /home/runner/work/CodeQL-Community-Packs/CodeQL-Community-Packs/codeql_home/codeql/codeql (2.27.5), the server is on the PATH, and git status --short printed nothing.
  • Locally with server 2.27.4 and CLI 2.27.5: initialize and tools/list over stdio returned 65 tools, none marked read-only. Through the server, codeql_query_compile with --warnings=error compiled csharp/src/security/CWE-918/RequestForgery.ql, and search_ql_code found its @id in csharp/src. Without CODEQL_PATH the same server picked a VS Code extension distribution instead of the CLI on the PATH.
  • Through the server, on a small C# database: CallGraphFrom with sourceFunction returned only the calls from that function, and CallGraphTo with targetFunction only the calls to it, both as sarif-latest. PrintCFG printed with graphtext. codeql_database_create built a JavaScript database with build mode none.
  • The profile's front matter parses, its prompt is 15,043 characters (the limit is 30,000), and every path it names exists.

After merge

  1. Assign an issue to Copilot with this agent: choose Query contributor in the assignment, or with the REST API agent_assignment.custom_agent: "query-contributor".
  2. In the session log, the step that starts the MCP servers should list ql-mcp and its tools.
  3. Optional: in Settings, Copilot, Copilot in the cloud, Validation tools, turn off the CodeQL check. Here it scans the whole checkout, including the codeql/ clone, and in a recent session it timed out without a result.

MCP Setup

{
  "mcpServers": {
    "ql-mcp": {
      "type": "local",
      "command": "codeql-development-mcp-server",
      "args": [],
      "tools": ["*"],
      "env": {
        "CODEQL_PATH": "/home/runner/work/CodeQL-Community-Packs/CodeQL-Community-Packs/codeql_home/codeql/codeql",
        "CODEQL_MCP_WORKSPACE": "/home/runner/work/CodeQL-Community-Packs/CodeQL-Community-Packs",
        "CODEQL_MCP_SCAN_EXCLUDE_DIRS": "codeql_home"
      }
    }
  }
}

The setup steps install the CodeQL Development MCP server (2.27.4, the newest
release that is not newer than the pinned CLI) and the dependencies of its tool
query packs, and check that the checkout stays clean.

A new agent profile, .github/agents/query-contributor.agent.md, starts the
server for its own sessions with the pinned CLI and an allowlist of its tools,
and holds the rules for query, library, data extension and test work in this
repository: layout, ids and metadata, suites and configs, tests first, data
extensions, performance, and what never goes into a pull request.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4124a708-0b20-41df-a2e2-c945fbf86752
Copilot AI balanced review requested due to automatic review settings November 25, 2026 23:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The contributor guidance contains unresolved inaccuracies and conflicts around security-query scope, removed alerts, model placement, version-update responsibilities, and scan coverage.

5 open issues
What changed in this PR

Adds CodeQL development tools and a dedicated Copilot agent to support query, library, model, and test contributions using the repository’s pinned CLI.

Changes:

  • Installs Node.js 26, CodeQL MCP server 2.27.4, and its tool-pack dependencies during Copilot setup.
  • Adds a query contributor profile with a scoped MCP tool allowlist and pinned CLI path.
  • Documents repository conventions, validation commands, performance checks, and contribution boundaries.
File Description
.github/​workflows/​copilot-setup-steps.yml Installs MCP prerequisites and prints CLI/server paths and checkout status.
.github/​agents/​query-contributor.agent.md Defines the query contributor agent, MCP configuration, and contribution guidance.

Review effort: Balanced

- Security or audit: a security query shows the weakness itself, which also
  covers settings and API uses that are insecure on their own. Only a weakness
  that needs data an attacker controls needs the flow.
- Configs: not every pack is in every shared config, so read the config's list
  before saying who gets a query.
- Tests: explain every removed row. A false positive removed from a safe case is
  the point of a fix; a row removed from a vulnerable case is a regression.
- Data extensions: a new remote source model for C# or Java goes in
  ext-library-sources, as CONTRIBUTING.md says.
- Versions: the maintainer bumps versions and pins when cutting a release, so
  the agent lists that under Follow-ups instead of changing them.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4124a708-0b20-41df-a2e2-c945fbf86752
Copilot AI balanced review requested due to automatic review settings November 26, 2026 04:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The call-graph queries omit the sourceFunction and targetFunction selectors, leaving the intended fixture functions unspecified despite the sourceFiles parameter.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Low severity Specify sourceFunction and targetFunction for call-graph queries

.github/​agents/​query-contributor.agent.md:115

The call-graph queries need different selectors from PrintAST/PrintCFG: server 2.27.4 documents sourceFunction for CallGraphFrom and targetFunction for CallGraphTo, both as comma-separated function names. Changing only queryName leaves the intended functions unspecified, so sourceFiles is not enough to inspect the fixture's calls. Specify those parameters explicitly.

5 resolved since last review

Review effort: Balanced

@felickz
felickz marked this pull request as ready for review November 26, 2026 05:14
…rofile

- CallGraphFrom and CallGraphTo take sourceFunction and targetFunction
  (function names), not sourceFiles. They are problem queries, so they need
  sarif-latest output, while PrintAST and PrintCFG use graphtext.
- CODEQL_MCP_WORKSPACE points the server at the checkout, so that relative
  paths no longer depend on its working directory.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4124a708-0b20-41df-a2e2-c945fbf86752
Copilot AI balanced review requested due to automatic review settings November 26, 2026 05:29
@felickz

felickz commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Copilot's review of bb1f4b4 listed one previously missed issue, without a thread: the call graph tool queries take sourceFunction (CallGraphFrom) and targetFunction (CallGraphTo), not sourceFiles. Fixed in b2beb41.

Checked through server 2.27.4 on a small C# database. CallGraphFrom with sourceFunction Main returned the call from Main to Helper and not the call from Helper to Leaf. CallGraphTo with targetFunction Leaf returned only the call from Helper. Both are problem queries, so graphtext cannot interpret them. The bullet now names sarif-latest for them, and graphtext for PrintAST and PrintCFG.

The same commit adds CODEQL_MCP_WORKSPACE to the profile's environment. Without it, the server resolves relative paths against its own working directory.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Two allowlisted MCP tools can execute build subprocesses outside the agent firewall during test database extraction, reintroducing a critical execution risk.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

High severity Remove build-executing database tools from the MCP allowlist

.github/​agents/​query-contributor.agent.md:51

Both tools extract test databases and can execute build scripts: rust/test/security/CWE-918/SsrfReflectionInjection/options.yml, for example, enables Cargo checking with external dependencies. Invoking them through MCP therefore permits build subprocesses outside the agent firewall, recreating the execution risk used to exclude codeql_database_create. Remove both tools from the allowlist and use the prescribed shell commands for extraction and testing instead.

Review effort: Balanced

The profile now starts ql-mcp with all of its tools, like the repository's MCP
settings, so that the agent can also create databases to test its work.
CODEQL_MCP_SCAN_EXCLUDE_DIRS skips the CLI download in codeql_home.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4124a708-0b20-41df-a2e2-c945fbf86752
Copilot AI balanced review requested due to automatic review settings November 26, 2026 05:48
@felickz
felickz merged commit 82bab7c into main Nov 26, 2026
31 checks passed
@felickz
felickz deleted the agents/codeql-mcp-server branch November 26, 2026 05:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Successful setup checks do not cover profile-driven ql-mcp startup in a hosted Copilot session or Linux C# database creation, so maintainer validation is still needed.

No open issues 🎉

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants