Skip to content

Add checks as a first-class MCP tool to the gh-aw MCP server#24757

Merged
pelikhan merged 3 commits intomainfrom
copilot/add-checks-cli-tool
Apr 5, 2026
Merged

Add checks as a first-class MCP tool to the gh-aw MCP server#24757
pelikhan merged 3 commits intomainfrom
copilot/add-checks-cli-tool

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 5, 2026

The gh-aw MCP server exposed 8 tools but omitted checks, forcing review workflows to shell out to gh aw checks — the one remaining gh-aw-specific bash dependency that breaks on unauthenticated agent runs.

Changes

  • pkg/cli/mcp_tools_readonly.go — Added registerChecksTool: accepts pr_number (required) and repo (optional), calls FetchChecksResult directly (no subprocess, same pattern as registerStatusTool), returns full ChecksResult JSON
  • pkg/cli/mcp_server.go — Registered registerChecksTool in createMCPServer alongside the other read-only tools
  • pkg/cli/mcp_server_command.go — Added checks to the --help tool list
  • docs/…/gh-aw-as-mcp-server.md — Documented checks parameters and normalized states (success, failed, pending, no_checks, policy_blocked)
  • .github/aw/debug-agentic-workflow.md — Added checks tool → gh aw checks to the MCP equivalents list
  • pkg/cli/mcp_server_json_integration_test.go — Added TestMCPServer_ChecksToolReturnsValidJSON with subtests for missing pr_number (expects MCP error) and valid pr_number (validates all ChecksResult JSON fields when credentials are available, gracefully handles auth errors otherwise); also added checks to TestMCPServer_AllToolsReturnContent

Usage

Review workflows can now replace the bash dependency:

# Before: required shell auth
- run: gh aw checks ${{ github.event.pull_request.number }} --json

# After: MCP-first, no auth plumbing needed
tools:
  agentic-workflows:
Use the `checks` tool with pr_number: "42" to get normalized CI state.

The returned required_state field is the authoritative CI verdict in repos with optional deployment integrations (Vercel, Netlify) posting commit statuses alongside required CI checks.

Exposes `gh aw checks` as an `agentic-workflows` MCP tool so review-style
workflows can fetch normalized CI state without shelling out to `gh aw checks`.

- pkg/cli/mcp_tools_readonly.go: registerChecksTool calling FetchChecksResult
- pkg/cli/mcp_server.go: register checks tool in createMCPServer
- pkg/cli/mcp_server_command.go: add checks to Long tool list
- docs/…/gh-aw-as-mcp-server.md: document the new checks tool
- .github/aw/debug-agentic-workflow.md: add checks to MCP equivalents list

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/bad45885-e19c-4193-b686-d4a71933c62e

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add checks CLI tool to gh-aw MCP server Add checks as a first-class MCP tool to the gh-aw MCP server Apr 5, 2026
Copilot AI requested a review from pelikhan April 5, 2026 16:53
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Apr 5, 2026

@copilot I test an integration test for this new command. Look at our other MP commands are tested.

Adds TestMCPServer_ChecksToolReturnsValidJSON to mcp_server_json_integration_test.go
following the same pattern as the audit/logs tool tests:
- missing pr_number → MCP error
- valid pr_number without GitHub credentials → graceful error
- valid pr_number with credentials → JSON with all ChecksResult fields verified

Also adds checks to TestMCPServer_AllToolsReturnContent.
Uses strings.HasPrefix for safe prefix checking.

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/c5b20c48-dfd4-4ac0-bcb8-d6e8afe3ed14

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 5, 2026

@copilot I test an integration test for this new command. Look at our other MP commands are tested.

Added TestMCPServer_ChecksToolReturnsValidJSON to mcp_server_json_integration_test.go in d952ec2, following the same pattern as the audit and logs tool tests:

  • missing pr_number subtest — verifies that omitting pr_number returns an MCP error (validates our required-field check)
  • valid pr_number subtest — in test environments without GitHub credentials the tool gracefully returns an error; when credentials are available it validates all seven ChecksResult JSON fields (state, required_state, pr_number, head_sha, check_runs, statuses, total_count)

Also added checks to TestMCPServer_AllToolsReturnContent with mayFailInTest: true (consistent with audit/logs).

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 5, 2026

Hey @Copilot 👋 — great idea exposing checks as a first-class MCP tool! Eliminating the last gh aw checks bash dependency from review workflows is a clear quality-of-life win, and the implementation mirrors the registerStatusTool pattern nicely.

Two things need attention before this can land:

  • Missing unit/integration test — every other read-only MCP tool has a companion test file (e.g. status_mcp_integration_test.goTestGetWorkflowStatuses_MCPIntegration). A checks_mcp_integration_test.go that calls FetchChecksResult and verifies the JSON can be marshalled/unmarshalled is needed to match the project's quality standards.

  • Existing integration test will breakpkg/cli/mcp_server_tools_test.go hardcodes the expected tool count and list:

    expectedTools := []string{"status", "compile", "logs", "audit", "mcp-inspect", "add", "update", "fix"}
    // ...
    if len(result.Tools) != len(expectedTools) {  // expects 8, will now get 9

    After this PR the server exposes 9 tools, so this assertion will fail. "checks" must be added to expectedTools.

If you'd like a hand knocking these out, here's a prompt you can hand off to your coding agent:

In the repository github/gh-aw, PR branch copilot/add-checks-cli-tool:

1. Create pkg/cli/checks_mcp_integration_test.go following the pattern in
   pkg/cli/status_mcp_integration_test.go. The test should:
   - Build tag: `//go:build !integration`
   - Call FetchChecksResult("", "1") and handle the expected error gracefully
     (we're not in a live repo, so just verify the function returns without panicking
     and that any non-nil result can be marshalled to JSON)
   - Mirror TestGetWorkflowStatuses_MCPIntegration / TestGetWorkflowStatuses_WithPattern
     in structure.

2. Update pkg/cli/mcp_server_tools_test.go:
   - Add "checks" to the expectedTools slice.
   - The slice currently expects 8 tools; it must now expect 9.

3. Run `make agent-finish` to confirm build, test, and lint all pass.

Generated by Contribution Check · ● 2.3M ·

@pelikhan pelikhan marked this pull request as ready for review April 5, 2026 17:18
Copilot AI review requested due to automatic review settings April 5, 2026 17:18
@pelikhan pelikhan merged commit 4557ce1 into main Apr 5, 2026
51 of 52 checks passed
@pelikhan pelikhan deleted the copilot/add-checks-cli-tool branch April 5, 2026 17:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new read-only MCP tool (checks) to the gh-aw MCP server so workflows can fetch normalized PR CI check state via MCP instead of shelling out to gh aw checks.

Changes:

  • Added checks MCP tool that calls FetchChecksResult and returns ChecksResult as JSON.
  • Registered checks in the MCP server and surfaced it in CLI help + docs.
  • Extended MCP integration tests to include the new tool.
Show a summary per file
File Description
pkg/cli/mcp_tools_readonly.go Implements registerChecksTool MCP tool returning ChecksResult JSON
pkg/cli/mcp_server.go Registers checks tool during server creation
pkg/cli/mcp_server_json_integration_test.go Adds integration test coverage and includes checks in the all-tools test matrix
pkg/cli/mcp_server_command.go Lists checks in mcp-server --help output
docs/src/content/docs/reference/gh-aw-as-mcp-server.md Documents checks parameters and normalized states
.github/aw/debug-agentic-workflow.md Adds checks to MCP ↔ CLI equivalents list

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 6/6 changed files
  • Comments generated: 4

Comment on lines +352 to +356
mcpLog.Printf("Executing checks tool: pr_number=%s, repo=%s", args.PRNumber, args.Repo)

result, err := FetchChecksResult(args.Repo, args.PRNumber)
if err != nil {
return nil, nil, newMCPError(jsonrpc.CodeInternalError, "failed to fetch checks", map[string]any{"error": err.Error()})
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

The PR description claims this tool avoids subprocesses, but FetchChecksResult ultimately shells out to the gh CLI via workflow.ExecGH (checks_command.go:186). If the goal is specifically to avoid calling gh aw checks that’s fine, but the description (and/or tool docs) should be clarified to avoid implying a pure in-process implementation.

Copilot uses AI. Check for mistakes.
Comment on lines 72 to 75
// Register remaining read-only tools
registerChecksTool(server)
registerMCPInspectTool(server, execCmd)

Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

In createMCPServer, checks is registered after logs/audit registration. Since createMCPServer returns early if registerLogsTool/registerAuditTool fail (e.g., schema generation errors), this read-only tool may never be available even though it doesn’t depend on those privileged tools. Consider registering checks alongside the other read-only tools before any early-return points.

Copilot uses AI. Check for mistakes.
params := &mcp.CallToolParams{
Name: "checks",
Arguments: map[string]any{
"pr_number": "1",
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

This test calls checks with only pr_number while running in a temporary git repo that has no remotes configured. Even if credentials are available, gh api typically can’t resolve the current repository without a remote/--repo, so the “verify JSON structure” branch is effectively unreachable. To actually validate JSON when creds are present, either set a repo remote in setupMCPServerTest or pass a known public repo argument here.

Suggested change
"pr_number": "1",
"pr_number": "1",
"repo": "cli/cli",

Copilot uses AI. Check for mistakes.
Comment on lines +420 to +430
if textContent.Text == "" {
t.Fatal("Expected non-empty text content from checks tool")
}

// In test environments without GitHub credentials, an error message is returned
if strings.HasPrefix(textContent.Text, "Error:") {
t.Logf("Checks tool returned error message (expected in test environment without GitHub credentials)")
return
}

// If credentials are available, verify JSON structure
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

After session.CallTool succeeds, this test checks for an "Error:" prefix in the returned content. But the checks tool returns failures as an MCP (jsonrpc) error (i.e., via the err return), so this branch should never be hit and may confuse future readers. Consider removing it or adjusting it to match the tool’s actual error-returning behavior.

Suggested change
if textContent.Text == "" {
t.Fatal("Expected non-empty text content from checks tool")
}
// In test environments without GitHub credentials, an error message is returned
if strings.HasPrefix(textContent.Text, "Error:") {
t.Logf("Checks tool returned error message (expected in test environment without GitHub credentials)")
return
}
// If credentials are available, verify JSON structure
if strings.TrimSpace(textContent.Text) == "" {
t.Fatal("Expected non-empty text content from checks tool")
}
// On success, the checks tool should return structured output; failures are
// reported by session.CallTool via err above.

Copilot uses AI. Check for mistakes.
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.

gh-aw MCP server exposes 8 CLI tools but not checks, forcing review workflows to shell out to gh aw checks

3 participants