Add --mcp flag to init command for Copilot Agent MCP configuration#2733
Add --mcp flag to init command for Copilot Agent MCP configuration#2733
Conversation
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>
pkg/cli/copilot_setup.go
Outdated
| go-version-file: go.mod | ||
| cache: true | ||
|
|
||
| - name: Install gh CLI |
| echo "GitHub CLI already installed" | ||
| fi | ||
|
|
||
| - name: Install gh-aw extension |
There was a problem hiding this comment.
@copilot always a fresh install so don't check for updates
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
@copilot inject extension install step if not found
There was a problem hiding this comment.
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>
|
@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>
Refactored to use YAML unmarshalling/marshalling in commit f14b821. The code now:
This approach is more reliable and maintainable than string manipulation. |
|
Agentic Changeset Generator triggered by this pull request. |
There was a problem hiding this comment.
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
--mcpflag to theinitcommand to configure GitHub Copilot Agent MCP server integration - Created new functionality to generate
.vscode/mcp.jsonand.github/workflows/copilot-setup-steps.ymlfiles - 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 }}", |
There was a problem hiding this comment.
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.
| "GH_TOKEN": "${{ github.token }}", | |
| "GH_TOKEN": yaml.String("${{ github.token }}"), |
| existingJSON, _ := json.Marshal(existingConfig) | ||
| newJSON, _ := json.Marshal(ghAwConfig) |
There was a problem hiding this comment.
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.
| 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) | |
| } |
| **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` |
There was a problem hiding this comment.
[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.
| - 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` |
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:
--mcpflag to theinitcommand to configure MCP integrationSolution Implemented
Added
--mcpflag togh aw initcommand that automatically configures:.github/workflows/copilot-setup-steps.yml- GitHub Copilot Agent setup workflow.vscode/mcp.json- VS Code MCP server configurationUsage:
Recent Updates (addressing PR feedback)
gh extension install githubnext/gh-aw(no upgrade check for fresh installs)Implementation Checklist
Files Created
pkg/cli/copilot_setup.go- Generates copilot-setup-steps.yml with YAML-based injection logicpkg/cli/mcp_config_file.go- Generates/updates .vscode/mcp.jsonpkg/cli/init_mcp_test.go- Comprehensive test suiteFiles Modified
pkg/cli/init_command.go- Added --mcp flagpkg/cli/init.go- Updated InitRepository functionpkg/cli/init_test.go- Updated testsdocs/src/content/docs/tools/cli.md- CLI documentationdocs/src/content/docs/tools/mcp-server.md- MCP server documentationKey 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
Testing
✅ All unit tests pass
✅ Manual testing verified
✅ Code review passed
✅ Backward compatibility verified
✅ Documentation reviewed
✅ PR feedback addressed (YAML parsing approach)
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.