Skip to content

Add --mcp flag to init command for Copilot Agent MCP configuration#2733

Merged
pelikhan merged 7 commits intomainfrom
copilot/configure-copilot-agent-mcp
Oct 29, 2025
Merged

Add --mcp flag to init command for Copilot Agent MCP configuration#2733
pelikhan merged 7 commits intomainfrom
copilot/configure-copilot-agent-mcp

Conversation

Copy link
Contributor

Copilot AI commented Oct 29, 2025

Implementation Complete: --mcp Flag for Init Command

Problem Statement

The issue requested adding support for configuring the gh-aw MCP server in GitHub Copilot Agent workflows by:

  1. Researching how to create action YAML files for Copilot Agent custom setup steps
  2. Adding a --mcp flag to the init command to configure MCP integration

Solution Implemented

Added --mcp flag to gh aw init command that automatically configures:

  • .github/workflows/copilot-setup-steps.yml - GitHub Copilot Agent setup workflow
  • .vscode/mcp.json - VS Code MCP server configuration

Usage:

gh aw init --mcp

Recent Updates (addressing PR feedback)

  • ✅ Removed "Install gh CLI" step (gh CLI is pre-installed in GitHub Actions runners)
  • ✅ Simplified extension installation to gh extension install githubnext/gh-aw (no upgrade check for fresh installs)
  • ✅ Refactored step injection to use YAML unmarshalling/marshalling instead of string manipulation
  • ✅ Updated tests to match new behavior

Implementation Checklist

  • Explore repository structure and understand existing init command
  • Understand copilot-setup-steps.yml format and requirements
  • Understand MCP configuration format (.vscode/mcp.json)
  • Add --mcp flag to init command
  • Create function to generate/update copilot-setup-steps.yml
  • Create function to generate/update .vscode/mcp.json
  • Add comprehensive tests for new functionality
  • Test manually in multiple scenarios
  • Run formatter and linter (all pass)
  • Run unit tests (all pass)
  • Update CLI documentation
  • Update MCP server documentation
  • Code review (no issues)
  • Address PR feedback (string manipulation → YAML parsing)
  • Final verification

Files Created

  • pkg/cli/copilot_setup.go - Generates copilot-setup-steps.yml with YAML-based injection logic
  • pkg/cli/mcp_config_file.go - Generates/updates .vscode/mcp.json
  • pkg/cli/init_mcp_test.go - Comprehensive test suite

Files Modified

  • pkg/cli/init_command.go - Added --mcp flag
  • pkg/cli/init.go - Updated InitRepository function
  • pkg/cli/init_test.go - Updated tests
  • docs/src/content/docs/tools/cli.md - CLI documentation
  • docs/src/content/docs/tools/mcp-server.md - MCP server documentation

Key Features

Idempotent: Won't overwrite existing customized files
Smart Injection: Adds extension install step to existing files if missing using proper YAML parsing
Preserves Config: Merges with existing mcp.json servers
Simplified Setup: Removes unnecessary steps (gh CLI pre-installed)
Proper YAML Handling: Uses unmarshalling/marshalling for reliable file updates
Complete Testing: All unit tests pass
Well-Documented: Complete documentation with examples
Backward Compatible: No breaking changes

Generated copilot-setup-steps.yml

name: "Copilot Setup Steps"

jobs:
  copilot-setup-steps:
    runs-on: ubuntu-latest
    permissions:
      contents: read

    steps:
      - name: Checkout code
        uses: actions/checkout@v5

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version-file: go.mod
          cache: true

      - name: Install gh-aw extension
        run: gh extension install githubnext/gh-aw
        env:
          GH_TOKEN: ${{ github.token }}

      - name: Build gh-aw from source
        run: make build
        continue-on-error: true

      - name: Verify gh-aw installation
        run: gh aw version || ./gh-aw version

Testing

✅ All unit tests pass
✅ Manual testing verified
✅ Code review passed
✅ Backward compatibility verified
✅ Documentation reviewed
✅ PR feedback addressed (YAML parsing approach)

Original prompt

This section details on the original issue you should resolve

<issue_title>Configuring copilot agent MCP</issue_title>
<issue_description>/scout

  • research how to create a action yml file to configuration custom steps to run in the github copilot agent job. Collects docs url + critical information to leverage this feature

  • add a "--mcp" flag to the "init" command that configures copilot agent with the gh-aw mcp: add gh-aw mcp server definition to mcps.json, add steps to install the extension in copilot steps</issue_description>

Comments on the Issue (you are @copilot in this section)

@pelikhan Use the information above to create a command to adds or update the steps to install the gh aw extension and create/update the MCP configuration to add the MCP-server command as MCP server

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits October 29, 2025 12:31
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add configuration for Copilot Agent MCP Add --mcp flag to init command for Copilot Agent MCP configuration Oct 29, 2025
Copilot AI requested a review from pelikhan October 29, 2025 12:47
go-version-file: go.mod
cache: true

- name: Install gh CLI
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot pre-installed, remove step

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the "Install gh CLI" step in commit 22ff732. The gh CLI is pre-installed in GitHub Actions runners, so this step is unnecessary.

echo "GitHub CLI already installed"
fi

- name: Install gh-aw extension
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot always a fresh install so don't check for updates

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified the extension installation to just gh extension install githubnext/gh-aw in commit 22ff732. Removed the upgrade check since it's always a fresh install in the setup steps.

if _, err := os.Stat(setupStepsPath); err == nil {
copilotSetupLog.Printf("File already exists: %s", setupStepsPath)
// File exists, skip creation to avoid overwriting user customizations
if verbose {
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot inject extension install step if not found

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added injection logic in commit 22ff732. The function now reads existing copilot-setup-steps.yml files and injects the extension install step after the "Set up Go" step if it's not already present. The injection is idempotent - it won't inject if the step already exists.

…l, add step injection

- Remove "Install gh CLI" step (pre-installed in GitHub Actions)
- Simplify extension installation to just install (no upgrade check)
- Add logic to inject extension install step into existing files
- Update tests to match new behavior

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

@copilot to inject steps, unmarshall yml, add steps, Marshall yml

- Replace string manipulation with proper YAML parsing
- Add WorkflowStep, WorkflowJob, and Workflow structs
- Use goccy/go-yaml for unmarshalling and marshalling
- Improves reliability and maintainability of step injection

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

Copilot AI commented Oct 29, 2025

@copilot to inject steps, unmarshall yml, add steps, Marshall yml

Refactored to use YAML unmarshalling/marshalling in commit f14b821. The code now:

  1. Unmarshals the existing YAML workflow into structs
  2. Adds the extension install step at the correct position
  3. Marshals back to YAML

This approach is more reliable and maintainable than string manipulation.

Copilot AI requested a review from pelikhan October 29, 2025 16:29
@pelikhan pelikhan marked this pull request as ready for review October 29, 2025 16:47
Copilot AI review requested due to automatic review settings October 29, 2025 16:47
@github-actions
Copy link
Contributor

Agentic Changeset Generator triggered by this pull request.

Copy link
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

This PR adds MCP (Model Context Protocol) server configuration support to the init command, enabling automatic setup of GitHub Copilot Agent integration.

  • Added --mcp flag to the init command to configure GitHub Copilot Agent MCP server integration
  • Created new functionality to generate .vscode/mcp.json and .github/workflows/copilot-setup-steps.yml files
  • Updated all test cases to accommodate the new parameter signature

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/cli/mcp_config_file.go New file implementing MCP configuration file creation and management for .vscode/mcp.json
pkg/cli/copilot_setup.go New file implementing GitHub Actions workflow generation for Copilot setup steps
pkg/cli/init_command.go Added --mcp flag and updated command documentation
pkg/cli/init.go Added MCP configuration logic when --mcp flag is enabled
pkg/cli/init_test.go Updated test calls to include new mcp parameter
pkg/cli/init_mcp_test.go New comprehensive test suite for MCP integration functionality
docs/src/content/docs/tools/mcp-server.md Added documentation for GitHub Copilot Agent configuration
docs/src/content/docs/tools/cli.md Added documentation for --mcp flag usage

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

Name: "Install gh-aw extension",
Run: "gh extension install githubnext/gh-aw",
Env: map[string]any{
"GH_TOKEN": "${{ github.token }}",
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

The environment variable uses a Go template syntax in a YAML constant that will be marshaled. Consider whether this syntax will be preserved correctly when marshaling the Env map[string]any field. The string literal ${{ github.token }} should remain as-is in the output YAML.

Suggested change
"GH_TOKEN": "${{ github.token }}",
"GH_TOKEN": yaml.String("${{ github.token }}"),

Copilot uses AI. Check for mistakes.
Comment on lines +63 to +64
existingJSON, _ := json.Marshal(existingConfig)
newJSON, _ := json.Marshal(ghAwConfig)
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

Marshal errors are silently ignored. While unlikely to fail for these simple structs, the error handling should be consistent with the rest of the function. Consider handling these errors or adding a comment explaining why they can be safely ignored.

Suggested change
existingJSON, _ := json.Marshal(existingConfig)
newJSON, _ := json.Marshal(ghAwConfig)
existingJSON, err := json.Marshal(existingConfig)
if err != nil {
return fmt.Errorf("failed to marshal existing MCP server config: %w", err)
}
newJSON, err := json.Marshal(ghAwConfig)
if err != nil {
return fmt.Errorf("failed to marshal new MCP server config: %w", err)
}

Copilot uses AI. Check for mistakes.
**With `--mcp` flag:**
- Creates `.github/workflows/copilot-setup-steps.yml` with steps to install the gh-aw extension
- Creates `.vscode/mcp.json` with gh-aw MCP server configuration
- Enables the gh-aw MCP server in GitHub Copilot Agent, providing tools like `status`, `compile`, `logs`, and `audit`
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

[nitpick] The documentation mentions 'Enables the gh-aw MCP server in GitHub Copilot Agent' but the workflow created is copilot-setup-steps.yml which sets up the environment. Consider clarifying that this configures the environment for the MCP server rather than enabling it directly in the agent.

Suggested change
- Enables the gh-aw MCP server in GitHub Copilot Agent, providing tools like `status`, `compile`, `logs`, and `audit`
- Configures the environment for the gh-aw MCP server in GitHub Copilot Agent, providing tools like `status`, `compile`, `logs`, and `audit`

Copilot uses AI. Check for mistakes.
@pelikhan pelikhan merged commit 36aa429 into main Oct 29, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/configure-copilot-agent-mcp branch October 29, 2025 21:25
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.

Configuring copilot agent MCP

3 participants